4

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:recommended',
    'plugin:@typescript-eslint/recommended',
    '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 precommit runs:

precommit: 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".
Kevin Ham
  • 51
  • 1
  • 3

1 Answers1

3

The top-level rules and config apply to all the matched files according to your command 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.org/docs/latest/user-guide/configuring/configuration-files#how-do-overrides-work

davecardwell
  • 3,380
  • 1
  • 17
  • 15
  • 1
    Interesting. The reason I was adding files, was in relation to the top answer in [this post](https://stackoverflow.com/questions/58510287/parseroptions-project-has-been-set-for-typescript-eslint-parser) which does solve my initial eslint parsing error. Wrapping it within overrides does not fix the above error. – Kevin Ham Jul 28 '22 at 16:47