我已经安装了eslint-config-airbnb,它应该预先配置ESLINT以便进行反应:
默认导出包含所有ESLint规则,包括ECMAScript 6+和React。它需要eslint,,,和eslint-plugin-jx-a11y。
我的.eslintrc扩展其配置:
{ "extends": "eslint-config-airbnb",
"env": {
"browser": true,
"node": true,
"mocha": true
},
"rules": {
"new-cap": [2, { "capIsNewExceptions": ["List", "Map", "Set"] }],
"react/no-multi-comp": 0,
"import/default": 0,
"import/no-duplicates": 0,
"import/named": 0,
"import/namespace": 0,
"import/no-unresolved": 0,
"import/no-named-as-default": 2,
"comma-dangle": 0, // not sure why airbnb turned this on. gross!
"indent": [2, 2, {"SwitchCase": 1}],
"no-console": 0,
"no-alert": 0,
"linebreak-style": 0
},
"plugins": [
"react", "import"
],
"settings": {
"import/parser": "babel-eslint",
"import/resolve": {
"moduleDirectory": ["node_modules", "src"]
}
},
"globals": {
"__DEVELOPMENT__": true,
"__CLIENT__": true,
"__SERVER__": true,
"__DISABLE_SSR__": true,
"__DEVTOOLS__": true,
"socket": true,
"webpackIsomorphicTools": true
}
}不幸的是,当我在.js文件中添加React代码时,会出现以下错误:
error JSX not allowed in files with extension '.js' react/jsx-filename-extension正如所述,eslint airbnb配置不就是支持JSX吗?
应该做些什么来消除这一错误?
发布于 2017-03-26 16:14:24
或者按照前面提到的将文件扩展名更改为.jsx,或者禁用jsx-文件名-扩展名规则。您可以将以下内容添加到您的配置中,以允许.js扩展。
"rules": {
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
}发布于 2018-03-27 06:32:54
这是我的工作。希望能帮助你。
.eslintrc中的jsx-文件名-扩展名:
“规则”:{“react/jsx-filename-扩展名”:}webpack.config.js中:
解析:{扩展名:‘..js’,'.jsx‘},发布于 2019-06-21 16:13:52
如果我不适合你就叫我假的
"rules": {
"react/jsx-filename-extension": [0],
"import/extensions": "off"
}https://stackoverflow.com/questions/43031126
复制相似问题