Vladislav Zaynchkovsky
Vladislav Zaynchkovsky

Reputation: 3339

ESlint override rule by nested directory

I want to disable rule for all files inside nested directory. I found examples only for exact path or by file extension. But it is not what I want.

We use it for shared config and don't know where this directory will be. We have many of them.

I'm trying config like this:

{
  overrides: [
    {
      files: [
        '**/test/**/*',
      ],
      rules: {
        "import/no-extraneous-dependencies": "off"
      }
    },
  ],
}

But glob like **/test/**/* and many others didn't not work.

Can someone help to reach this goal?

Upvotes: 2

Views: 2053

Answers (1)

fengelhardt
fengelhardt

Reputation: 1653

The above code should work.

How were you testing this? If it's an extension like VSCode you may need to refresh things to see latest definitions loaded.

If you are using a eslint service like esprint you will also need to restart it to grab latest definitions.

Caching Make sure that eslint is not configured to cache results to avoid having to cache bust when debugging things. eslint docs

Here's an example for a react-native app with multiple overrides

module.exports = {
  ...baseConfig,
  overrides: [
    typescriptOverrides,
    e2eOverrides,
    themeOverrides,
    {
      files: ['**/*.style.js'],
      rules: {
        'sort-keys': [
          'error',
          'asc',
          {
            caseSensitive: true,
            natural: true,
          },
        ],
      },
    },
    {
      files: ['**/*.test.js'],
      rules: {
        'arrow-body-style': 'off',
      },
    },
  ],
};

Debugging the glob matcher

  1. Run eslint in debug mode and see all the files being run example DEBUG=eslint:cli-engine npx eslint src/**/*.test.js
  2. You can test your glob patterns by running a ls command. Example: ls ./src/**/*.test.js will either return all the files or 'no matches found'.

Upvotes: 0

Related Questions