[英]Use custom `tslint` rule without compilation from typescript
I've made my own tslint rule , saved into tslint-rules/disallowGetterInsideOfTheLoopRule.ts
and added it into tslint config: 我已经制定了自己的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"
]
}
But it works only if I compile it to JavaScript and update import/export statements in compiled file: 但是只有当我将其编译为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) {
How can I use my rule in TypeScript without compilation? 没有编译,如何在TypeScript中使用规则?
To run linting I'm currently using npm run lint
with following script: 要运行linting,我目前正在使用
npm run lint
并使用以下脚本:
"lint": "tslint --config tslint.json --project tsconfig.json \"src/**/*.ts{,x}\"",
For now configured compilation without need to do manual updates: 对于现在配置的编译,无需手动更新:
"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}\"",
Of course tslint config changed to 当然,tslint配置更改为
"rulesDirectory": [
"./tslint-rules/bin"
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.