Angular CLI – ng lint Command

Angular CLI - ng lint Command

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 & SyntaxDescription
1<project>The name of the project to lint.

Options

Options are optional parameters.

Sr.No.Option & SyntaxDescription
1–configuration=configurationThe linting configuration to use.Aliases: -c
2–excludeFiles to exclude from linting.
3–filesFiles to include in linting.
4–fix=true|falseFixes linting errors (may overwrite linted files).Default: false
5–force=true|falseSucceeds even if there were linting errors. Default: false
6–format=formatOutput format (prose, json, stylish, verbose, pmd, msbuild, checkstyle, vso, fileslist).Default: prose
7–help=true|false|json|JSONShows a help message for this command in the console.Default: false
8–silent=true|falseShow output text.Default: false
9–tsConfig=tsConfigThe name of the TypeScript configuration file.
10–tslintConfig=tslintConfigThe name of the TSLint configuration file.
11–typeCheck=true|falseControls 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

Leave a Reply