我们正在使用自定义的eslint插件来推动我们的重构并防止某些错误。 就像不使用这种不赞成使用的方法和不安全的金钱计算一样。
第二条规则是:
const netAmount = amount - taxAmount // NOT SAFE
array.forEach(value, index) {console.log(index - 1)} // NOT SAFE (But I want it safe)
我想知道表达式中变量的类型。所以当我使用
这样的整数时type Integer = number & {__isInteger = true}
array.map(value: any, index: Integer){console.log(index - 1)} // I can ignore my rule because `(index - 1)` is safe.
我目前的规则:
create: function(context) {
return {
BinaryExpression(expression) {
if(expression.operator && expression.operator === '-') {
context.report(expression, 'Use the safelySubstractFloats helper instead of computing the difference with the - operator');
}
}
};
}
@ typescript-eslint是否可能?我需要为打字稿规则做另一个eslint插件吗?我喜欢一些例子:D