我想添加@typescript-eslint/no-floating-promises
到我的 ESLint 规则中并且遇到了困难。
这需要parserOptions
.
这是我的 .eslintrc.js:
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2017,
project: './tsconfig.json'
},
plugins: [
'@typescript-eslint',
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'prettier'
],
rules: {
'@typescript-eslint/no-floating-promises': ['error'],
'@typescript-eslint/no-explicit-any': 'off'
}
};
和我的 tsconfig.json:
{
"compilerOptions": {
"target": "ES2017",
"lib": ["ES2017"],
"module": "commonjs",
"declaration": true,
"outDir": "lib",
"removeComments": true,
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"],
"exclude": ["src/**/*.spec.ts"]
}
问题是exclude
. 我不希望我的测试(规格)被编译到outDir
. 但这在我运行 ESLint 时会导致以下错误:
error 解析错误:“parserOptions.project”已为@typescript-eslint/parser 设置。该文件与您的项目配置不匹配:src/index.spec.ts。该文件必须包含在至少一个提供的项目中
(脚本是"lint": "eslint \"src/**/*.ts\""
)
我确实想整理我的测试。
在我添加之前一切都很好parserOptions
- 我需要它来制定no-floating-promises
规则。
typescript -eslint 常见问题解答说:
要解决此问题,只需确保 tsconfig 中的 include 选项包含您要 lint 的每个文件。
问题是我正在创建一个库,并且我不想发布测试文件。
如何只构建我想要发布到一个目录的文件,同时仍然对所有文件进行 linting?(我想让构建尽可能简单。)