- Learn React with TypeScript 3
- Carl Rippon
- 173字
- 2021-06-10 19:16:40
Built-in rules
tslint has a handy collection of built-in rulesets that can be used. We can use these by specifying the ruleset name in the extends field. We can use multiple rulesets by putting all their names in the array:
- Let's adopt the opinionated set of rules that tslint ships with, called "tslint:recommended". So, in our tslint.json file, let's remove the rules field and add an extends field, as follows:
{
"extends": ["tslint:recommended"]
}
We immediately get lint errors when tslint.json is saved. The error is complaining about the lack of an I prefix on our Product interface. The logic behind the rule is that, while reading code, if a type starts with an I, we immediately know that it is an interface.
- Let's pretend that this rule isn't valuable to us. We can override this rule from "tslint:recommended" in the "rules" field. The rule is called "interface-name". So, let's override this to false:
{
"extends": ["tslint:recommended"],
"rules": {
"interface-name": false
}
}
When tslint.json is saved, the linting errors immediately go away.
推薦閱讀
- Apache ZooKeeper Essentials
- Beginning C++ Game Programming
- Mastering Unity Shaders and Effects
- Java軟件開發基礎
- Apache Mesos Essentials
- 深入剖析Java虛擬機:源碼剖析與實例詳解(基礎卷)
- OpenStack Networking Essentials
- Learning VMware vSphere
- Java EE 7 with GlassFish 4 Application Server
- 深度實踐KVM:核心技術、管理運維、性能優化與項目實施
- 視窗軟件設計和開發自動化:可視化D++語言
- Tableau Dashboard Cookbook
- 前端架構設計
- Managing Windows Servers with Chef
- 微服務設計