- 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.
推薦閱讀
- PWA入門與實踐
- 程序員面試白皮書
- LabVIEW Graphical Programming Cookbook
- WSO2 Developer’s Guide
- 深入理解Java7:核心技術與最佳實踐
- Flash CS6中文版應用教程(第三版)
- Java程序設計:原理與范例
- iOS編程基礎:Swift、Xcode和Cocoa入門指南
- Elasticsearch for Hadoop
- Apache Kafka Quick Start Guide
- Web Development with MongoDB and Node(Third Edition)
- Android驅動開發權威指南
- Flowable流程引擎實戰
- Hands-On Kubernetes on Windows
- Clojure Web Development Essentials