- 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.
推薦閱讀
- Vue 3移動Web開發與性能調優實戰
- C++程序設計教程
- Designing Machine Learning Systems with Python
- JavaScript+jQuery網頁特效設計任務驅動教程(第2版)
- WSO2 Developer’s Guide
- 看透JavaScript:原理、方法與實踐
- HTML5入門經典
- Scientific Computing with Scala
- Mastering Android Development with Kotlin
- Node.js全程實例
- NoSQL數據庫原理
- UNIX Linux程序設計教程
- 區塊鏈技術進階與實戰(第2版)
- Mastering C++ Multithreading
- 運維前線:一線運維專家的運維方法、技巧與實踐