Is there a better way of using parserOptions.project? #8312
Replies: 5 comments 4 replies
-
Definitely interested in this. We are using multiple ESLint plugins. One of them is What would be the {
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
"@nrwl/nx/enforce-module-boundaries": [ ... ]
},
{
"files": ["*.ts", "*.tsx"],
"settings": {
"import/extensions": [".ts"],
"import/parsers": {
"@typescript-eslint/parser": [".ts"]
},
"import/resolver": {
"typescript": {
"alwaysTryTypes": true,
"project": "./tsconfig.*?.json"
}
}
},
"plugins": ["unused-imports"],
"extends": [
"plugin:@nrwl/nx/typescript",
// "plugin:@typescript-eslint/recommended-requiring-type-checking"
"plugin:unicorn/recommended",
"plugin:sonarjs/recommended",
"plugin:import/recommended",
"plugin:import/typescript"
],
"rules": {
...
}
},
{
"files": ["*.ts", "*.tsx"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2019,
"project": ["tsconfig.*?.json"],
"sourceType": "module"
},
"plugins": ["rxjs-angular"],
"extends": ["plugin:rxjs/recommended"],
"rules": {
...
}
},
// Is it OK to put this in the root eslintrc?
{
"files": ["*.ts"],
"extends": ["plugin:@nrwl/nx/angular"],
"rules": {
"@angular-eslint/component-class-suffix": [
"error",
{
"suffixes": ["Component", "Dialog", "Form", "Layout", "Container", "Page", "Root"]
}
]
}
}, |
Beta Was this translation helpful? Give feedback.
-
Also interested in this. |
Beta Was this translation helpful? Give feedback.
-
Hello ! I tried several things: // root eslintrc.json
{
"parserOptions": {
"project": "./tsconfig.*?.json"
},
} This one works, but has bad performances (7s / lib for me) // project eslintrc.json
{
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"parserOptions": {
"project": "./libs/my-lib/tsconfig.*?.json"
}
}
]
} This also works, but I have to update every eslintrc.json file... I don't really understand the difference between the two, the first one seems to be using my |
Beta Was this translation helpful? Give feedback.
-
Ok, so to everyone wondering about this, here is what I found and understood. Sadly, this is not explained in the docs (or I was not able to find anything about it).
The problem is that it is very annoying to set this option manually for every lib (and it is very easy to forget it). But I then realised that the library generators had an option called The solution we came up in our team was to create our own generators (https://nx.dev/recipes/generators/local-generators) and stop using the default ones. I think this is the way to go to enforce some consistency in the workspace. You create your own generators with just a few parameters and you call nx generators with the parameters you see fit. So we created our own library generator that always calls nx native generators passing the Here is a part of this generator : export default async function (
tree: Tree,
{
name,
framework,
// [...]
}
) {
// [...]
switch (framework) {
case LibraryFramework.NONE:
await genericLibraryGenerator(tree, { ...commonSettings, setParserOptionsProject: true });
break;
case LibraryFramework.ANGULAR:
await angularLibraryGenerator(tree, {
...commonSettings,
setParserOptionsProject: true,
// [...]
});
break;
case LibraryFramework.NEST:
await nestLibraryGenerator(tree, {
...commonSettings,
setParserOptionsProject: true
// [...]
});
break;
}
// [...]
await formatFiles(tree);
return () => {
installPackagesTask(tree);
};
} Hopefully, this will help someone ^^ |
Beta Was this translation helpful? Give feedback.
-
Based on solution from @darckoune (thanks a lot!), I am sharing similar solution but without creating custom generators. The outcome is the same. Maybe someone will find it useful. You can specify default parameters for generators in Open
You will have to provide this setup for all your generators collections like |
Beta Was this translation helpful? Give feedback.
-
As the specs state: Do not use parserOptions.project within your root .eslintrc.json, but I would like to use for all my projects and libs
It just doesn't feel good to include this within every project and lib and it's easy to forget when someone generates a new lib or project.
So my root .eslintrc.json looks like this:
Is this still a bad practise? Should I change this?
Beta Was this translation helpful? Give feedback.
All reactions