0

Given a project structure as follows:

main
  ∟ dir1
      ∟ component-a.ts
      ∟ component-a.spec.ts
      ∟ component-b.ts
      ∟ component-b.spec.ts
  ∟ dir2
      ∟ component-c.ts
      ∟ component-c.spec.ts
  ∟ dir3
      ∟ subdir
          ∟ component-d.ts
          ∟ component-d.spec.ts

How can I exclude all spec files except the ones in main/dir3/?

By excluding the *.spec.ts pattern, I am unable to re-include the inner directory then unless I create an .eslintrc.json file inside it, but I would like not to have to duplicate the whole ruleset.

I've also tried changing the exclusion pattern to something like **/!(dir3)/**/*.spec.ts, but that doesn't seem to work.

My current config is as follows:

{
  "root": true,
  "ignorePatterns": [...],
  ...
  "overrides": [
    {
      "files": ["*.ts"],
      "excludedFiles": [
        "*.spec.ts"
      ],
      "rules": {...}
    }
  ]
}
LostMyGlasses
  • 3,074
  • 20
  • 28
  • Hello, I guess you can use an .eslintignore file and use the method described here: https://stackoverflow.com/questions/5533050/gitignore-exclude-folder-but-include-specific-subfolder. Does that help? – g_bor Apr 13 '21 at 10:36
  • It does, thanks! If you want to write an answer, I'll accept it. – LostMyGlasses Apr 13 '21 at 10:45

1 Answers1

0

You can use a

.eslintignore

file with a content like this:

main/*
!main/dir3

There is a more detailed description about this method here: .gitignore exclude folder but include specific subfolder

g_bor
  • 1,077
  • 6
  • 14