My project structure
My tsconfig.json
{
"compilerOptions": {
"target": "ES2022",
"module": "commonjs",
"outDir": "./dist",
"rootDir": "./",
"strict": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": "./src",
"declaration": true,
"allowJs": true
},
"include": [
"src/**/*.ts",
],
"exclude": [
"eslint.config.mjs",
"dist/**"
]
}
My eslint.config.mjs:
// @ts-check
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import tsParser from '@typescript-eslint/parser'
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = dirname(fileURLToPath(import.meta.url));
export default tseslint.config(
{
files: [
"src/**/*.ts"
],
ignores: [
'dist/**/*.ts',
'dist/**',
"**/*.mjs",
"eslint.config.mjs",
"**/*.js"
],
rules: {
"@typescript-eslint/no-unnecessary-condition": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
},
},
...tseslint.configs.strictTypeChecked,
...tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
project: "./tsconfig.json",
projectService: true,
tsconfigRootDir: __dirname,
projectFolderIgnoreList: [
"**dist**",
],
},
},
},
);
I want tsc to put compiled outputs fo dist folder (I'm new to TypeScript so I don't know if this is the right way to a TS project).
I've ignored files under dist folder but I still got these errors:
/Users/kainzhong/VSCode/eslintTmp/dist/src/index.d.ts
0:0 error Parsing error: /Users/kainzhong/VSCode/eslintTmp/dist/src/index.d.ts was not found by the project service. Consider either including it in the tsconfig.json or including it in allowDefaultProject
/Users/kainzhong/VSCode/eslintTmp/dist/src/index.js
0:0 error Parsing error: /Users/kainzhong/VSCode/eslintTmp/dist/src/index.js was not found by the project service. Consider either including it in the tsconfig.json or including it in allowDefaultProject
/Users/kainzhong/VSCode/eslintTmp/dist/src/lib/lib.d.ts
0:0 error Parsing error: /Users/kainzhong/VSCode/eslintTmp/dist/src/lib/lib.d.ts was not found by the project service. Consider either including it in the tsconfig.json or including it in allowDefaultProject
/Users/kainzhong/VSCode/eslintTmp/dist/src/lib/lib.js
0:0 error Parsing error: /Users/kainzhong/VSCode/eslintTmp/dist/src/lib/lib.js was not found by the project service. Consider either including it in the tsconfig.json or including it in allowDefaultProject
/Users/kainzhong/VSCode/eslintTmp/eslint.config.mjs
0:0 error Parsing error: /Users/kainzhong/VSCode/eslintTmp/eslint.config.mjs was not found by the project service. Consider either including it in the tsconfig.json or including it in allowDefaultProject
Haven't I already ignored these files? Why does eslint still complain about them?
This config doesn't actually ignore those files - that's the issue. ignores
has two ways of behaving:
files
, it stops that specific config block from affecting those ignored filesfiles
, it tells ESLint to ignore those filesMove the ignores
to their own block at the start:
export default tseslint.config(
{
ignores: [
'dist/**/*.ts',
'dist/**',
"**/*.mjs",
"eslint.config.mjs",
"**/*.js"
],
},
{
files: [
"src/**/*.ts"
],
// ...
From https://eslint.org/docs/latest/use/configure/configuration-files#excluding-files-with-ignores.