John
John

Reputation: 213

How can I ignore all files without an extension in eslint

Currently in my .eslintignore I have the following:

**/*.json
**/*.svg
**/*.bat
**/*.sh
**/*.html
**/*.png
**/*.txt
**/*.ico
**/*.md

How can I prevent eslint from linting files that have no extension? For example, some of my docker files don't have an extension and I don't want to list them all out explicitly.

Upvotes: 0

Views: 7335

Answers (1)

evelynhathaway
evelynhathaway

Reputation: 1887

The best solution is to only tell ESLint to search for files matching JavaScript extensions you use (e.g. ts,tsx,js,jsx,cjs,mjs) instead of telling it to find everything, and then ignoring specific extensions.

To tell ESLint to add extensions, you can use the --ext command-line option, or use the overrides configuration as shown below:

.eslintrc.js

module.exports = {
  // [Your config here...]
  // Empty overrides block that lists your globs for the 
  overrides: [
    {
      files: ["**/*.{ts,tsx,js,jsx}"]
    }
  ]
};

Then make sure you are telling ESLint the path you want to lint by using eslint ./ or eslint ./src in your lint script, without using glob patterns for extensions, as running eslint ** for instance will load every file extension.

package.json

{
  "name": "example",
  "version": "1.0.0",
  "scripts": {
    "lint": "eslint ./"
  }
}

After you've made these changes, you should no longer need an ESLint ignore file just to disable common file extensions.

Upvotes: 4

Related Questions