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

New Rule: Consistent Variable Naming #267

Open
elbrujohalcon opened this issue Feb 27, 2023 · 0 comments
Open

New Rule: Consistent Variable Naming #267

elbrujohalcon opened this issue Feb 27, 2023 · 0 comments
Labels
Milestone

Comments

@elbrujohalcon
Copy link
Member

Consistent Variable Naming

Brief Description

This is a more sophisticated version of #266, but it's also more heuristic (thus the possibility of emitting false positives).
The idea is for Elvis to use some sound-alike algorithm to find variables with similar names, like MyVar and My_Var, or MyVar and MyVariable, or MyID and My_id, etc…

Should be on by default?

NO, unless we find a suitable default with a very low false positive rate.

Reasoning

The reasoning here is, again, similar to #266:

If two variables have the same name, it's very likely that they refer to the same concept and, therefore, it would make the lives of code readers easier if they share the exact same name, including casing and all.

Refactoring Proposal

Rename one or more of the variables.

Configuration

The rule must have some soundness_level parameter to adjust how much alike two variables need to be for them to be considered the same.

Examples

-module bad.

-export [my_fun/1, my_fun/2].

my_fun(MyVar) -> my_fun(MyVar, too).

my_fun(My_Var, too) -> {My_Var, too}.
-module good.

-export [my_fun/1, my_fun/2].

my_fun(MyVar) -> my_fun(MyVar, too).

my_fun(MyVar, too) -> {MyVar, too}.
-module also_good.

-export [my_fun/1, my_fun/2].

my_fun(MyVar) -> my_fun(MyVar, too).

my_fun(MyVar, MyOtherVar) -> {MyVar, MyOtherVar}.
@elbrujohalcon elbrujohalcon added this to the 2.1.0 milestone Feb 27, 2023
@elbrujohalcon elbrujohalcon changed the title Consistent Variable Naming New Rule: Consistent Variable Naming Feb 28, 2023
@elbrujohalcon elbrujohalcon modified the milestones: 3.0.0, 3.1.0 Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant