我需要编写一个Angular Typescript规则来警告人们,如果他们使用某些'关键字/短语'。例如,如果关键字“ Birthdate”或“ SSN”直接位于源文件中,则应给出警告。
有人将如何使用TS Lint编写此规则?
当前正在尝试研究,在Stackoverflow文章搜索档案中没有看到任何文章,
好奇如何操作下面的示例代码或(对任何其他解决方案开放),>
以下限制使用debugger
语句
https://github.com/eranshabi/tslint-custom-rules-boilerplate/blob/master/src/myCustomRule.ts
import * as Lint from 'tslint'; import * as ts from 'typescript'; export class Rule extends Lint.Rules.AbstractRule { static FAILURE_STRING = 'Use of debugger statements is forbidden.'; public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { return this.applyWithWalker(new Walk(sourceFile, this.getOptions())); } } class Walk extends Lint.RuleWalker { protected visitDebuggerStatement(node: ts.DebuggerStatement) { this.addFailureAt(node.getStart(), node.getEnd() - node.getStart(), Rule.FAILURE_STRING, this.fix(node)); super.visitDebuggerStatement(node); } private fix(node: ts.DebuggerStatement): Lint.Fix { return new Lint.Replacement(node.pos, node.end, '') } }
其他资源:
https://rangle.io/blog/custom-tslint-for-angular/
https://medium.com/@andrey.igorevich.borisov/writing-custom-tslint-rules-from-scratch-62e7f0237124
我需要编写一个Angular Typescript规则来警告人们,如果他们使用某些'关键字/短语'。例如,如果关键字“ Birthdate”或“ SSN”直接位于源文件中,则应给出...
我通过管道检查来做到这一点,但是您可以通过以下所示的预先提交:Is it possible to ban a list of words with ESlint or anything else when pre-commit?