Как отключить ошибки eslint

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's user avatar

Flip

6,2737 gold badges46 silver badges75 bronze badges

asked Mar 11, 2016 at 11:25

user3690467's user avatar

The old:

"eslint.enable": false

Is deprecated, now you need to use the builtin VSCode mechanism for disabling extensions:

vscode-screenshot

answered Dec 12, 2020 at 18:46

melMass's user avatar

melMassmelMass

3,8531 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

webpreneur's user avatar

webpreneurwebpreneur

80510 silver badges15 bronze badges

2

go to File => Preferences => Settings

enter image description here

go to Extensions=>ESLint

enter image description here

Uncheck the EsLint:Enable

enter image description here

answered Oct 24, 2018 at 11:45

Prakash Nagaraj's user avatar

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 Orji's user avatar

Emeka OrjiEmeka Orji

1744 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

Yasin Tazeoglu's user avatar

If you want to disable eslint errors in VSCode, Go to settings.json and disable all rules like this

   "eslint.rules.customizations": [
    {
        "rule": "*",
        "severity": "off"
    }
]

This will disable all the eslint rules for you. If you want to disable a particular rule like «@typescript-eslint/no-this-alias», you can do the following

"eslint.rules.customizations": [
        {
            "rule": "@typescript-eslint/no-this-alias",
            "severity": "off"
        }
    ]

answered Sep 6 at 8:50

suyashpatil's user avatar

Please open settings.json file and edit the configuration as below:

"eslint.enable": false

Hope this helps.

answered Sep 21, 2022 at 16:23

Mahfuz Khandaker's user avatar

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 dogg's user avatar

snoob doggsnoob dogg

2,4993 gold badges31 silver badges55 bronze badges

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's user avatar

Flip

6,2737 gold badges46 silver badges75 bronze badges

asked Mar 11, 2016 at 11:25

user3690467's user avatar

The old:

"eslint.enable": false

Is deprecated, now you need to use the builtin VSCode mechanism for disabling extensions:

vscode-screenshot

answered Dec 12, 2020 at 18:46

melMass's user avatar

melMassmelMass

3,8531 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

webpreneur's user avatar

webpreneurwebpreneur

80510 silver badges15 bronze badges

2

go to File => Preferences => Settings

enter image description here

go to Extensions=>ESLint

enter image description here

Uncheck the EsLint:Enable

enter image description here

answered Oct 24, 2018 at 11:45

Prakash Nagaraj's user avatar

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 Orji's user avatar

Emeka OrjiEmeka Orji

1744 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

Yasin Tazeoglu's user avatar

If you want to disable eslint errors in VSCode, Go to settings.json and disable all rules like this

   "eslint.rules.customizations": [
    {
        "rule": "*",
        "severity": "off"
    }
]

This will disable all the eslint rules for you. If you want to disable a particular rule like «@typescript-eslint/no-this-alias», you can do the following

"eslint.rules.customizations": [
        {
            "rule": "@typescript-eslint/no-this-alias",
            "severity": "off"
        }
    ]

answered Sep 6 at 8:50

suyashpatil's user avatar

Please open settings.json file and edit the configuration as below:

"eslint.enable": false

Hope this helps.

answered Sep 21, 2022 at 16:23

Mahfuz Khandaker's user avatar

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 dogg's user avatar

snoob doggsnoob dogg

2,4993 gold badges31 silver badges55 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" or 0 — turn the rule off
  • "warn" or 1 — turn the rule on as a warning (doesn’t affect exit code)
  • "error" or 2 — 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

  • Use with Caution. Disabling ESLint rules inline should be restricted and used only in situations with a clear and
    valid reason for doing so. Disabling rules inline should not be the default solution to resolve linting errors.
  • Document the Reason. Provide a comment explaining the reason for disabling a particular rule after the -- section of the comment. This
    documentation should clarify why the rule is being disabled and why it is necessary in that specific situation.
  • Temporary Solutions. If a disable comment is added as a temporary measure to address a pressing issue, create a follow-up task to address the underlying problem adequately. This ensures that the
    disable comment is revisited and resolved at a later stage.
  • Code Reviews and Pair Programming. Encourage team members to review each other’s code regularly. Code reviews can help
    identify the reasons behind disable comments and ensure that they are used appropriately.
  • Configurations. Whenever possible, prefer using ESLint configuration files over disable comments. Configuration
    files allow for consistent and project-wide rule handling.

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).

ESLint — очень удобный инструмент контроля стиля кода. Но иногда, его нужно отключить. В этой заметке, я расскажу как это сделать.

Общий случай

Для примера, представим, что ESLint ругается у нас в файле есть console.log().

Чтобы временно отключить ESLint, нужно добавить комментарий /* eslint-disable */ перед строками, которые мы хотим проигнорировать:

/* eslint-disable */
console.log('JavaScript debug log');
console.log('eslint is disabled now');

ESLint отключится, как только увидит такой комментарий и не будет анализировать все что идет после него.

Чтобы включить ESLint обратно, используется комментарий /* eslint-enable */.

/* eslint-disable */
console.log('JavaScript debug log');
console.log('eslint is disabled now');
/* eslint-enable */

Чтобы отключить не все правила, а только какие-то определенные, нужно перечислить их в тех же комментариях через запятую:

/* eslint-disable no-console, no-control-regex*/
console.log('JavaScript debug log');
console.log('eslint is disabled now');

Правила eslint-disable и eslint-enable должны всегда находится в блочных комментариях. Так работать не будет:

// eslint-disable no-console, no-control-regex
console.log('JavaScript debug log');
console.log('eslint is disabled now');

Одна строка

Чтобы отключить ESLint для одной строки, можно использовать для варианта.

Для текущей строки — строчный комментарий после окончания строки:

console.log('eslint is disabled for the current line'); // eslint-disable-line

Для следующей строки — строчный комментарий выше строки которую мы отключаем:

// eslint-disable-next-line
console.log('eslint is disabled for the current line');

Весь файл или папка

Чтобы отключить ESLint во всем файле, можно добавить /* eslint-disable */ в первой строке этого файла.

Альтернативно, можно создать файл .eslintignore в корневой директории проекта. Формат этого файла совпадает с форматом .gitignore и ты можешь добавить туда не только файлы, но и папки.

build/*.js
config/*.js
bower_components/foo/*.js

If I add any given ESLint rule, for example no-param-reassign in an existing codebase I’m likely to get many violations.

Is there a good way to programmatically add, on line-by-line bases, suppressions for all existing violations?

In the example case:

// eslint-diable-next-line no-param-reassign
param = foo;

To clarify

I do want the rule in my project, guarding all new code we write. I don’t want to fix all the old code that is emitting violations by hand (I want a script to do that for me or eslint itself if possible). This is why I would like to suppress all existing violations but respect all new violations. My main goal is to comply with the new rule as fast as possible to get the value from it on all new code. I don’t mind old lingering suppressed violations.

asked Mar 11, 2020 at 3:50

Red Mercury's user avatar

Red MercuryRed Mercury

3,9811 gold badge26 silver badges32 bronze badges

5

I was having this same issue with a bunch of react-hooks/exhaustive-deps lint warnings ended up using the json formatter and a script to insert the eslint disable comment. I ran yarn lint . -f json -o warnings.json to get the json list of lints and then this

const json = require('./warnings.json');
const fs = require('fs');

json.forEach(({ filePath, messages, source }) => {
  // if there is no source we have nothing that needs to be eslint-ignore'd
  if (!source) {
    return;
  }

  const data = source.split('\n');

  // if the source has multiple lines which need to be eslint-ignored our offset changes per addition
  // offset is 1 because line numbers start at 1 but index numbers in an array start at 0
  let offset = 1;

  // group errors/warnings by line because we want to have one eslint disable comment with all the rules to disable
  const groupedMessages = messages.reduce((acc, next) => {
    const prevMessages = acc[next.line] ? acc[next.line] : [];
    // some lines may have the same rule twice
    const duplicateRuleForLine = prevMessages.find(message => message.ruleId === next.ruleId);
    // ignore jsx and graphql lint rules
    const applicableRule = next.ruleId && !next.ruleId.includes('jsx') && !next.ruleId.includes('graphql');

    // ignore the eslint-ignore addition for duplicates and non applicable rules
    if (duplicateRuleForLine || !applicableRule) {
      return acc;
    }

    return {
      ...acc,
      [next.line]: [...prevMessages, next],
    };
  }, {});

  Object.entries(groupedMessages).forEach(([line, messages]) => {
    // grouped ignores
    const ignore = `// eslint-disable-next-line ${messages.map(({ ruleId }) => ruleId).join(' ')}`;
    data.splice(line - offset, 0, ignore);
    offset--;
  });

  const updated = data.join('\n');

  fs.writeFile(filePath, updated, function(err) {
    if (err) return console.log(err);
  });
});

Worked out well for me, although I wish these comments I inserted were auto-formatted.

answered Sep 22, 2020 at 21:08

Jonathan Portorreal's user avatar

2

I tried suppress-eslint-errors npm answered by @user15185791, but it did not work with ESLint8.
But, I was able to find https://github.com/mizdra/eslint-interactive from that npm issue.
So far this wonderful npm is working perfectly.

The execution is as follows command.

yarn add -D eslint-interactive
yarn eslint-interactive src
yarn remove eslint-interactive

answered Aug 2, 2022 at 13:20

katsusuke's user avatar

katsusukekatsusuke

4715 silver badges5 bronze badges

You can remove the particular rule that you don’t want in your project by modifying the .eslintrc.* file or an eslintConfig field in a package.json file. As they are responsible for the rules in your project. If you remove any rule from them, your editor will stop looking for that violation.

If you still want those rule for future development then don’t modify your rules config file, instead of that there are two things that you can do,

  1. Suppress the old code that is violating the rules.

  2. Fix them. (recommended)

answered Mar 11, 2020 at 3:56

Anurodh Singh's user avatar

3

For an individual line:

// eslint-disable-next-line

For a block

/* eslint-disable */
// liniting issues here
/* eslint-enable */

Without eslint-disable, linting will be disabled for the rest of the file

answered Mar 11, 2020 at 4:37

Brian Barnes's user avatar

Brian BarnesBrian Barnes

1,0097 silver badges15 bronze badges

If you don’t want to go file by file adding these directives, you could use ESLint overrides feature. In .eslintrc:

{
  /*
    Main set of properties here
    ...
  */
  overrides: [
    {
      files: [
        /*
          List of glob patterns matching files that should have
          some rules overwritten
        */
      ],
      rules: [
        /* 
          Add the common rules here, otherwise they'll be overwritten.
          After that, add the ones you want to disable:
        */
        no-param-reassign: 0,
      ]
    },
  ],
}

Otherwise, if you want to disable a rule in a single line, you just need to do like this:

// eslint-disable-nex-line <rule name>

Finally, if you want to disable a rule in many lines of code, you can use:

// eslint-disable <rule name>

// Code on which the rule shouldn't be applied
// ...

// eslint-enable <rule name>

answered Mar 11, 2020 at 10:18

Daniel Alves's user avatar

Понравилась статья? Поделить с друзьями:
  • Как осознать свою ошибку
  • Как отключить ошибка ssl
  • Как определяется предельная ошибка выборки
  • Как отключить отчеты об ошибках windows 10
  • Как определить уровень существенности допущенной ошибки