如何解决创建 react app eslint 更漂亮的配置
但我在 vscode 上没有收到任何错误
这是我的 elint 配置
const path = require('path');
module.exports = {
env: {
browser: true,es2021: true,node: true,},extends: [
'airbnb','prettier','prettier/react','plugin:react/recommended','plugin:prettier/recommended','plugin:import/errors','plugin:import/warnings',],parserOptions: {
ecmaFeatures: {
jsx: true,ecmaVersion: 12,sourceType: 'module',plugins: ['react','import','prettier'],rules: {
'prettier/prettier': 'error','react/jsx-uses-react': 'off','react/react-in-jsx-scope': 'off','import/named': 'off','import/no-self-import': 'off','import/no-extraneous-dependencies': 'off','react/jsx-props-no-spreading': 'off','import/prefer-default-export': 'off','no-param-reassign': [
'error',{ props: true,ignorePropertyModificationsFor: ['draft'] },settings: {
'import/resolver': {
alias: {
map: [['@',path.join(path.resolve(__dirname,'./src'))]],extensions: ['.js','.jsx','.json'],node: {
extensions: ['.js','.jsx'],};
我的配置有什么问题?
如您所见,没有错误。
注意: eslint 和 prettier 扩展已启用并成功运行。在这些错误之前,我遇到了错误并且 vscode 显示错误,我确信 vscode eslint 可以工作。
怎么了?
解决方法
我认为这些错误是由 create-react-app 附带的 webpack configuration 引起的。
当您在项目中调用 npm start
时,webpack 进程在幕后启动,对您在自定义 eslint 配置文件中指定的别名一无所知。您的自定义 eslint-config-file 仅由您的编辑器使用(或更具体地说,由您启用的 eslint-extension 使用),我相信没有顺利的方法来更改它(无需创建您自己的 webpack 配置)。
另见https://create-react-app.dev/docs/setting-up-your-editor/#displaying-lint-output-in-the-editor,它描述了我上面写的内容。
请注意,即使您自定义了 ESLint 配置,这些更改也只会影响编辑器集成。它们不会影响终端和浏览器内的 lint 输出。这是因为 Create React App 有意提供了一组最小的规则来查找常见错误。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。