allow singleQuote and backtick in eslint - eslint

I need to use only signleQuote and backTick in the eslint .
These are my codes in the json file :
"rulse":{
"quotes": "error",
"jsx-quotes": [2, "prefer-single"]
}

There is a misspelling and you must tell eslint what quotes to use:
"rules": {
"quotes": ["error", "single", "avoid-escape"]
}

Related

How to turn off eslint rule?

How do you turn off an eslint rule, for example no-inferrable-types which comes from the extension "eslint:recommended"?
For example if my .eslintrc.json contains:
"extends": [
"eslint:recommended",
.....
"#typescript-eslint/no-inferrable-types": [
"error",
{
"ignoreParameters": false,
"ignoreProperties": false
}
],
Set the value to "off" , as described here:
https://eslint.org/docs/latest/user-guide/configuring/rules
For example:
"#typescript-eslint/no-inferrable-types": "off",

ESLint options - overrideConfig not loading

I installed ESLint and set these settings in setting.json but EsLint does not start properly globally for VS Code.
Invalid Options: - Unknown options: envs, globals, parserOptions, rules
- 'envs' has been removed. Please use the 'overrideConfig.env' option instead.
- 'globals' has been removed. Please use the 'overrideConfig.globals' option instead.
- 'parserOptions' has been removed. Please use the 'overrideConfig.parserOptions' option instead.
- 'rules' has been removed. Please use the 'overrideConfig.rules' option instead.
These are my settings:
"eslint.options": {
"envs": [
"es6",
"browser",
"node",
"mocha"
],
"globals": [
"expect"
],
"parserOptions": {
"ecmaVersion": 2019,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"semi": "error",
"curly": "error",
"quotes": [
"warn",
"single"
],
"no-undef": "error"
}
},
In case you are still looking for an answer, I just had the same issue.. You need to wrap your eslint options into an overrideConfig object. In this case the aimed object in the error message overrideConfig.(...) will be provided correctly.
Similar issue here

bracket issue use prettier with eslint

I use prettier with eslint in vs code as follow setting.
//.eslintrc
{
"parser": "babel-eslint",
"root": true,
"extends": [
"airbnb",
"plugin:vue/essential",
"plugin:prettier/recommended",
"eslint:recommended"
],
"rules": {
"no-console": 0
}
}
//.prettierc
{
"printWidth": 100,
"singleQuote": true,
"jsxBracketSameLine": true
}
but some eslint recommend conflict autoformatting from prettier.
prettier make code like this.
import { mapGetters, mapActions } from 'vuex'
(autosaving)
import {
mapGetters,
mapActions
} from 'vuex'
but now eslint draw red line.
// example
Replace `␍⏎··mapActions,␍⏎··mapGetters␍⏎` with `·mapActions,·mapGetters·`eslint(prettier/prettier)
I don't want eslint red line anywhere...
so I was found some document, but cannot found prettier setting..
how disable this red line?
Since prettier is very opinionated, it might cause trouble with es-lint sometimes. You might want to use a library like prettier-eslint
This will format your code with prettier, then try to fix it with eslint.
You can probably disable the conflicting rules as described in the prettier docs.
https://prettier.io/docs/en/eslint.html
They've mentioned adding
{ "extends": ["prettier"] }
to your .eslintrc.json might help along with other configuration.

Turn off error for console.log on my eslint

I'm trying to turn off lint warning for my eslint at VS code.
My code is contains.
console.log('blabla..');
eslint said as below.
error Unexpected console statement no-console
Even though already add no-restricted-syntax at my .eslintrc.json, no fixed.
Here is my .eslintrc.json
{
"env": {
"es6": true,
"node": true,
"amd": true,
"mocha": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
},
"rules": {
"linebreak-style": [
"error",
"windows"
],
"no-restricted-syntax": [
"error",
{
"selector": "CallExpression[callee.object.name='console'][callee.property.name=/^(log|warn|error|info|trace)$/]",
"message": "Unexpected property on console object was called"
}
]
}
}
What did I mistake?
Allowing the console.log to stay in code is requiring a separate rule.
You need to add 'no-console' statement to your eslint config rules.
Like so:
rules: {
"no-console": 0
}
A better practice is to warn you about all the console.log in your code, like so:
rules: {
"no-console": 1
}
I followed the advice of Elad and went into the package.json to add the rule of "no-console": 0 and at first it didn't seem like it worked but this is because I needed to restart the development server. If it seems like it's not working, make sure you restart the development server because if you change anything in the package-json, you have to restart your server.
You can add // eslint-disable-line if you need to ignore a specific (or multiple) line

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