我想将@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时,这会导致以下错误:
错误解析错误:"parserOptions.project“已设置为@parserOptions.project/解析器。该文件与项目配置不匹配: src/index.spec.ts。该文件必须至少包含在所提供的一个项目中。
(脚本为"lint": "eslint \"src/**/*.ts\"" )
我do想给我的测试涂上棉线。
在我添加parserOptions之前,一切都很好--我需要这一点来执行no-floating-promises规则。
要解决这个问题,只需确保tsconfig中的include选项包含每个要链接的文件。
问题是我正在创建一个库,我不想发布测试文件。
如何在仍在林立所有文件的同时,只构建要发布到一个目录的文件?(我希望使构建尽可能简单。)
发布于 2020-03-16 05:37:00
我在我的项目中使用了两个tsconfig.json。
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/**/*"]
}tsconfig.build.json
{
"extends": "./tsconfig.json",
"exclude": ["src/**/*.spec.ts"]
}要构建该项目,请运行tsc -p tsconfig.build.json。
https://stackoverflow.com/questions/60698487
复制相似问题