I have ESlint configured with vscode using the plugin, now I’m wondering is there some way I can stop ESlint from showing me the parser/syntax errors, so I can instead view the syntax errors that the Salsa language service provides by default.
Flip
6,1437 gold badges45 silver badges75 bronze badges
asked Mar 11, 2016 at 11:25
The old:
"eslint.enable": false
Is deprecated, now you need to use the builtin VSCode mechanism for disabling extensions:
answered Dec 12, 2020 at 18:46
melMassmelMass
3,5131 gold badge31 silver badges30 bronze badges
In order to disable ESLint only for a specific repo (instead of disabling it globally). Create .vscode
folder in your project root and there create a settings.json
then add the following config:
{
"eslint.enable": false
}
Maybe after this setting you should consider adding the .vscode/settings.json
line to your .gitignore
file too, but it is based on your dev team’s preference.
}
Additionally if you’d like to ignore only some vendor/3PP .js
files only then you should consider creating an .eslintignore
file. Read more about this here.
answered Mar 8, 2019 at 13:05
webpreneurwebpreneur
7959 silver badges15 bronze badges
2
go to File => Preferences => Settings
go to Extensions=>ESLint
Uncheck the EsLint:Enable
answered Oct 24, 2018 at 11:45
In VSCode, go to
File >> preferences >> settings
Type ‘eslint quiet’ in the search bar and click
the check box for quiet mode.
In quiet mode, eslint would ignore basic errors.
This should work for many VSCode users as at March 4, 2022.
You’re welcome!
answered Mar 4, 2022 at 17:33
Emeka OrjiEmeka Orji
1754 silver badges11 bronze badges
1
1-) npm install -g eslint
2-) Open up settings.json and add the property: "eslint.enable": false
answered Oct 24, 2018 at 9:12
Please open settings.json file and edit the configuration as below:
"eslint.enable": false
Hope this helps.
answered Sep 21, 2022 at 16:23
2
I don’t understand why some answers states that eslint.enable
is depracted. it works for me. in my WorkSpace settings (JSON), I add the following configuration and eslint errors disapears
{
...
"settings": {
"eslint.enable": false
},
}
answered Feb 15 at 15:24
snoob doggsnoob dogg
2,4083 gold badges29 silver badges53 bronze badges
Rules are the core building block of ESLint. A rule validates if your code meets a certain expectation, and what to do if it does not meet that expectation. Rules can also contain additional configuration options specific to that rule.
ESLint comes with a large number of built-in rules and you can add more rules through plugins. You can modify which rules your project uses with either configuration comments or configuration files.
Rule Severities
To change a rule’s severity, set the rule ID equal to one of these values:
"off"
or0
— turn the rule off"warn"
or1
— turn the rule on as a warning (doesn’t affect exit code)"error"
or2
— turn the rule on as an error (exit code is 1 when triggered)
Rules are typically set to "error"
to enforce compliance with the rule during continuous integration testing, pre-commit checks, and pull request merging because doing so causes ESLint to exit with a non-zero exit code.
If you don’t want to enforce compliance with a rule but would still like ESLint to report the rule’s violations, set the severity to "warn"
. This is typically used when introducing a new rule that will eventually be set to "error"
, when a rule is flagging something other than a potential buildtime or runtime error (such as an unused variable), or when a rule cannot determine with certainty that a problem has been found (when a rule might have false positives and need manual review).
To configure rules inside of a file using configuration comments, use a comment in the following format:
/* eslint eqeqeq: "off", curly: "error" */
In this example, eqeqeq
is turned off and curly
is turned on as an error. You can also use the numeric equivalent for the rule severity:
/* eslint eqeqeq: 0, curly: 2 */
This example is the same as the last example, only it uses the numeric codes instead of the string values. The eqeqeq
rule is off and the curly
rule is set to be an error.
If a rule has additional options, you can specify them using array literal syntax, such as:
/* eslint quotes: ["error", "double"], curly: 2 */
This comment specifies the “double” option for the quotes
rule. The first item in the array is always the rule severity (number or string).
Configuration comments can include descriptions to explain why the comment is necessary. The description must occur after the configuration and is separated from the configuration by two or more consecutive -
characters. For example:
/* eslint eqeqeq: "off", curly: "error" -- Here's a description about why this configuration is necessary. */
/* eslint eqeqeq: "off", curly: "error"
--------
Here's a description about why this configuration is necessary. */
/* eslint eqeqeq: "off", curly: "error"
* --------
* This will not work due to the line above starting with a '*' character.
*/
Using configuration files
To configure rules inside of a configuration file, use the rules
key along with an error level and any options you want to use. For example:
{
"rules": {
"eqeqeq": "off",
"curly": "error",
"quotes": ["error", "double"]
}
}
And in YAML:
---
rules:
eqeqeq: off
curly: error
quotes:
- error
- double
Rules from Plugins
To configure a rule that is defined within a plugin, prefix the rule ID with the plugin name and /
.
In a configuration file, for example:
{
"plugins": [
"plugin1"
],
"rules": {
"eqeqeq": "off",
"curly": "error",
"quotes": ["error", "double"],
"plugin1/rule1": "error"
}
}
And in YAML:
---
plugins:
- plugin1
rules:
eqeqeq: 0
curly: error
quotes:
- error
- "double"
plugin1/rule1: error
In these configuration files, the rule plugin1/rule1
comes from the plugin named plugin1
, which is contained in an npm package named eslint-plugin-plugin1
.
You can also use this format with configuration comments, such as:
/* eslint "plugin1/rule1": "error" */
Note: When specifying rules from plugins, make sure to omit eslint-plugin-
. ESLint uses only the unprefixed name internally to locate rules.
Disabling Rules
To disable rule warnings in a part of a file, use block comments in the following format:
/* eslint-disable */
alert('foo');
/* eslint-enable */
You can also disable or enable warnings for specific rules:
/* eslint-disable no-alert, no-console */
alert('foo');
console.log('bar');
/* eslint-enable no-alert, no-console */
Note: /* eslint-enable */
without any specific rules listed causes all disabled rules to be re-enabled.
To disable rule warnings in an entire file, put a /* eslint-disable */
block comment at the top of the file:
/* eslint-disable */
alert('foo');
You can also disable or enable specific rules for an entire file:
/* eslint-disable no-alert */
alert('foo');
To ensure that a rule is never applied (regardless of any future enable/disable lines):
/* eslint no-alert: "off" */
alert('foo');
To disable all rules on a specific line, use a line or block comment in one of the following formats:
alert('foo'); // eslint-disable-line
// eslint-disable-next-line
alert('foo');
/* eslint-disable-next-line */
alert('foo');
alert('foo'); /* eslint-disable-line */
To disable a specific rule on a specific line:
alert('foo'); // eslint-disable-line no-alert
// eslint-disable-next-line no-alert
alert('foo');
alert('foo'); /* eslint-disable-line no-alert */
/* eslint-disable-next-line no-alert */
alert('foo');
To disable multiple rules on a specific line:
alert('foo'); // eslint-disable-line no-alert, quotes, semi
// eslint-disable-next-line no-alert, quotes, semi
alert('foo');
alert('foo'); /* eslint-disable-line no-alert, quotes, semi */
/* eslint-disable-next-line no-alert, quotes, semi */
alert('foo');
/* eslint-disable-next-line
no-alert,
quotes,
semi
*/
alert('foo');
All of the above methods also work for plugin rules. For example, to disable eslint-plugin-example
’s rule-name
rule, combine the plugin’s name (example
) and the rule’s name (rule-name
) into example/rule-name
:
foo(); // eslint-disable-line example/rule-name
foo(); /* eslint-disable-line example/rule-name */
Note: Comments that disable warnings for a portion of a file tell ESLint not to report rule violations for the disabled code. ESLint still parses the entire file, however, so disabled code still needs to be syntactically valid JavaScript.
Configuration comments can include descriptions to explain why disabling or re-enabling the rule is necessary. The description must come after the configuration and needs to be separated from the configuration by two or more consecutive -
characters. For example:
// eslint-disable-next-line no-console -- Here's a description about why this configuration is necessary.
console.log('hello');
/* eslint-disable-next-line no-console --
* Here's a very long description about why this configuration is necessary
* along with some additional information
**/
console.log('hello');
Using configuration files
To disable rules inside of a configuration file for a group of files, use the overrides
key along with a files
key. For example:
{
"rules": {...},
"overrides": [
{
"files": ["*-test.js","*.spec.js"],
"rules": {
"no-unused-expressions": "off"
}
}
]
}
To disable all inline config comments, use the noInlineConfig
setting in your configuration file. For example:
{
"rules": {...},
"noInlineConfig": true
}
You can also use the –no-inline-config CLI option to disable rule comments, in addition to other in-line configuration.
To report unused eslint-disable
comments, use the reportUnusedDisableDirectives
setting. For example:
{
"rules": {...},
"reportUnusedDisableDirectives": true
}
This setting is similar to –report-unused-disable-directives CLI option, but doesn’t fail linting (reports as "warn"
severity).
I have ESlint configured with vscode using the plugin, now I’m wondering is there some way I can stop ESlint from showing me the parser/syntax errors, so I can instead view the syntax errors that the Salsa language service provides by default.
Flip
6,1437 gold badges45 silver badges75 bronze badges
asked Mar 11, 2016 at 11:25
The old:
"eslint.enable": false
Is deprecated, now you need to use the builtin VSCode mechanism for disabling extensions:
answered Dec 12, 2020 at 18:46
melMassmelMass
3,5131 gold badge31 silver badges30 bronze badges
In order to disable ESLint only for a specific repo (instead of disabling it globally). Create .vscode
folder in your project root and there create a settings.json
then add the following config:
{
"eslint.enable": false
}
Maybe after this setting you should consider adding the .vscode/settings.json
line to your .gitignore
file too, but it is based on your dev team’s preference.
}
Additionally if you’d like to ignore only some vendor/3PP .js
files only then you should consider creating an .eslintignore
file. Read more about this here.
answered Mar 8, 2019 at 13:05
webpreneurwebpreneur
7959 silver badges15 bronze badges
2
go to File => Preferences => Settings
go to Extensions=>ESLint
Uncheck the EsLint:Enable
answered Oct 24, 2018 at 11:45
In VSCode, go to
File >> preferences >> settings
Type ‘eslint quiet’ in the search bar and click
the check box for quiet mode.
In quiet mode, eslint would ignore basic errors.
This should work for many VSCode users as at March 4, 2022.
You’re welcome!
answered Mar 4, 2022 at 17:33
Emeka OrjiEmeka Orji
1754 silver badges11 bronze badges
1
1-) npm install -g eslint
2-) Open up settings.json and add the property: "eslint.enable": false
answered Oct 24, 2018 at 9:12
Please open settings.json file and edit the configuration as below:
"eslint.enable": false
Hope this helps.
answered Sep 21, 2022 at 16:23
2
I don’t understand why some answers states that eslint.enable
is depracted. it works for me. in my WorkSpace settings (JSON), I add the following configuration and eslint errors disapears
{
...
"settings": {
"eslint.enable": false
},
}
answered Feb 15 at 15:24
snoob doggsnoob dogg
2,4083 gold badges29 silver badges53 bronze badges
Reading Time: 2 minutes
After applying ESLint to our codebase to automatic find problems and improve code quality, we may want to disable certain ESLint rules in specify code, file, folder or even whole project! Let’s look into them here.
Benefits of ESLint
There are quite a few benefits to integrate ESLint into projects.
- Analyse code to find problems
- Able to integrate with Git to prevent pushing of codes can break the rules
- Automatically fix code with VS Code
- Improve code quality
ESLint Disable Methods
There are various scope to which we can choose to disable for all rules or certain rules. Below are the more common ones. Let’s look into each of them.
1. Disable Current Line
To disable all ESLint rules check on a current single line code, we can add eslint-disable-line
on the right side of the code. If we want to specific only certain rules, we can append the rule name.
console.log('Ignore me'); // eslint-disable-line no-console
2. Disable Next Line
As disabling ESLint on the same line is not too readable, We can also use eslint-disable-next-line
to indicate that we will disable ESLint on next line code.
// eslint-disable-next-line no-console console.log('Ignore me');
3. Disable Block
If there are more than 2 lines to disable ESLint, we will use eslint-disable
block comment to indicate the start of the disabling and eslint-enable
block comment to indicate the end.
/* eslint-disable */ console.log('Ignore me 1'); console.log('Ignore me 2'); /* eslint-enable */
4. Disable File
Since eslint-disable
indicate the start of the disabling ESLint, we can place this at the beginning of the file to disable whole file.
/* eslint-disable no-console */ // The rest of the code import React from 'react'; ...
Although the above block comment method does work, it is not advisable as it will not be easily trackable. Hence, the other method is to use .eslintignore
to indicate the files to ignore.
We will place the .eslintignore
file in the root directory of the project, then add the file name with relative path into the file.
myfile.js src/component/myfile.js
5. Disable Folder
To disable ESLint in the whole folder, we will also make use of .eslintignore
file to indicate the folder to disable.
6. Disable Project
The most common way to disable is via project level since there might be some rules that we want to ignore fully.
We will first create a .eslintrc.json file, then we will enter in the rules to disable on project level like the illustration below.
{ "rules": { "eqeqeq": "off", "no-console": "off" } }
Conclusion
We have look at how we can disable ESLint base on the scope we want to disable. From a simple code line level to project level. Thus, we will need to decide which to choose base on use-case.
ESLint can be used to identify and fix code problems. By default, ESLint will warn or error on any code problems it finds. To ignore specific code problems, you can use the ignorePattern
option. This allows you to specify a regular expression which will be used to ignore any code problems that match it. For example, you can use ignorePattern: "^I[gnore]+$"
to ignore all code problems that contain the word «ignore». Additionally, you can use the "ignoreComments": true
option to ignore any code problems found in comments. This is useful if you want to allow comments that are not necessarily compliant with the coding style.
Table of Contents
- ignorePatterns in Config Files
- The .eslintignore File
- Using an Alternate File
- Using eslintIgnore in package.json
- Ignored File Warnings
You can configure ESLint to ignore certain files and directories while linting by specifying one or more glob patterns. You can ignore files in the following ways:
- Add
ignorePatterns
to a configuration file. - Create a dedicated file that contains the ignore patterns (
.eslintignore
by default).
ignorePatterns
in Config Files
You can tell ESLint to ignore specific files and directories using ignorePatterns
in your config files. ignorePatterns
patterns follow the same rules as .eslintignore
. Please see the .eslintignore
file documentation to learn more.
{ "ignorePatterns": ["temp.js", "**/vendor/*.js"], "rules": { } }
- Glob patterns in
ignorePatterns
are relative to the directory that the config file is placed in. - You cannot write
ignorePatterns
property underoverrides
property. - Patterns defined in
.eslintignore
take precedence over theignorePatterns
property of config files.
If a glob pattern starts with /
, the pattern is relative to the base directory of the config file. For example, /foo.js
in lib/.eslintrc.json
matches to lib/foo.js
but not lib/subdir/foo.js
.
If a config is provided via the --config
CLI option, the ignore patterns that start with /
in the config are relative to the current working directory rather than the base directory of the given config. For example, if --config configs/.eslintrc.json
is present, the ignore patterns in the config are relative to .
rather than ./configs
.
The .eslintignore
File
You can tell ESLint to ignore specific files and directories by creating a .eslintignore
file in your project’s root directory. The .eslintignore
file is a plain text file where each line is a glob pattern indicating which paths should be omitted from linting. For example, the following omits all JavaScript files:
When ESLint is run, it looks in the current working directory to find a .eslintignore
file before determining which files to lint. If this file is found, then those preferences are applied when traversing directories. Only one .eslintignore
file can be used at a time, so .eslintignore
files other than the one in the current working directory are not used.
Globs are matched using node-ignore, so a number of features are available:
- Lines beginning with
#
are treated as comments and do not affect the ignore patterns. - Paths are relative to the current working directory. This is also true of paths passed in via the
--ignore-pattern
command. - Lines preceded by
!
are negated patterns that re-include a pattern that was ignored by an earlier pattern. - Ignore patterns behave according to the
.gitignore
specification.
Of particular note is that like .gitignore
files, all paths used as patterns for both .eslintignore
and --ignore-pattern
must use forward slashes as their path separators.
/root/src/*.js rootsrc*.js
Please see .gitignore
’s specification for further examples of valid syntax.
In addition to any patterns in the .eslintignore
file, ESLint always follows a couple of implicit ignore rules even if the --no-ignore
flag is passed. The implicit rules are as follows:
-
node_modules/
is ignored. - dot-files (except for
.eslintrc.*
) as well as dot-folders and their contents are ignored.
There are also some exceptions to these rules:
-
If the path to lint is a glob pattern or directory path and contains a dot-folder, all dot-files and dot-folders are linted. This includes dot-files and dot-folders that are buried deeper in the directory structure.
For example,
eslint .config/
would lint all dot-folders and dot-files in the.config
directory, including immediate children as well as children that are deeper in the directory structure. -
If the path to lint is a specific file path and the
--no-ignore
flag has been passed, ESLint would lint the file regardless of the implicit ignore rules.For example,
eslint .config/my-config-file.js --no-ignore
would causemy-config-file.js
to be linted. It should be noted that the same command without the--no-ignore
line would not lint themy-config-file.js
file. -
Allowlist and denylist rules specified via
--ignore-pattern
or.eslintignore
are prioritized above implicit ignore rules.For example, in this scenario,
.build/test.js
is the desired file to allowlist. Because all dot-folders and their children are ignored by default,.build
must first be allowlisted so that eslint becomes aware of its children. Then,.build/test.js
must be explicitly allowlisted, while the rest of the content is denylisted. This is done with the following.eslintignore
file:# Allowlist 'test.js' in the '.build' folder # But do not allow anything else in the '.build' folder to be linted !.build .build/* !.build/test.js
The following
--ignore-pattern
is also equivalent:eslint --ignore-pattern '!.build' --ignore-pattern '.build/*' --ignore-pattern '!.build/test.js' parent-folder/
Using an Alternate File
If you’d prefer to use a different file than the .eslintignore
in the current working directory, you can specify it on the command line using the --ignore-path
option. For example, you can use .jshintignore
file because it has the same format:
eslint --ignore-path .jshintignore file.js
You can also use your .gitignore
file:
eslint --ignore-path .gitignore file.js
Any file that follows the standard ignore file format can be used. Keep in mind that specifying --ignore-path
means that the existing .eslintignore
file is not used. Note that globbing rules in .eslintignore
follow those of .gitignore
.
Using eslintIgnore in package.json
If an .eslintignore
file is not found and an alternate file is not specified, ESLint looks in package.json
for the eslintIgnore
key to check for files to ignore.
{ "name": "mypackage", "version": "0.0.1", "eslintConfig": { "env": { "browser": true, "node": true } }, "eslintIgnore": ["hello.js", "world.js"] }
Ignored File Warnings
When you pass directories to ESLint, files and directories are silently ignored. If you pass a specific file to ESLint, then ESLint creates a warning that the file was skipped. For example, suppose you have an .eslintignore
file that looks like this:
And then you run:
You’ll see this warning:
foo.js 0:0 warning File ignored because of a matching ignore pattern. Use "--no-ignore" to override. ✖ 1 problem (0 errors, 1 warning)
This message occurs because ESLint is unsure if you wanted to actually lint the file or not. As the message indicates, you can use --no-ignore
to omit using the ignore rules.
Consider another scenario where you want to run ESLint on a specific dot-file or dot-folder, but have forgotten to specifically allow those files in your .eslintignore
file. You would run something like this:
You would see this warning:
.config/foo.js 0:0 warning File ignored by default. Use a negated ignore pattern (like "--ignore-pattern '!<relative/path/to/filename>'") to override ✖ 1 problem (0 errors, 1 warning)
This message occurs because, normally, this file would be ignored by ESLint’s implicit ignore rules (as mentioned above). A negated ignore rule in your .eslintignore
file would override the implicit rule and reinclude this file for linting. Additionally, in this case, --no-ignore
could be used to lint the file as well.
ESLint
8.30
-
Configuration Files (New)
This is an experimental feature. To opt-in, place an eslint. config. js file in the root of your project or set the ESLINT_USE_FLAT_CONFIG environment variable to true.
-
Configuring language options
Options specific to how ESLint evaluates your JavaScript code can be configured using the languageOptions object.To configure the version of JavaScript (ECMAScript) that ESLint uses to evaluate your JavaScript.
-
Configuring ESLint
ESLint is designed to be flexible and configurable for your use case. You can turn off every rule and run only with basic syntax validation or mix and match the bundled rules and your custom rules to fit the needs of your project.
-
Language Options
The JavaScript ecosystem has a variety of runtimes, versions, extensions, and frameworks. Each of these can have different supported syntax and global variables.