- Angular CLI 教程
- Angular CLI - 首页
- Angular CLI - 概述
- Angular CLI - 环境设置
- Angular CLI 命令
- Angular CLI - ng version
- Angular CLI - ng new
- Angular CLI - ng help
- Angular CLI - ng generate
- Angular CLI - ng build
- Angular CLI - ng run
- Angular CLI - ng serve
- Angular CLI - ng lint
- Angular CLI - ng test
- Angular CLI - ng e2e
- Angular CLI - ng add
- Angular CLI - ng analytics
- Angular CLI - ng config
- Angular CLI - ng doc
- Angular CLI - ng update
- Angular CLI - ng xi18n
- Angular CLI - 代码覆盖率
- Angular CLI 有用资源
- Angular CLI - 快速指南
- Angular CLI - 有用资源
- Angular CLI - 讨论
Angular CLI - ng lint 命令
本章解释了 ng lint 命令的语法、参数和选项,并提供了一个示例。
语法
ng lint 命令的语法如下:
ng lint <project> [options] ng l <project> [options]
ng lint 在 Angular 应用代码上运行 lint 工具。它检查指定 Angular 项目的代码质量。它默认使用 TSLint 作为 lint 工具,并使用 tslint.json 文件中提供的默认配置。
参数
ng lint 命令的参数如下:
| 序号 | 参数 & 语法 | 描述 |
|---|---|---|
| 1 | <project> | 要 lint 的项目的名称。 |
选项
选项是可选参数。
| 序号 | 选项 & 语法 | 描述 |
|---|---|---|
| 1 | --configuration=configuration |
要使用的 lint 配置。 别名: -c |
| 2 | --exclude | 要从 lint 中排除的文件。 |
| 3 | --files | 要包含在 lint 中的文件。 |
| 4 | --fix=true|false | 修复 lint 错误(可能会覆盖已 lint 的文件)。 默认值: false |
| 5 | --force=true|false |
即使存在 lint 错误也成功。 默认值: false |
| 6 | --format=format |
输出格式(prose、json、stylish、verbose、pmd、msbuild、checkstyle、vso、fileslist)。 默认值: prose |
| 7 | --help=true|false|json|JSON |
在控制台中显示此命令的帮助消息。 默认值: false |
| 8 | --silent=true|false | 显示输出文本。 默认值: false |
| 9 | --tsConfig=tsConfig | TypeScript 配置文件的名称。 |
| 10 | --tslintConfig=tslintConfig | TSLint 配置文件的名称。 |
| 11 | --typeCheck=true|false |
控制 lint 的类型检查。 默认值: false |
首先移动到使用 **ng build** 命令更新的 Angular 项目。该命令可在 https://tutorialspoint.com/angular_cli/angular_cli_ng_build.htm 找到。
按如下方式更新 goals.component.html 和 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 {
}
}
goals.component.html
<p>{{title}}</p>
现在运行 lint 命令。
示例
下面给出了 ng lint 命令的示例:
\>Node\>TutorialsPoint> ng lint Linting "TutorialsPoint"... ERROR: D:/Node/TutorialsPoint/src/app/goals/goals.component.ts:9:27 - Missing semicolon ERROR: D:/Node/TutorialsPoint/src/app/goals/goals.component.ts:13:2 - file should end with a newline Lint errors found in the listed files.
这里 ng lint 命令检查了应用程序的代码质量并打印了 lint 状态。
现在更正 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 {
}
}
现在运行 lint 命令。
示例
下面给出一个示例:
\>Node\>TutorialsPoint> ng lint Linting "TutorialsPoint"... All files pass linting.
广告