The directory structure in the Angular project I'm working on is as follows (reduced to the relevant files):
project
|- libs
| |- utils
| |- common
| |- src
| | |- lib
| | |- model
| | | |- translation
| | | |- translation-helper.ts (3)
| | |- utils-common.module.ts
| |- .eslintrc.json (2)
| |- project.json
|- .eslintrc.json (1)
For further reference, I have numbered the files.
The .eslintrc.json
files make some statements about file inclusion/exclusion:
(1) starts like this:
{
"root": true,
"ignorePatterns": ["**/*"],
...
}
(2) starts like this:
{
"extends": ["../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
...
}
Note that I think no-one in the team has written that code; I think it's all part of the whole bunch of files that nx generates automatically for all modules. That notwithstanding, based on the docs for .eslintrc.json
, I think it makes sense and should work - globally, all files are excluded, which is overridden per module by negating (hence the !
pattern) the wildcard exclusion (and possibly then declaring more specific exclusions).
Now, I'm trying to run ESLint for file (3):
npx nx lint utils-common --files=**/model/translation/translation-helper.ts
Unfortunately, this results in the following output:
Linting "utils-common"...
> NX All files matching the following patterns are ignored:
- 'libs/utils/common/src/**/*.ts'
Please check your '.eslintignore' file.
Pass --verbose to see the stacktrace.
There are no .eslintignore
files in the directory hierarchy.
Also, I am very sure file (2) is picked up by ESLint, for if e.g. the path indicated in extends
of (2) is wrong (for example, having one directory level too much or too little), ESLint does output a corresponding error.
Lastly, ESLint will happily lint if I remove the **/*
ignore pattern from (1), but I feel that was not the intention of whichever person/tool/template put that ignore pattern there in the first place. Also, I want to understand why it doesn't work the way it is configured now.
What is going on here? Why does ESLint claim all of my files are excluded?
It looks like the ignorePatterns
do indeed work as I describe.
However, file (2) also contained the following in its overloads
section:
"files": ["*.ts"],
"extends": [
"plugin:@nrwl/nx/angular",
"../../../.eslintrc.json"
],
This caused file (1) to be included again, including the original ignorePatterns
with **/*
, thereby circumventing my adaptation of the ignorePatterns
above in file (2).
The solution I am choosing is to have an additional root .eslintrc.json
file (with a different name), which defines the base for individual rules to override. Then, from within the overrides
, I can extend from that file, whereas the global extends
attribute will point to the original root file.