eslint配置注意事项

1). 4:1 error Parsing error: The keyword 'import' is reserved
确保.eslintrc文件存在,并且内容为

{
  "extends": "airbnb",
  "plugins": ["react"]
}

2). Value "data["0"].VariableDeclarator" has additional properties.

如下所示错误代码,是因为最新的eslint需要重新配置,按照下面路径方法配置即可:eslint-config-airbnb-base安装配置

ERROR in ./src/index.js
Module build failed: Error: /home/suwu150/WebStormProject/electron-desktop-tools/node_modules/eslint-config-airbnb-base/rules/es6.js:
        Configuration for rule "prefer-destructuring" is invalid:
        Value "data["0"].VariableDeclarator" has additional properties.
        Value "data["0"].AssignmentExpression" has additional properties.

Referenced from: /home/suwu150/WebStormProject/electron-desktop-tools/node_modules/eslint-config-airbnb-base/index.js
Referenced from: airbnb
Referenced from: /home/suwu150/WebStormProject/electron-desktop-tools/.eslintrc
    at validateRuleOptions (/home/suwu150/WebStormProject/electron-desktop-tools/node_modules/eslint/lib/config/config-validator.js:109:15)

3). - Unexpected top-level property "comma-dangle".

ERROR in ./src/index.js
Module build failed: Error: ESLint configuration in /home/suwu150/WebStormProject/electron-desktop-tools/.eslintrc is invalid:
        - Unexpected top-level property "comma-dangle".

    at validateConfigSchema (/home/suwu150/WebStormProject/electron-desktop-tools/node_modules/eslint/lib/config/config-validator.js:214:15)
    at Object.validate (/home/suwu150/WebStormProject/electron-desktop-tools/node_modules/eslint/lib/config/config-validator.js:231:5)

Unexpected top-level property,我的原因是没有将规则写对地方,
错误的写法如下所示:

{
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true,
      "experimentalObjectRestSpread": true
    }
  },
  "rules": {
    "semi": 2
  },
  "comma-dangle": [1,"always-multiline"],
  "plugins": ["react"],
  "extends": "airbnb"
}

正确的写法如下所示:

{
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true,
      "experimentalObjectRestSpread": true
    }
  },
  "rules": {
    "semi": 2,
    "comma-dangle": ["off"]
  },
  "plugins": ["react"],
  "extends": "airbnb"
}

4). Parsing error: Unexpected token : 或者 Parsing error: Unexpected token =

 34:52  error  Parsing error: Unexpected token :

✖ 1 problem (1 error, 0 warnings)

 @ ./src/store/configureStore.js 6:19-58
 @ ./src/index.js
 @ multi webpack-hot-middleware/client?path=http://localhost:3000/__webpack_hmr babel-polyfill ./src/index.js

Use the babel-eslint parser in your ESLint configuration.
也就是在.eslintrc中添加"parser": "babel-eslint", 即可
安装依赖包:npm install babel-eslint –save

{
  "parser": "babel-eslint",
  "plugins": ["react"],
  ...
}

5).error: Expected linebreaks to be ‘LF’ but found ‘CRLF’
我们从github上拉别人项目的时候。有时候会遇到这个报错:
error: Expected linebreaks to be ‘LF’ but found ‘CRLF’
这就是eslint的报错了,可能是原作者用的是linux系统。
只需在eslintrc文件里面将
linebreak-style: [“error”, “unix”]
改成
linebreak-style: [“error”, “windows”](我用的是windows)即可

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

suwu150

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值