我在使用 Next.js 设置 eslint 时遇到问题。当我运行时,它实际上正确地检查了我的所有文件next build
,但是当我在开发模式下运行应用程序时(next
), eslint 实际上只是 lintspages/_app.js
,并完全忽略我的所有其他文件(例如pages/index.js
).
My next.config.js
看起来像这样:
module.exports = {
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
if (dev) {
config.module.rules.push({
test: /\.(j|t)sx?$/,
exclude: /node_modules/,
loader: 'eslint-loader',
})
}
return config
},
}
and .eslintrc.js
看起来像这样:
module.exports = {
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": [
"react"
],
"rules": {
"react/prop-types": 0,
"react/react-in-jsx-scope": 0
}
};
是否有一个示例项目演示使用 Next.js 设置 eslint? Eslint 几乎是任何现代 JS Web 应用程序的标准,因此我很惊讶地发现文档或任何演示项目中都没有提及 eslint。