wemake-python-styleguide icon indicating copy to clipboard operation
wemake-python-styleguide copied to clipboard

Enforce `x`, `x1`,` x2` naming consistency

Open sobolevn opened this issue 4 years ago • 10 comments

Rule request

Thesis

I often see that some people use this naming pattern:

x1 = 1
x2 = 2

Which is perfectly fine. But, this one looks ugly:

x = 1
x2 = 2

Note x1 vs x2 difference.

Reasoning

My proposed solution is to create a new naming rule to check that if a variable named something1 or something2 there should not be just something in the current scope. While just something and something1 with something2 are totally fine.

Our own code will have lots of these issues!

sobolevn avatar May 04 '20 11:05 sobolevn

I would say that any numbered name should trigger a violation on unnumbered one.

sobolevn avatar May 04 '20 11:05 sobolevn

Hi, I'd like to claim this issue.

raghul-rajasekar avatar Jun 05 '20 08:06 raghul-rajasekar

Thanks a lot, @raghul-rajasekar!

sobolevn avatar Jun 05 '20 08:06 sobolevn

Hi, I am a Umich student and would like to work on this issue for one of my class assignments!

I have a question regarding the rule: Would just having something like x2 = 2 (without x1 = 1) count as violating the rule?

toennifer avatar Nov 09 '20 23:11 toennifer

No, any names with a context are fine. We only look for this pattern:

x = 1
x2 = 2

sobolevn avatar Nov 10 '20 07:11 sobolevn

Thanks a lot, assigned! Feel free to ask for any help you need 👍

sobolevn avatar Nov 10 '20 07:11 sobolevn

Might also want to consider checking for underscores:

x = 1
x_2 = 2

Dreamsorcerer avatar Feb 08 '21 12:02 Dreamsorcerer

I am wondering: what context should we care about? One function? Or the whole module?

sobolevn avatar Feb 08 '21 12:02 sobolevn

Ok, I am going to only check for names in the same context. Whatever it might be: function, class, module.

sobolevn avatar Feb 08 '21 13:02 sobolevn

Ok, this is hard. There are lots of corner cases and small things to think about.

For example, attributes need special handling:

  • some.x and some.x2 are violating this rule
  • while some.x and other.x2 are not

So, I am moving this feature for the next version.

sobolevn avatar Feb 08 '21 14:02 sobolevn