MartinThoma / flake8-simplify

❄ A flake8 plugin that helps you to simplify code
MIT License
186 stars 19 forks source link

[New Rule] Enumeration of 4 or more variables #133

Open MartinThoma opened 2 years ago

MartinThoma commented 2 years ago

Explanation

A code smell I see sometimes is enumeration of variables where an iterable should be used, e.g. a list.

Using a list has several advantages:

Example

# Bad
foo1 = "bar"
foo2 = "baz"
foo3 = "42"
foo4 = "1337"

# Good
foo = ["bar", "baz", "42", "1337"]

False-Positives

Just looking for a number in the end would have a quite high chance of false-positivies, e.g.:

Hence I would look for variables where the direct siblings are 1-4 (or more)