I want to specify which files are to be linted in my eslintrc.js, so I've added files: ...
module.exports = {
extends: [
'react-app',
'react-app/jest',
'eslint:remended',
'plugin:@typescript-eslint/remended',
'prettier',
],
files: ['*.ts', '*.jsx', '*.ts', '*.tsx'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.json',
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 'latest',
sourceType: 'module',
},
rules: {
'testing-library/no-node-access': 'off',
},
};
But getting the following error when my premit runs:
premit: BABEL_ENV=development eslint src --ext .js,.jsx,.ts,.tsx --fix'*.ts', '*.tsx'
Error: ESLint configuration in .eslintrc.js is invalid:
- Unexpected top-level property "files".
I want to specify which files are to be linted in my eslintrc.js, so I've added files: ...
module.exports = {
extends: [
'react-app',
'react-app/jest',
'eslint:remended',
'plugin:@typescript-eslint/remended',
'prettier',
],
files: ['*.ts', '*.jsx', '*.ts', '*.tsx'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.json',
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 'latest',
sourceType: 'module',
},
rules: {
'testing-library/no-node-access': 'off',
},
};
But getting the following error when my premit runs:
premit: BABEL_ENV=development eslint src --ext .js,.jsx,.ts,.tsx --fix'*.ts', '*.tsx'
Error: ESLint configuration in .eslintrc.js is invalid:
- Unexpected top-level property "files".
Share
Improve this question
asked Jul 28, 2022 at 14:09
Kevin HamKevin Ham
711 gold badge1 silver badge4 bronze badges
2 Answers
Reset to default 6The top-level rules and config apply to all the matched files according to your mand line options (--ext
etc.)
You only use "files"
inside nested "overrides"
blocks when you want to specify which files the overrides apply to.
See https://eslint/docs/latest/user-guide/configuring/configuration-files#how-do-overrides-work
I have a new version of eslint.config.js
, and I too get the error.
I found an answer on the question: How can i fix "- Unexpected top-level property "files"."
To fix this issue, the “files” property needs to be included in the “overrides” property instead of the top-level property. Below is an example of how to correctly include the “files” property in the “overrides” property: