I've made my own tslint rule , saved into tslint-rules/disallowGetterInsideOfTheLoopRule.ts
and added it into tslint config:
{
"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:
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?
To run linting I'm currently using npm run lint
with following script:
"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
"rulesDirectory": [
"./tslint-rules/bin"
]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.