tslint-consistent-codestyle
tslint-consistent-codestyle copied to clipboard
naming-convention: banned names and require minimum length
I would like to disallow short variable names and certain keywords.
This should already be possible with a regex, but maybe that could still be added as an option?
Examples where this is useful:
// Short variable names
try {} catch (e) {}
[1, 2].map(n => n*2)
[1, 2].forEach(v => v)
window.addEventListener('error', (ev) => {})
// Banned words (specific names, such as `err`, `num` and `val`
try {} catch (err) {}
[1, 2].map(num => num*2)
[1, 2].forEach(val => val)
Maybe there should be a way to define exceptions, for example i:
for(let i = 0; i < 1; i++) {}
I also noticed that the rule doesn't seem to trigger for the variable used in the catch: try {} catch (e) {}. Is that intended behavior or a bug?
I agree that this is a valid use case. The blacklist would be pretty hard to implement as regular expression. Combining that with a minimum length makes it even worse.
I'm accepting PRs to add new options for minLength, blacklist and maybe maxLength.
We just need to come to a conclusion whether blacklist should be a string array or a regular expression.
Maybe there should be a way to define exceptions
That's already possible using the filter option.