ESlint custom indentation - eslint

I am trying to understand how can i implement the following indent rule in ESlint:
spaces: 2
spaces for continued lines: 4
This documentation does not seem to mention anything about it.
My current code is:
"#typescript-eslint/indent": [
"error",
2,
{
"FunctionDeclaration": {
"parameters": "first"
},
"FunctionExpression": {
"parameters": "first"
}
}
],

Related

ARM Template concat with multiline

I'm almost sure last time I was playing with ARM templates there was some trick to make code tidy and concat() with multiple lines. Yes, I know I could use
"myvar": "[concat(
'abc',
'def
)]"
if I'm deploying with cli/powershell, but I won't control the tools of the template's users, so they'll very likely just copy-paste into web console.
Any idea? Besides having a custom function to join multi-line text encoded as array:
"variables": {
"splitStr": [
"first line",
"second line",
"third line"
],
"output": "[custom.join(variables('splitStr'))]"
},
"functions": [
{
"namespace": "custom",
"members": {
"join": {
"parameters": [
{
"type": "array",
"name": "splitStr"
}
],
"output": {
"type": "string",
"value": "[replace(replace(replace(string(parameters('splitStr')), '[\"', ''), '\"]', ''), '\",\"', '\\n')]"
}
}
}
}
],
We're talking about a working sample code pushing hundred-ish lines of configuration text into a deployed VM, so text readability is important.

Azure Rule engine File extension with json file

I am trying to create a rule engine in a cdn endpoint. like this:
But using a Json file (The result in the image has been achieved manually but now i want to automate this).
So far I got this:
"deliveryPolicy": {
"description": "Rewrite and Redirect",
"rules": [
{
"name" : "UrlFileExtension",
"order": 2,
"conditions": [
{
"name": "UrlFileExtension",
"parameters": {
"#odata.type": "#Microsoft.Azure.Cdn.Models.UrlFileExtensionMatchConditionParameters",
"Extension": 0,
"operator": "LessThanOrEqual",
"matchValues": [0]
}
}
],
"actions": [
{
"name": "UrlRewrite",
"parameters": {
"#odata.type": "#Microsoft.Azure.Cdn.Models.DeliveryRuleUrlRewriteActionParameters",
"sourcePattern": "/",
"destination": "/index.html",
"preserveUnmatchedPath": false
}
}
]
},
The action works just fine, but the urlfileextentionI cant get it to work, it does not recognize the odata.type either.
Please any hint ot suggestion how to fix the condition?
You might want to try with this odata.type for the condition
"#odata.type": "#Microsoft.Azure.Cdn.Models.DeliveryRuleUrlFileExtensionMatchConditionParameters",
instead of
"#odata.type": "#Microsoft.Azure.Cdn.Models.UrlFileExtensionMatchConditionParameters",
https://learn.microsoft.com/en-us/python/api/azure-mgmt-cdn/azure.mgmt.cdn.models.urlfileextensionmatchconditionparameters?view=azure-python
(I'm aware the documentation says Python, I could not find better, but it could be your solution)

ESLint: how to spaced-comment exceptions on VSCode folding regions comments

I have spaced-comment in my configuration for ESLint to enforce spacing in comments but cannot determine how to add VSCode's folding regions comments to the exceptions array.
ESLint config:
"spaced-comment": [ "error", "always", {
"line": {
"exceptions": ["#region", "#endregion", "region", "endregion"]
}
}]
Source code
//#region My region
//#endregion My region
or
//region My region
//endregion My region
Message from ESLint:
Expected exception block, space or tab after '//' in comment.
Expectation: ESLint should allow me to use commented VSCode folding regions without forcing me to add a space between // and #region.
You can solve this by using markers instead of exceptions:
"spaced-comment": [ "error", "always", {
"line": {
"markers": ["#region", "#endregion", "region", "endregion"]
}
}]

Function highlighting with monokai in VS Code / Atom and Sublime

While running Sublime Text 3 and VS Code (or Atom) with the Monokai color theme, the Sublime Text syntax highlighting uses blue for function calls, such as in the example below
However, when I open the same code in VS Code using the monokai theme, functions are not painted blue
I would really like to change that, the code looks much better with function calls highlighted. However, I looked around the web and couldn't find how to change this behavior. Does anyone have any tips for that?
Thanks!
SEE UPDATE BELOW!
Seems like I've found a temporary solution. Go to this folder (if you are on Mac) /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/theme-monokai/themes and put this code in monokai-color-theme.json file:
{
"name": "Function call",
"scope": "meta.function-call.generic",
"settings": {
"foreground": "#66d9efff"
}
},
Here is an example how it can look like:
screenshot
But keep in mind, that after theme update this changes may disappear!
UPDATE:
After having a couple more troubles with highlighting, I decided to upload the file with theme to GitHub and keep it up to date. So, if you don't want to dive into the code, just look in my repository: https://github.com/spyker77/monokai-theme-extended
UPDATE (April 2021)
It turns out that the previous solution is not sustainable. Therefore at the moment a better one could be:
In you Visual Studio Code go to "Code" => "Preferences" => "Color Theme" and pick Monokai;
Open settings.json file (how-to);
There will probably already be a bunch of settings in there, so all you need to do is just add the following customisations at the end and before the closing brace (don't forget a trailing comma after the last setting you continue):
"editor.tokenColorCustomizations": {
"[Monokai]": {
"textMateRules": [
{
"name": "Decorator definition decorator",
"scope": "punctuation.definition.decorator.python",
"settings": {
"foreground": "#F92672"
}
},
{
"name": "Meta function-call",
"scope": "meta.function-call.generic.python",
"settings": {
"foreground": "#66D9EF"
}
},
{
"name": "Storage type function async",
"scope": "storage.type.function.async.python",
"settings": {
"foreground": "#F92672",
}
},
{
"name": "Punctuation separator period",
"scope": "punctuation.separator.period.python",
"settings": {
"foreground": "#F8F8F2",
}
},
{
"name": "Entity name function decorator",
"scope": "entity.name.function.decorator.python",
"settings": {
"foreground": "#66D9EF",
}
},
{
"name": "Entity name type class",
"scope": "entity.name.type.class.python",
"settings": {
"fontStyle": ""
}
},
{
"name": "Entity other inherited-class",
"scope": "entity.other.inherited-class.python",
"settings": {
"fontStyle": "italic"
}
},
{
"name": "Support type python",
"scope": "support.type.python",
"settings": {
"fontStyle": ""
}
},
{
"name": "String quoted docstring multi python",
"scope": "string.quoted.docstring.multi.python",
"settings": {
"foreground": "#88846F",
}
}
]
}
}
after trying for server hours finally found a solution and I came back to you to share the solution since I tried the answer above and couldn't make it work.
it turns out that the problem I with VScode extensions (python for Vscode), so disable that first,extension
then go to your setting.json file like that how to open setting
add this to the top of your file
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "meta.function-call.generic",
"settings": {
"foreground":"#19D1E5"
}
}
]
},
and restart VScode and this should work, btw I am using monokai vibrent, and I am sure it will work in any theme you like.
setting.json
like this here
In settings.json:
"editor.tokenColorCustomizations": {
"[Monokai]": {
{
"scope": "entity.name.function",
"settings": {
"foreground": "#fdc306d0", // use your desired color
"fontStyle": "underline" // I like this, foreground color has some reduced opacity
}
}
}
}
might do the trick.

How to tell eslint that you prefer single quotes around your strings

I'm new to eslint and it's spewing out a ton of errors telling me to use doublequotes:
error Strings must use doublequote
That's not my preference. I've got an .eslintrc file set up with the basics:
{
"env": {
"node": 1
}
}
I'd like to configure it for single quotes.
http://eslint.org/docs/rules/quotes.html
{
"env": {
"node": 1
},
"rules": {
"quotes": [2, "single", { "avoidEscape": true }]
}
}
If you're using TypeScript/ES6 you might want to include template literals (backticks). This rule prefers single quotes, and allows template literals.
TypeScript Examples
"#typescript-eslint/quotes": [
"error",
"single",
{
"allowTemplateLiterals": true
}
]
Another useful option is to allow single or double quotes as long as the string contains an escapable quote like "lorem ipsum 'donor' eta" or 'lorem ipsum "donor" eta'.
"#typescript-eslint/quotes": [
"error",
"single",
{
"avoidEscape": true,
"allowTemplateLiterals": true
}
]
References:
ESLint
https://eslint.org/docs/rules/quotes
TypeScript ESLint
https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/quotes.md
rules: {
'prettier/prettier': [
'warn',
{
singleQuote: true,
semi: true,
}
],
},
In version "eslint": "^7.21.0"
For jsx strings, if you would like to set this rule for all files, create the rule in the eslint config file.
rules: {
'jsx-quotes': [2, 'prefer-single'],
}
Or 'prefer-double' for double quotes.
If you also want to allow double quotes if they would avoid escaping a single quote inside the string, and allow template literals (the reasonable defaults, imo) try the following:
{
"env": {
"node": 1
},
"rules": {
"quotes": [2, "single", { "avoidEscape": true, "allowTemplateLiterals": true }]
}
}

Resources