У меня есть следующая структура репозитория:
cypress
папка
.eslintrc.js
tsconfig.json
basic.spec.ts
src
папка
.eslintrc.js
tsconfig.base.json
tsconfig.json
Я намерен установить корень tsconfig.json
только для папки src
, и то же самое касается .eslintrc.js
. Затем я пытаюсь настроить tsconfig.json
и .eslintrc.js
для папки cypress
. Но я получаю следующую ошибку при запуске ESLint:
Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: cypress\basic.spec.ts.
The file must be included in at least one of the projects provided.eslint
вот некоторые фрагменты файлов конфигурации:
tsconfig.base.json
:
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": false,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"removeComments": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"alwaysStrict": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"baseUrl": "./",
"paths": {
"@/containers/*": ["src/components/containers/*"],
"@/layout/*": ["src/components/layout/*"],
"@/ui/*": ["src/components/ui/*"],
"@/utils/*": ["src/utils/*"],
"@/images/*": ["public/images/*"],
"@/models/*": ["src/models/*"],
"@/data/*": ["src/data/*"],
"@/hooks/*": ["src/hooks/*"]
},
"typeRoots": ["./node_modules/@types", "./@types"]
}
}
tsconfig.json
файл:
{
"extends": "./tsconfig.base.json",
"include": ["next-env.d.ts", "src/**/*.ts", "src/**/*.tsx", "tests/**/*.ts"],
"exclude": ["node_modules"]
}
.eslintrc.js
файл:
module.exports = {
root: true,
env: {
browser: true,
es2021: true,
},
extends: [
'eslint:recommended',
'next/core-web-vitals',
'plugin:@typescript-eslint/recommended',
'plugin:import/typescript',
'prettier',
],
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 12,
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint', 'unused-imports', 'react-hooks', 'node'],
};
cypress/tsconfig.json
файл:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"isolatedModules": false,
"types": ["cypress"]
},
"include": ["../node_modules/cypress", "./**/*.ts"],
"exclude": []
}
cypress/.eslintrc.js
файл:
module.exports = {
root: true,
env: {
es2021: true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:import/typescript',
'prettier',
],
parserOptions: {
ecmaVersion: 12,
project: './tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint', 'unused-imports', 'node'],
};
Поэтому я не понимаю, почему я получил ошибку, потому что basic.spec.ts
включен в файл cypress/tsconfig.json
.
@Baboo из корневой папки
@Baboo Я запускаю это: npx eslint -c cypress/.eslintrc.js cypress
Итак, проблема в том, что ESLint по умолчанию определяет текущий рабочий каталог как корневую папку. Таким образом, это привело к тому, что ESLint обнаружил корневой файл tsconfig.json.
Проблема решена, выполнив в файле cypress/.eslintrc.js
:
parserOptions: {
ecmaVersion: 12,
project: './tsconfig.json',
tsconfigRootDir: 'cypress',
sourceType: 'module',
},
(также можно решить, установив значение проекта на cypress/tsconfig.json
)
Для дополнительной справки: https://github.com/typescript-eslint/typescript-eslint/issues/4732
Из какой папки вы запускаете eslint, чтобы получить эту ошибку?