[-1, 2, -3].map(Math.abs);
with tslint.json configuration:
{
"rules": {
"ban": [
true,
["Math", "abs"]
]
}
}
No error.
A lint failure.
This would be a breaking change, but it makes sense to me. Maybe put it under an option until 6.0?
How come ban is restricted to call expressions? Can we just remove this line?
https://github.com/palantir/tslint/blob/master/src/rules/banRule.ts#L149
Another use case - I want to ban usage of length and name on the DOM window global. It's a rare gotcha but it's gotten me multiple times after refactoring.
console.log('surprise, these are defined in lib.dom.d.ts', length, name);
The following TypeScript-based solutions don't work: (because Subsequent variable declarations must have the same type.)
declare var length: never;
// nor
interface Window {
length: never;
}
Reference in TypeScript issues - https://github.com/Microsoft/TypeScript/issues/14306
@ryanatkn I believe your case would be covered by #3824.
I'm looking for banning those global variables, but also usages of Function.length. Could this rule be expanded to cover property accesses too?
~Removing~ Ignoring the Type: Breaking Change label per #4811. Now accepting PRs!
Most helpful comment
Another use case - I want to ban usage of
lengthandnameon the DOM window global. It's a rare gotcha but it's gotten me multiple times after refactoring.The following TypeScript-based solutions don't work: (because
Subsequent variable declarations must have the same type.)Reference in TypeScript issues - https://github.com/Microsoft/TypeScript/issues/14306