I'm struggling to incorporate
@typescript-eslint/no-floating-promises
into my ESLint guidelines.
This necessitates the use of parserOptions
.
Below is my .eslintrc.js configuration:
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'
}
};
and this is my tsconfig.json content:
{
"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"]
}
The issue arises with the exclude
setting. I want to prevent my tests from being compiled to the output directory, but this leads to an error when running ESLint:
error Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser. The file does not match your project config: src/index.spec.ts. The file must be included in at least one of the projects provided
The script I use is "lint": "eslint \"src/**/*.ts\""
.
I absolutely want to perform linting on my tests.
Everything was functioning properly until the introduction of parserOptions
- which is essential for the no-floating-promises
rule.
The typescript-eslint FAQ recommends:
To resolve this issue, ensure that the include option in your tsconfig encompasses all the files you want to lint.
The dilemma lies in the fact that I am constructing a library and prefer not to expose the test files during publication.
Is there a way to compile only the files intended for publishing to a single directory while still being able to lint every file? (Keeping the build process as simple as possible is preferred.)