如何将一条线标记为始终失败?

How can I mark a line to always fail?

有没有办法添加一个 tslint 指令来将下一行标记为错误?这在使用不应提交的代码进行测试时非常有用,例如调试代码或注释掉的功能行。

// thisImportantFunction();
// tslint:error-next-line
myTestCodeFunction();

只需将有问题的行设置为:

debugger;

它应该被 linter 捕获并且不会影响代码,除非你是 运行 开发者工具。

更新

或者您可以在 if:

中创建未赋值的变量或赋值
if (let a = 10) {
  a = 20;
}

同样,您的 linter 不应允许它保留,但它不会损害您的代码。

好像不支持out-of-the-box:

https://palantir.github.io/tslint/usage/rule-flags/

但是,TSLint 确实支持自定义规则:

https://palantir.github.io/tslint/develop/custom-rules/

一个潜在的解决方案是编写一个总是失败的自定义规则,为项目禁用它,然后启用上面你希望总是失败的行:

/* tslint:enable:error-next-line */
myTestCodeFunction();