我已经made my own tslint rule,保存到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并更新已编译文件中的导入/导出语句时,它才有效:
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}\"",
答案 0 :(得分:0)
对于现在配置的编译,无需进行手动更新:
"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"
]