ng lint <project> [options] ng l <project> [options]
ng lint run the linting tool on angular app code. It checks the code quality of angular project specified. It uses TSLint as default linting tool and uses the default configuration available in tslint.json file. Options are optional parameters.
Sr.No. | Argument & Syntax | Description |
---|---|---|
1 | <project> | The name of the project to lint. |
Sr.No. | Option & Syntax | Description |
---|---|---|
1 | --configuration=configuration |
The linting configuration to use. Aliases: -c |
2 | --exclude | Files to exclude from linting. |
3 | --files | Files to include in linting. |
4 | --fix=true|false | Fixes linting errors (may overwrite linted files). Default: false |
5 | --force=true|false |
Succeeds even if there was linting errors. Default: false |
6 | --format=format |
Output format (prose, json, stylish, verbose, pmd, msbuild, checkstyle, vso, fileslist). Default: prose |
7 | --help=true|false|json|JSON |
Shows a help message for this command in the console. Default: false |
8 | --silent=true|false | Show output text. Default: false |
9 | --tsConfig=tsConfig | The name of the TypeScript configuration file. |
10 | --tslintConfig=tslintConfig | The name of the TSLint configuration file. |
11 | --typeCheck=true|false |
Controls the type check for linting. Default: false |
First move to an angular project updated using ng build command.
Update goals.component.html and goals.component.ts as following.
goals.component.ts
import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-goals', templateUrl: './goals.component.html', styleUrls: ['./goals.component.css'] }) export class GoalsComponent implements OnInit { title = 'Goal Component' constructor() { } ngOnInit(): void { } }
goals.component.html
<p>{{title}}</p>
Now run the linting command.
\>Node\>Howcodex> ng lint Linting "Howcodex"... ERROR: D:/Node/Howcodex/src/app/goals/goals.component.ts:9:27 - Missing semicolon ERROR: D:/Node/Howcodex/src/app/goals/goals.component.ts:13:2 - file should end with a newline Lint errors found in the listed files.
Here ng lint command has checked the code quality of application and prints linting status.
Now correct the errors in goals.component.ts.
goals.component.ts
import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-goals', templateUrl: './goals.component.html', styleUrls: ['./goals.component.css'] }) export class GoalsComponent implements OnInit { title = 'Goal Component'; constructor() { } ngOnInit(): void { } }
Now run the linting command.
\>Node\>Howcodex> ng lint Linting "Howcodex"... All files pass linting.