简体   繁体   中英

How should I update *.eslintrc* to ESLint see the changes?

I want to use ESLint on my JavaScript project. I use Project Reactor, Spring Boot, ReactJS and Webpack. I created .eslintrc file in the root folder near pom.xml.

It seems ESLint works. When I apply

eslint src\main\js\components

it says

1:1 error Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

Ok, I have found this and updated my .eslintrc :

{
"env": {
    "browser": true,
    "commonjs": true,
    "node": true,
    "es6": true
},
"extends": "eslint:recommended",
"parserOptions": {
    "parserOptions": { "sourceType": "module" }
},
"plugins": [
    "react"
],
"rules": {
    "indent": [
        "error",
        "tab"
    ],
    "linebreak-style": [
        "error",
        "unix"
    ],
    "quotes": [
        "error",
        "double"
    ],
    "semi": [
        "error",
        "always"
    ],
    "import":"true",
    "keyword-spacing": 2
}
}

But that does not help.

I searched .eslintrc files in my project directory and found may .eslintrc , .eslintrc.json , .eslintrc.yml files, but they does not have sourceType: module . Seems they are generated by npm install command. One of them:

{
"rules": {
    "id-length": 0,
    "max-lines": 0,
    "max-statements-per-line": [2, { "max": 3 }],
    "max-nested-callbacks": [2, 3],
    "max-statements": 0,
    "no-implicit-coercion": [1],
    "no-invalid-this": [1]
}
}

I tried to rebuild the project, delete all .eslintrc except mine.

My packages.json contains:

"devDependencies": {
"babel-core": "^6.18.2",
"babel-loader": "^6.2.7",
"babel-polyfill": "^6.16.0",
"babel-preset-es2015": "^6.18.0",
"babel-preset-react": "^6.16.0",
"css-loader": "^0.26.4",
"eslint": "^5.0.0",
"eslint-plugin-react": "^7.10.0",
"extract-text-webpack-plugin": "^2.1.0",
"file-loader": "^1.1.10",
"image-webpack-loader": "^4.1.0",
"react-redux": "^5.0.7",
"style-loader": "^0.13.2",
"url-loader": "^0.6.2",
"webpack": "^2.2.1"
}

How should I update .eslintrc to ESLint see the changes? Why additional eslint files are created?

You seem to have nested parserOptions inside itself:

"parserOptions": {
    "parserOptions": { "sourceType": "module" }
},

Remove one level of nesting and it should work:

"parserOptions": {
    "sourceType": "module"
},

Why additional eslint files are created?

Are they under node_modules ? They'll be from your dependencies. You shouldn't need to worry about them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM