karlhorky / eslint-tricks

A collection of useful ESLint tricks
42 stars 0 forks source link

Prefer configuration over CLI flags #3

Open remcohaszing opened 4 months ago

remcohaszing commented 4 months ago

Quite often I see commands that use --ext or glob patterns, for example:

eslint --ext ts,tsx .
eslint 'src/**/*.ts'

It’s better to use configuration instead. Configuration gets picked up by other integrations too.

export default [
  {
    // Ignore the dist folder
    // 'ignorePatterns' for legacy config
    ignores: ['**/dist/**'],

    // Registers support for the `.ts` and `.tsx` extensions
    files: ['**/*.ts', '**/*.tsx']
  }
]

Now you can just run:

# ESLint 8
eslint .

# ESLint 9
eslint
karlhorky commented 4 months ago

Interesting, this sounds like a nice small tip for people.

I'm trying to find out a way to make it fit into my "-tricks" format - these are usually A) obscure or hard to find information and B) potentially high value, because other ways do not exist

Eg here are some other repos:

But maybe I'm missing an opportunity here and this could indeed exist here somewhere in eslint-tricks ... 🤔