Disable a specific linter rule in Atom (for js-standard)

断了今生、忘了曾经 提交于 2019-12-19 07:24:23

问题


How do I tell an Atom linter, specifically js-standard, to ignore a rule? I want it ignored project-wide, and I thought that I could achieve this with a package.json or a .eslintrc but I can't get either to work. The rule I want to disable is camelcase

I should be able to do this in a package.json file, because the js-standard linter has an option called honorStyleSettings:

Honors style settings defined in package.json.

Current style settings supported:

ignore
parser

What's the syntax of these settings?


回答1:


For the record, here's how to use js-standard in Atom while selectively disabling a certain rule.

  1. Disable the linter-js-standard atom package
  2. Install linter-eslint
  3. Add an .eslintrc file:

    {
      "extends": ["standard"],
      "rules": {
        "camelcase": 0
      }
    }
    

You may also need to install standard and eslint via npm, if you don't have them already.




回答2:


Using the default install, there is no way to do this in linter-js-standard. (I believe this was a conscious decision on the part of the module authors who believe that standard is a hard target rather than an ideal.)

If you wish to use eslint-style comments to disable linting for certain lines or code sections, install babel-eslint via npm i --save-dev babel-eslint and add

{
  ...
  "standard": {
    "parser": "babel-eslint"
  }
  ...
}

to your package.json file which will allow you to annotate your source as needed.

Example

Assuming foo is defined but not used elsewhere in your file, linter will warn: 'foo is assigned a value but never used. (no-unused-vars)'

const foo = 1

After installing babel-eslint, configuring standard in your package.json file, and adding this comment, linter will ignore the line.

const foo = 1 // eslint-disable-line

See Configuring ESLint for other configuration annotations.




回答3:


I've managed to disable the "camelcase" rule by going to "linter-js-standard" package folder and adding to node_modules/standard/eslintrc.json file the following line:

"rules": { "camelcase": [0] }

So the entire "eslintrc.json" looks like:

{
  "extends": ["standard", "standard-jsx"],
  "rules": { "camelcase": [0] }
}

Just save or edit your .js file in Atom for the changes to take effect.

On my Linux desktop the full path to eslintrc.json is:

~/.atom/packages/linter-js-standard/node_modules/standard/eslintrc.json

Of course, when you update the "linter-js-standard" package in Atom, you'll have to do the above steps again.

To turn the "camelcase" rule on you may change the "camelcase" value to [2] instead of deleting the entire "rules" line:

"rules": { "camelcase": [2] }



回答4:


If it is ESlint that your plugin uses then create a .eslintrc file in the root of your project & write your rules within there.

Heres an example of a .eslintrc file github example. I find i need to close and reopen Atom to refresh the lint errors

EDIT:

showEslintRules (default: false). You will need to change this option to true.



来源:https://stackoverflow.com/questions/37426512/disable-a-specific-linter-rule-in-atom-for-js-standard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!