最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Error: ESLint configuration in .eslintrc.js is invalid: - Unexpected top-level property "files" -

programmeradmin0浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 6

The 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:

发布评论

评论列表(0)

  1. 暂无评论