前言
在項目開發過程中,有時候苦惱於eslint的校驗規則,例如變量定義爲使用、空格等的校驗。
主要有兩種方式可實現關閉eslint提醒。
第一種方式
在react-scripts依賴包下的config目錄找到webpack.config.js
配置文件,在webpack.config.js
中註釋掉以下代碼:
{
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,
},
第二種方式
在 package.json
中修改爲以下:
eslintConfig": {
"extends": "react-app",
"rules": {
"no-undef": "off",
"no-restricted-globals": "off",
"no-unused-vars": "off"
}
}
然後重啓npm start。