簡體   English   中英

使用自定義`tslint`規則,無需從打字稿進行編譯

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM