Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

naming-convention: banned names and require minimum length #112

Open
AndreasGassmann opened this issue Feb 28, 2019 · 1 comment
Open

naming-convention: banned names and require minimum length #112

AndreasGassmann opened this issue Feb 28, 2019 · 1 comment

Comments

@AndreasGassmann
Copy link

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?

@ajafff
Copy link
Owner

ajafff commented Mar 1, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants