In this Angular CLI ng lint Command chapter explains the syntax, argument and options of ng lint command along with an example. So all the details of Angular CLI ng lint Command explain below-
Syntax
The syntax for ng lint command is as follows −
ng lint <project> [options] ng l <project> [options]
ng lint run the linting tool on angular app code. It checks the code quality of the angular project specified. It uses TSLint as the default linting tool and uses the default configuration available in the tslint.json file.
Arguments
The argument for ng lint command is as follows −
Sr.No. | Argument & Syntax | Description |
---|---|---|
1 | <project> | The name of the project to lint. |
Options
Options are optional parameters.
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 were 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. which is available at https://adglob.in/blog/angular-cli-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.
Example
An example for ng lint command is given below −
\>Node\>Adglob> ng lint Linting "Adglob"... ERROR: D:/Node/Adglob/src/app/goals/goals.component.ts:9:27 - Missing semicolon ERROR: D:/Node/Adglob/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 the 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.
Example
An example is stated below −
\>Node\>Adglob> ng lint Linting "Adglob"... All files pass linting.
Next Topic : Click Here