Setting file extensions in ESLint configuration using overrides

Viewed 1285

I'm trying to specify the file extensions that ESLint should check by setting overrides in the configuration rather than needing to use the --ext command line flag. The documentation for that says:

By default, ESLint lints *.js files and the files that match the overrides entries of your configuration.

The documentation for overrides says that glob patterns for files can be along the lines of "src/*.js" or "**/*.js" and that these are relative to the base directory of your ESLint configuration file. Neither of these options are working for me to make ESLint process files beyond the default of *.js (in my case *.jsx).

Here's the output when I run ESLint with --ext:

scott@dev /home/scott/project (main)
$ npx eslint --ext .js,.jsx ./src

/home/scott/project/src/file.jsx
  1:1  warning  Unexpected console statement  no-console

āœ– 1 problem (0 errors, 1 warning)

As expected, it produces a warning. But without --ext, ESLint doesn't produce any output.

The directory structure:

/home/scott/project/
  .eslintrc.js
  src/
      file.jsx

.eslintrc.js:

const rules = {
    // ...
};

module.exports = {
    // ...
    overrides: [
        {
          files: [ "*.jsx" ], // also doesn't work with "src/**/*.jsx", "**/*.jsx"
          rules: rules
        }
    ],
    rules: rules
};

What do I have to do?

0 Answers
Related