How to config ESLint for React on Atom Editor

后端 未结 5 733
自闭症患者
自闭症患者 2020-12-12 20:52

In Atom Editor I installed the following plugins

  1. linter
  2. linter-eslint

It seems they don\'t recognize the JSX syntaxis.

I have

相关标签:
5条回答
  • 2020-12-12 20:57

    To get Eslint working nicely with React.js:

    1. Install linter & linter-eslint plugins
    2. Run npm install eslint-plugin-react
    3. Add "plugins": ["react"] to your .eslintrc config file
    4. Add "ecmaFeatures": {"jsx": true} to your .eslintrc config file

    Here is an example of a .eslintrc config file:

    {
        "env": {
            "browser": true,
            "node": true
        },
    
        "globals": {
            "React": true
        },
    
        "ecmaFeatures": {
            "jsx": true
        },
    
        "plugins": [
            "react"
        ]
    }
    

    I am using Eslint v1.1.0 at the moment.

    Side note: I had to install both eslint and eslint-plugin-react as project dependencies (e.g., npm install eslint eslint-plugin-react --save-dev). Hopefully this helps.

    0 讨论(0)
  • 2020-12-12 21:07

    Updated answer for 2016: just install the react package in Atom and add a .eslintrc file in your project root (or in your home dir) containing the following:

    {
      "parserOptions": {
        "ecmaFeatures": {
          "jsx": true
        }
      },
      "env": {
        "es6": true
      }
    }
    

    And re-open any files containing JSX and it should work.

    0 讨论(0)
  • 2020-12-12 21:12

    You need to edit a project local .eslintrc file that will get picked up by ESLint. If you want integration with Atom, you can install the plugins linter and linter-eslint.

    To quickly setup ESLint for React best practices, current best option is installing the npm package eslint-plugin-react and extending their recommended configuration instead of toggling many rules manually:

    {
      "extends": [ "eslint:recommended", "plugin:react/recommended" ],
      "plugins": [ "react" ]
    }
    

    This will enable eslint-plugin-react and recommended rules from ESLint & React presets. There is more valuable information in the latest ESLint user-guide itself.

    Here is an example of parser options optimized for ES6 and webpack:

    {
      "parserOptions": {
        "sourceType": "module",
        "ecmaVersion": 6,
        "ecmaFeatures": {
          "impliedStrict": true,
          "experimentalObjectRestSpread": true,
          "jsx": true
        }
      }
    }
    
    0 讨论(0)
  • 2020-12-12 21:16

    I use Atom and it works just fine. You just need an .eslintrc in your project root which tells ESLint that you're using eslint-plugin-react.

    0 讨论(0)
  • 2020-12-12 21:19
    1. For Mac user: Go to Atom --> preferences --> Install --> search package linter-eslint --> click install

    2. For Ubuntu user: Go to Edit --> preferences --> Install --> search package linter-eslint --> click install

    3. go to command line ---> npm install --save-dev eslint-config-rallycoding

    4. Come to atom make new file .eslintrc and extend the rallycoding.

    0 讨论(0)
提交回复
热议问题