ESLint配置无效报错:.eslintrc.js存在意外顶级属性linebreak-style
ESLint配置错误修复方案
错误原因
报错提示的Unexpected top-level property "linebreak-style"是因为linebreak-style是ESLint的规则项,必须嵌套在配置对象的rules属性内,你当前将其放在了顶级层级,导致配置结构无效。
修复后的.eslintrc.js配置
将linebreak-style移至rules对象中,同时清理配置末尾多余的type here字符,另外移除重复的react/no-unescaped-entities规则:
module.exports = { extends: [ "airbnb-base", "plugin:eslint-plugin/recommended", "eslint:recommended", "plugin:react/recommended", ], plugins: ["react"], rules: { "no-restricted-syntax": 0, "react/no-unescaped-entities": "off", "react/require-default-props": 0, "padded-blocks": ["error", "never"], "comma-dangle": "off", "linebreak-style": ["error", "windows"] }, };
额外注意事项
你的package.json中存在eslintConfig字段,同时又使用独立的.eslintrc.js配置文件。在Create React App项目中,独立配置文件会覆盖package.json里的ESLint配置,但如果后续出现规则不生效的情况,可以删除package.json中的eslintConfig节点,确保统一使用.eslintrc.js的配置。
内容的提问来源于stack exchange,提问作者Carmen Adrien
相关产品推荐
相关产品推荐

