[英]Use custom `tslint` rule without compilation from typescript
我已經制定了自己的tslint規則 ,將其保存到tslint-rules/disallowGetterInsideOfTheLoopRule.ts
,並將其添加到tslint配置中:
{
"defaultSeverity": "error",
"extends": [
"tslint:latest",
"tslint-react"
],
"jsRules": {},
"rules": {
"disallow-getter-inside-of-the-loop": [true, "functionWithSomeVeryUniqueName"]
},
"rulesDirectory": [
"./tslint-rules"
]
}
但是只有當我將其編譯為JavaScript並更新已編譯文件中的import / export語句時,它才有效:
var Lint = require("tslint");
var ts = require("typescript");
const arrayMethods = new Set(["find", "findIndex", "sort", "forEach", "filter", "flatMap", "map", "every", "some", "reduce", "reduceRight"]);
module.exports.Rule = class Rule extends Lint.Rules.AbstractRule {
apply(sourceFile) {
沒有編譯,如何在TypeScript中使用規則?
要運行linting,我目前正在使用npm run lint
並使用以下腳本:
"lint": "tslint --config tslint.json --project tsconfig.json \"src/**/*.ts{,x}\"",
對於現在配置的編譯,無需手動更新:
"compile-lint-rules": "for %f in (./tslint-rules/*.ts) do tsc \"./tslint-rules/%f\" --lib es2018 --skipLibCheck --outDir ./tslint-rules/bin",
"lint": "npm run compile-lint-rules && tslint --config tslint.json --project tsconfig.json \"src/**/*.ts{,x}\"",
當然,tslint配置更改為
"rulesDirectory": [
"./tslint-rules/bin"
]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.