如何固定eslint配置?
我有node.js项目,并从eslint配置开始。有.eslintrc.json
{
"parser": "babel-eslint",
"extends": [
"airbnb",
"plugin:node/recommended",
"plugin:security/recommended",
"prettier",
],
"env": {
"node":true,
"commonjs": true,
"es6": true,
},
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"plugins": [
"prettier"
],
"rules": {
"prettier/prettier": "error",
"node/exports-style": ["error", "module.exports"],
"node/file-extension-in-import": ["error", "always"],
"node/prefer-global/buffer": ["error", "always"],
"node/prefer-global/console": ["error", "always"],
"node/prefer-global/process": ["error", "always"],
"node/prefer-global/url-search-params": ["error", "always"],
"node/prefer-global/url": ["error", "always"],
"node/prefer-promises/dns": "error",
"node/prefer-promises/fs": "error",
},
}
和package.json
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "server.js",
"license": "ISC",
"lint-staged": {
"*.{js,jsx}": [
"eslint --fix",
"git add"
],
"*.scss": [
"stylelint --fix",
"git add"
]
},
"scripts": {
"development": "nodemon",
"test": "echo \"Error: no test specified\" && exit 1",
"start": "babel-node server.js",
"eslint": "eslint config '**/*.js' --ext .js",
"prettier": "prettier '**/*.js' --write",
"stylelint": "stylelint '**/*.js'"
},
"author": "",
"dependencies": {
"@babel/polyfill": "^7.6.0",
"body-parser": "^1.19.0",
"cookie-parser": "^1.4.4",
"cors": "^2.8.5",
"express": "^4.17.1",
"helmet": "^3.21.0",
"history": "^4.9.0",
"mongoose": "^5.6.13",
"nodemon": "^1.19.2"
},
"devDependencies": {
"@babel/cli": "^7.6.4",
"@babel/core": "^7.6.0",
"@babel/node": "^7.6.3",
"@babel/plugin-proposal-class-properties": "7.3.3",
"@babel/plugin-proposal-json-strings": "7.2.0",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/plugin-syntax-import-meta": "7.2.0",
"@babel/preset-env": "^7.3.1",
"@commitlint/cli": "^7.5.2",
"@commitlint/config-conventional": "^7.5.0",
"autoprefixer": "^9.4.7",
"babel-eslint": "^10.0.3",
"babel-loader": "^8.0.6",
"babel-preset-env": "^1.7.0",
"cross-env": "^5.2.0",
"eslint": "^6.4.0",
"eslint-config-airbnb": "^18.0.1",
"eslint-config-prettier": "^6.3.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-prettier": "^3.1.0",
"husky": "^1.3.1",
"lint-staged": "^8.1.4",
"prettier": "^1.18.2",
"rimraf": "^2.6.3",
"stylelint": "^10.1.0",
"stylelint-config-standard": "^18.3.0",
"stylelint-order": "^3.1.0"
}
}
[当我尝试从目录根目录写入yarn run eslint时出现错误:
$纱run纱线运行v1.17.3
warning ../package.json:没有许可证字段$ eslint config'** / *。js'--ext .js
糟糕!出问题了! :(
ESLint:6.4.0。
无法在]读取JSON文件>
/ Users / vladyslavsymonenko / Chess / server / .eslintrc.json:
无法读取配置文件:> /Users/vladyslavsymonenko/Chess/server/.eslintrc.json错误:位置1040中的JSON中的意外令牌]
错误命令失败,退出代码为2。info请访问;此命令的文档。
我对结果真的很困惑,请帮助我)
我有node.js项目,并从eslint配置开始。有.eslintrc.json {“ parser”:“ babel-eslint”,“ extends”:[“ airbnb”,“ plugin:node / recommended”,“ plugin:security / ...
回答如下:您需要从.eslintrc中删除所有结尾的逗号(例如第7行的"prettier",
,因为它不是有效的JSON:
如何固定eslint配置?
我有node.js项目,并从eslint配置开始。有.eslintrc.json
{
"parser": "babel-eslint",
"extends": [
"airbnb",
"plugin:node/recommended",
"plugin:security/recommended",
"prettier",
],
"env": {
"node":true,
"commonjs": true,
"es6": true,
},
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"plugins": [
"prettier"
],
"rules": {
"prettier/prettier": "error",
"node/exports-style": ["error", "module.exports"],
"node/file-extension-in-import": ["error", "always"],
"node/prefer-global/buffer": ["error", "always"],
"node/prefer-global/console": ["error", "always"],
"node/prefer-global/process": ["error", "always"],
"node/prefer-global/url-search-params": ["error", "always"],
"node/prefer-global/url": ["error", "always"],
"node/prefer-promises/dns": "error",
"node/prefer-promises/fs": "error",
},
}
和package.json
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "server.js",
"license": "ISC",
"lint-staged": {
"*.{js,jsx}": [
"eslint --fix",
"git add"
],
"*.scss": [
"stylelint --fix",
"git add"
]
},
"scripts": {
"development": "nodemon",
"test": "echo \"Error: no test specified\" && exit 1",
"start": "babel-node server.js",
"eslint": "eslint config '**/*.js' --ext .js",
"prettier": "prettier '**/*.js' --write",
"stylelint": "stylelint '**/*.js'"
},
"author": "",
"dependencies": {
"@babel/polyfill": "^7.6.0",
"body-parser": "^1.19.0",
"cookie-parser": "^1.4.4",
"cors": "^2.8.5",
"express": "^4.17.1",
"helmet": "^3.21.0",
"history": "^4.9.0",
"mongoose": "^5.6.13",
"nodemon": "^1.19.2"
},
"devDependencies": {
"@babel/cli": "^7.6.4",
"@babel/core": "^7.6.0",
"@babel/node": "^7.6.3",
"@babel/plugin-proposal-class-properties": "7.3.3",
"@babel/plugin-proposal-json-strings": "7.2.0",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/plugin-syntax-import-meta": "7.2.0",
"@babel/preset-env": "^7.3.1",
"@commitlint/cli": "^7.5.2",
"@commitlint/config-conventional": "^7.5.0",
"autoprefixer": "^9.4.7",
"babel-eslint": "^10.0.3",
"babel-loader": "^8.0.6",
"babel-preset-env": "^1.7.0",
"cross-env": "^5.2.0",
"eslint": "^6.4.0",
"eslint-config-airbnb": "^18.0.1",
"eslint-config-prettier": "^6.3.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-prettier": "^3.1.0",
"husky": "^1.3.1",
"lint-staged": "^8.1.4",
"prettier": "^1.18.2",
"rimraf": "^2.6.3",
"stylelint": "^10.1.0",
"stylelint-config-standard": "^18.3.0",
"stylelint-order": "^3.1.0"
}
}
[当我尝试从目录根目录写入yarn run eslint时出现错误:
$纱run纱线运行v1.17.3
warning ../package.json:没有许可证字段$ eslint config'** / *。js'--ext .js
糟糕!出问题了! :(
ESLint:6.4.0。
无法在]读取JSON文件>
/ Users / vladyslavsymonenko / Chess / server / .eslintrc.json:
无法读取配置文件:> /Users/vladyslavsymonenko/Chess/server/.eslintrc.json错误:位置1040中的JSON中的意外令牌]
错误命令失败,退出代码为2。info请访问;此命令的文档。
我对结果真的很困惑,请帮助我)
我有node.js项目,并从eslint配置开始。有.eslintrc.json {“ parser”:“ babel-eslint”,“ extends”:[“ airbnb”,“ plugin:node / recommended”,“ plugin:security / ...
回答如下:您需要从.eslintrc中删除所有结尾的逗号(例如第7行的"prettier",
,因为它不是有效的JSON: