简体   繁体   English

我应该如何将* .eslintrc *更新为ESLint以查看更改?

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

I want to use ESLint on my JavaScript project. 我想在我的JavaScript项目上使用ESLint。 I use Project Reactor, Spring Boot, ReactJS and Webpack. 我使用Project Reactor,Spring Boot,ReactJS和Webpack。 I created .eslintrc file in the root folder near pom.xml. 我在pom.xml附近的根文件夹中创建了.eslintrc文件。

It seems ESLint works. 看来ESLint有用。 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 : 好吧,我发现并更新了.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 . 我在项目目录中搜索了.eslintrc文件,发现可能有.eslintrc.eslintrc.json.eslintrc.yml文件,但它们没有sourceType:module Seems they are generated by npm install command. 似乎它们是由npm install命令生成的。 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. 我试图重建项目,删除除我以外的所有.eslintrc

My packages.json contains: 我的packages.json包含:

"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? 如何将.eslintrc更新为ESLint,以查看更改? Why additional eslint files are created? 为什么要创建其他eslint文件?

You seem to have nested parserOptions inside itself: 您似乎在自己内部嵌套了parserOptions

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

Remove one level of nesting and it should work: 删除一层嵌套,它应该起作用:

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

Why additional eslint files are created? 为什么要创建其他eslint文件?

Are they under node_modules ? 它们在node_modules下吗? They'll be from your dependencies. 它们将来自您的依赖项。 You shouldn't need to worry about them. 您无需担心它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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