Configuring ESLint

  1. Configuration Comments - use JS comments to embed configuration information directly into a file.

  2. Configuration Files - use a JS, JSON, or YAML file to specify configuration information for an entire directory and all of its subdirectories. This can be in the form of an .eslintrc file or an eslintConfig field in a package.json file, both of which ESLint will look for and reed automatically, or you can specify a configuration file on the command line.

Specifying Parser Options

ESLint allows you to specify the JS language options you want to support. By Default, ESLint support only ES5 syntax. You can override that setting to enable support for ES6 and 7 as well as JSX by using parser options.

Parser options are set in your .eslintrc file by using the parserOptions property. The available options are:

  • ecmaVersion - set to 3, 5(default), 6 or 7 to specify the version of ECMAScript you want to use.
  • sourceType - set to "script" (default) or "module" if your code is in ECMAScript modules.
  • emcaFeatures - an object indicating which additional language features you’d like to use:

    *   `globalReturn` - allow `return` statements in the global scope.
    
    • impliedStrict - enable global strict mode (if ecmaVersion is 5 or greater)
    • jsx: enable JSX
    • experimentalObjectRestSpread - enable support for the experimental object rest/spread properties

An example:

{
  "parserOptions":{
    "emcaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    }
  },
  "rules":{
    "semi": 2
  }
}
`</pre>

### Specifying Parser

By Default, ESLint uses `Espree` as its parser. You can optionally specify that a different parser should be used in your configuration file so long as the parser meets the following requirements:
  • It must be an npm module installled locally;
  • It must have an Esprima-compatible interface
  • It must produce Esprima-compatible AST and token objects.

    Specifying ENV

  • browser

  • node
  • commonjs
  • es6
  • mocha

    `{
      "env":{
        "browser": true,
        "node": true
      }
    }
    
    ### Configuring Rules
    
    ESLint comes with a large number of rules, you can modify which rules your project use either using configuration comments or configuration files. To change a rules setting, you must set the rule ID equal to one of these values: 
    
    - `"off"` or `0` to turn rule off.
    - `"warn"` or `1` to turn the rule as a warning(doesn't affect exit code)
    - `"error"` or `2` to turn the rule on as an error(exit code is 1 when triggered)
    
    ### Demo
    
    `

    npm install -g eslint

    `

eslint –init
`` 生成.eslintrc.js`

但是这个文件最好手动生成

# ESLint

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×