Bootstrap

React进阶(十一):create-react-app脚手架关闭 eslint 提醒

一、前言

在项目开发过程中,有时候苦恼于的校验规则,例如变量、方法定义时空格等的校验。

主要有两种方式可实现关闭提醒。

二、第一种方式

在依赖包下的目录找到配置文件,在中注释掉以下代码:

{
          test: /\.(js|mjs|jsx|ts|tsx)$/,
          enforce: 'pre',
          use: [
            {
              options: {
                cache: true,
                formatter: require.resolve('react-dev-utils/eslintFormatter'),
                eslintPath: require.resolve('eslint'),
                resolvePluginsRelativeTo: __dirname,
                // @remove-on-eject-begin
                ignore: isExtendingEslintConfig,
                baseConfig: isExtendingEslintConfig
                  ? undefined
                  : {
                      extends: [require.resolve('eslint-config-react-app')],
                    },
                useEslintrc: isExtendingEslintConfig,
                // @remove-on-eject-end
              },
              loader: require.resolve('eslint-loader'),
            },
          ],
          include: paths.appSrc,
        },

三、第二种方式

在 中修改为以下:

eslintConfig": {
    "extends": "react-app",
    "rules": {
      "no-undef": "off",
      "no-restricted-globals": "off",
      "no-unused-vars": "off"
    }
  }

然后重启。

四、拓展阅读