javascript - 我应该如何将 *.eslintrc* 更新为 ESLint 查看更改?
问题描述
我想在我的 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"
},
为什么要创建额外的 eslint 文件?
他们在node_modules
吗?它们将来自您的依赖项。你不应该担心他们。
推荐阅读
- mysql-workbench - mysql工作台SSL连接错误:SSL_CTX_set_default_verify_paths失败
- json - 如何在 Swift 中从 JSON 创建对象?
- python - U-net:如何提高多类分割的准确性?
- swift - 如何为 iOS 和 macOS 设置不同的切换样式
- twitter-bootstrap - Firefox 在打印 Bootstrap + Google Fonts 时会切断单词的结尾
- regex - float(x,y) 的正则表达式可能吗?
- c++ - 编写了一个 C++ 代码来检查表达式是否有平衡括号并且我的代码没有运行。我已经卡了一天了
- c# - C# EventHandler:如何在客户端应用程序中处理 EventHandler?
- flutter - 获取 Flutter Cupertino_icons 依赖错误
- python - 从 PyQt 线程传回多个参数