angular-eslint: Type-check rules cause errors when using `ng lint`
Steps to reproduce
-
Run the commands
ng new sample-application ng add @angular-eslint/schematics
-
Change
angular.json
’sprojects:sample-app:architect:lint
property to:"lint": { "builder": "@angular-eslint/builder:lint", "options": { "eslintConfig": ".eslintrc.js", "tsConfig": [ "tsconfig.app.json", "tsconfig.spec.json", "e2e/tsconfig.json" ], "exclude": ["**/node_modules/**"] } },
-
Create a
.eslintrc.js
file with:module.exports = { extends: [ // comment this next line out to see no errors occur "plugin:@typescript-eslint/recommended-requiring-type-checking", "plugin:@angular-eslint/recommended", ], plugins: ["@typescript-eslint", "@angular-eslint"], };
-
Run the command
ng lint
Output
An unhandled exception occurred: Error while loading rule '@typescript-eslint/await-thenable': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.
Occurred while linting
Other notes
I created a repository to reproduce this issue. It can be found here: https://github.com/delasteve/eslint-angular-issue-sample-repo
I’m also trying to figure out if this next error is an angular-eslint
issue or something else. If you swap the order of the extends array so that plugin:@angular-eslint/recommended
is first, you will receive the following error:
D:\development\sample-app\src\app\app.component.html
0:0 error Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: src\app\app.component.html.
The extension for the file (.html) is non-standard. You should add "parserOptions.extraFileExtensions" to your config
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 22 (5 by maintainers)
For the ones that are redirected by Google to this issue due to the error about the html file:
With the latest version at the time of writing (0.2.0-beta.1), this problem dissapears with the following data structure:
The
lintFilePatterns
property is key here, just pass a glob with only the .ts files.I have uploaded a repository with my favorite eslint configuration for Angular if you want to take a look: https://github.com/gagle/angular-starter
@JamesHenry, it comes with the territory when beta testing.
Thanks for all your hard work.
@guilhermetod – Thanks for that suggestion. I’d been experiencing the exact same problem in my project and your fix worked for me. I wound up tweaking it a bit, to be more explicit about which filetypes were extending which configs:
@gagle, @alechemy’s solution works for linting both TypeScript and HTML files. The only thing that will need to change with
0.2.0-beta.1
is theparsersOptions.project
property.OLD:
NEW:
@delasteve After spending many hours yesterday working on
typescript-eslint
configuration issues, I learned several things that I think will solve you issues:parserOptions.project
property does NOT inherit the basetsconfig.json
from theextends
option inside yourtsconfig.app.json
, then you need to specify yourtsconfig.json
in addition totsconfig.app.json
inside yourparserOptions.project
array. See here for more info - it explains this. Therefore, change this:to
Your second issue regarding the error
The file does not match your project config: src\app\app.component.html. The extension for the file (.html) is non-standard. You should add "parserOptions.extraFileExtensions" to your config
- that is due to atsconfig.json
configuration issue. You did not post it here, but I assume you did not include theinclude
option to specifically include only *.ts files. Here is an example of my workingtsconfig.json
fileAs you can see, you need to
include
the type of files typescript should be checking, otherwise I believe it defaults to all files in thebaseUrl
which would cause your issue regarding the error aboutapp.component.html
. TypeScript should not be reading files with.html
or.css
extensions, etc.Let me know if any of this works for you.