我应该如何将 *.eslintrc* 更新为 ESLint 以查看更改?
How should I update *.eslintrc* to ESLint see the changes?
我想在我的 JavaScript 项目中使用 ESLint。我使用 Project Reactor、Spring Boot、ReactJS 和 Webpack。我在 pom.xml.
附近的根文件夹中创建了 .eslintrc 文件
ESLint 似乎有效。当我申请
eslint src\main\js\components
它说
1:1 error Parsing error: 'import' and 'export' may appear only with 'sourceType: module'
好的,我找到了 并更新了我的 .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
}
}
但这于事无补。
我在我的项目目录中搜索了 .eslintrc 文件,发现可能 .eslintrc, .eslintrc.json, .eslintrc.yml 文件,但它们没有 sourceType: module。似乎它们是由 npm install
命令生成的。其中之一:
{
"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]
}
}
我试图重建项目,删除所有 .eslintrc 除了我的。
我的 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"
}
我应该如何更新 .eslintrc 到 ESLint 才能看到变化?
为什么要创建额外的 eslint 文件?
您似乎在自身内部嵌套了 parserOptions
:
"parserOptions": {
"parserOptions": { "sourceType": "module" }
},
删除一层嵌套,它应该可以工作:
"parserOptions": {
"sourceType": "module"
},
Why additional eslint files are created?
他们在 node_modules
之下吗?它们将来自您的依赖项。您不必担心它们。
我想在我的 JavaScript 项目中使用 ESLint。我使用 Project Reactor、Spring Boot、ReactJS 和 Webpack。我在 pom.xml.
附近的根文件夹中创建了 .eslintrc 文件ESLint 似乎有效。当我申请
eslint src\main\js\components
它说
1:1 error Parsing error: 'import' and 'export' may appear only with 'sourceType: module'
好的,我找到了
{
"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
}
}
但这于事无补。
我在我的项目目录中搜索了 .eslintrc 文件,发现可能 .eslintrc, .eslintrc.json, .eslintrc.yml 文件,但它们没有 sourceType: module。似乎它们是由 npm install
命令生成的。其中之一:
{
"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]
}
}
我试图重建项目,删除所有 .eslintrc 除了我的。
我的 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"
}
我应该如何更新 .eslintrc 到 ESLint 才能看到变化? 为什么要创建额外的 eslint 文件?
您似乎在自身内部嵌套了 parserOptions
:
"parserOptions": {
"parserOptions": { "sourceType": "module" }
},
删除一层嵌套,它应该可以工作:
"parserOptions": {
"sourceType": "module"
},
Why additional eslint files are created?
他们在 node_modules
之下吗?它们将来自您的依赖项。您不必担心它们。