为什么 Eslint 在不同的机器上会报不同的结果?
Why does Eslint report different results on different machines?
在我们的项目中,我们使用的是 tslint,但最近迁移到了 eslint。 运行 我本地机器 (Windows) 上的命令 "eslint \"packages/**/*.{ts,tsx}\""
报告 1 个错误和 409 个警告,但是 运行 linux 机器上的相同命令报告 1 个错误和2746 个警告。
带有 --env-info 标志的 运行 linter 的结果在两台机器上是相同的
Node version: v12.16.1
npm version: v6.13.4
Local ESLint version: v7.22.0 (Currently used)
Global ESLint version: Not found
插件的版本似乎也匹配。
文件夹结构如下所示:
.eslintrc.js
tsconfig.json
package.json
.eslintignore
packages/ (contains subprojects which don't have their own eslint config files)
配置文件内容:
.eslintrc.js 文件
module.exports = {
"root": true,
"env": {
"browser": true,
"node": true,
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"sourceType": "module"
},
"plugins": [
"eslint-plugin-jsdoc",
"eslint-plugin-import",
"eslint-plugin-react",
"eslint-plugin-prefer-arrow",
"react-hooks",
"@typescript-eslint"
],
"settings": {
"react": {
"version": "17.0.0",
},
},
"rules": {...}
}
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"strictPropertyInitialization": false,
"jsx": "preserve"
},
"exclude": [
"node_modules",
"**/*.md",
"**/dist/**"
],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
]
}
我还检查了 Linux 机器报告的一些警告,但我的本地 Windows 机器没有。例如,以下各行均报告警告“任何类型值的不安全调用”
const {breakPoints} = useTheme();
const currentBreak = useCurrentBreakPoint(breakPoints);
但是类型似乎是正确的,打字稿也没有抱怨它们。
什么可能导致两台机器之间的 linting 结果不同?
问题是由缺少依赖项引起的。 运行 在 linting 修复问题之前,所有子项目中的“npm install”。
在我们的项目中,我们使用的是 tslint,但最近迁移到了 eslint。 运行 我本地机器 (Windows) 上的命令 "eslint \"packages/**/*.{ts,tsx}\""
报告 1 个错误和 409 个警告,但是 运行 linux 机器上的相同命令报告 1 个错误和2746 个警告。
带有 --env-info 标志的 运行 linter 的结果在两台机器上是相同的
Node version: v12.16.1
npm version: v6.13.4
Local ESLint version: v7.22.0 (Currently used)
Global ESLint version: Not found
插件的版本似乎也匹配。
文件夹结构如下所示:
.eslintrc.js
tsconfig.json
package.json
.eslintignore
packages/ (contains subprojects which don't have their own eslint config files)
配置文件内容:
.eslintrc.js 文件
module.exports = {
"root": true,
"env": {
"browser": true,
"node": true,
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"sourceType": "module"
},
"plugins": [
"eslint-plugin-jsdoc",
"eslint-plugin-import",
"eslint-plugin-react",
"eslint-plugin-prefer-arrow",
"react-hooks",
"@typescript-eslint"
],
"settings": {
"react": {
"version": "17.0.0",
},
},
"rules": {...}
}
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"strictPropertyInitialization": false,
"jsx": "preserve"
},
"exclude": [
"node_modules",
"**/*.md",
"**/dist/**"
],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
]
}
我还检查了 Linux 机器报告的一些警告,但我的本地 Windows 机器没有。例如,以下各行均报告警告“任何类型值的不安全调用”
const {breakPoints} = useTheme();
const currentBreak = useCurrentBreakPoint(breakPoints);
但是类型似乎是正确的,打字稿也没有抱怨它们。
什么可能导致两台机器之间的 linting 结果不同?
问题是由缺少依赖项引起的。 运行 在 linting 修复问题之前,所有子项目中的“npm install”。