-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
wemake-python-styleguide is a Flake8-based style guide that depends on many other Flake8 plugins (AFAICT all implemented by Ruff), but it also ships lots of custom Flake8 rules. Is there an interest to implement those? As a bonus, the rule naming format is already Ruff-friendly (three letters, three numbers, sorted into categories)
UPDATE 2023-04-19: I have finally got to work on the list a bit more. Here are the rules that I think would make sense to implement in Ruff.
WPS1xx — Naming
Some of those are already covered by pep8-naming (N), but some are missing.
-
WPS100— Forbid blacklisted (= not expressive enough) module names (likeutils) -
covered by N807WPS101— Forbid magic names (except some whitelisted ones). -
covered by N999WPS102— Forbid module names that do not match our pattern. -
WPS110— Forbid blacklisted variable names. (similar to WPS100) -
WPS111— Forbid short variable or module names (1-2 characters). -
WPS112— Forbid private name pattern. (e.g.__collect_coverage())- potentially fixable (
__collect_coverage()→_collect_coverage())
- potentially fixable (
-
covered by PLC0414WPS113— Forbid using the same alias as the original name in imports. -
WPS114— Forbid names with underscored numbers pattern. (wrong:iso_123_456) -
WPS115— Require snake_case for naming class attributes. Similar to N806- potentially fixable (
VARIABLE_NAME→variable_name)
- potentially fixable (
-
WPS116— Forbid using more than one consecutive underscore in variable names.- potentially fixable (
variable__name→variable_name)
- potentially fixable (
-
WPS117— Forbid naming variablesself,cls, ormcs. -
WPS118— Forbid long variable or module names. (default: over 45 characters) -
WPS119— Forbid Unicode names. Only allow ASCII. -
WPS120— Forbid trailing_for names that do not need it. (variables that don't actually shadow any builtins)- potentially fixable (
variable_name_→variable_name)
- potentially fixable (
-
WPS121— Forbid using variables that are marked as unused. Either don't use or rename- potentially fixable (
_variable_name→variable_name)
- potentially fixable (
-
WPS122— Forbid explicit unused variables. Either use or don't define- potentially fixable (
_ = my_function()→my_function())
- potentially fixable (
-
WPS123— Forbid unused variables with multiple underscores.- potentially fixable (
__, var_name = my_function()→_, var_name = my_function())
- potentially fixable (
-
WPS124— Forbid variable or module names which could be difficult to read. (e.g.Memo0Output) -
covered byWPS125— Forbid variable or module names which shadow builtin names.flake8-builtins(A)
WPS2xx — Complexity
Unlike mccabe (C90), WPS also relies on other metrics, like Jones complexity and cognitive complexity (as proposed by G. Ann Campbell). Some violations are covered by Pylint (PLR).
-
WPS200— Forbid modules with complex lines. (median Jones Complexity of module > 12) -
WPS201— Forbid modules with too many (12+) imports. -
WPS202— Forbid too many (7+) classes and functions in a single module. -
WPS203— Forbid modules with too many (50+) imported names. -
WPS204— Forbid overused expressions in a module, function or method. (expression referenced over 4 times in function / over 7 times in module) -
WPS210— Forbid too many (5+) local variables in the unit of code. -
covered by PLR0913WPS211— Forbid too many arguments for a function or method. -
covered by PLR0911WPS212— Forbid placing too many return statements in a function. -
covered by PLR0915WPS213— Forbid putting too many expressions in a single function. -
WPS214— Forbid too many methods (7) in a single class. -
WPS215— Restrict the maximum number of base classes (3). -
WPS216— Restrict the maximum number of decorators (5). -
WPS217— Forbid placing too many (5+)awaitexpressions in a function. -
WPS218— Forbid placing too many (5+)assertstatements into a function. -
WPS219— Forbid consecutive expressions with too deep (4+) access level. (e.g.self.attr.inner.wrapper.method.call()— 5 levels deep) -
[WPS220]— Forbid nesting blocks too deep.- kinda covered by C901?
-
WPS221— Forbid complex (Jones Complexity > 14) lines. -
WPS222— Forbid conditions with too many (4+) logical operators. -
WPS223— Forbid too many (3+)elifbranches. -
WPS224— Forbid too manyforstatements within a comprehension. -
WPS225— Forbid too many (3+)exceptcases in a singletryclause. -
WPS226— Forbid the overuse (3+ usages) of string literals. -
WPS227— Forbid returning or yielding tuples that are too long. -
WPS228— Forbid compare expressions that are too long (4+ items). -
WPS229— Forbidtryblocks with bodies that are too long (over 1 line). -
WPS230— Forbid instances with too many (6+) public attributes. -
WPS231— Forbid functions with too much (12+) cognitive complexity. -
WPS232— Forbid modules with average cognitive complexity that is too high (8+). -
WPS233— Forbid call chains that are too long (3+). -
WPS234— Forbid overly complex annotations (3+ levels). -
WPS235— Forbidfrom ... import ...with too many (8+) imported names. -
WPS236— Forbid using too many (4+) variables to unpack a tuple. -
WPS237— Forbids f-strings that are too complex.A complex format string is defined as use of any formatted value that is not:
- the value of a variable
- the value of a collection through lookup with a variable, number, or string as the key
- the return value of a procedure call without arguments
-
WPS238— Forbids too many (3+)raisestatements in a function.
WPS3xx — Consistency
A lot of those are very opinionated and some have to do with code style. Implement with caution :)
-
covered by TID252WPS300— Forbid imports relative to the current folder. -
WPS301— Forbid imports likeimport os.path(dotted raw imports). -
covered by UP025WPS302— Forbidustring prefix. -
WPS303— Forbid underscores (_) in numbers. -
WPS304— Forbid partial floats like.05or23.. -
WPS305— Forbid f-strings. -
WPS306— Forbid writing classes without base classes. Useobjectas implicit base class. -
WPS307— Forbid multipleifstatements inside list comprehensions. -
covered by PLR0133WPS308— Forbid comparing between two literals. -
covered by SIM300WPS309— Forbid comparisons where the argument doesn't come first. -
WPS310— Forbid uppercaseX,O,B, andEin numbers. -
WPS311— Forbid comparisons with multiple in checks. -
WPS312— Forbid comparisons of a variable to itself. -
covered by E275WPS313— Enforce separation of parenthesis from keywords with spaces. -
WPS314— Forbid using if statements that use invalid (= always true or always false) conditionals. (if True:) -
WPS315— Forbid extra object in parent classes list. -
WPS316— Forbid multiple assignment targets for context managers. -
covered by E122WPS317— Forbid incorrect indentation for parameters. -
covered by E117WPS318— Forbid extra indentation. -
WPS319— Forbid brackets in the wrong position. -
WPS320— Forbid multi-line function type annotations. -
WPS321— Forbid uppercase string modifiers. -
WPS322— Forbid triple quotes for singleline strings. -
WPS323— Forbid % formatting on strings. -
covered by RET502WPS324— Enforce consistent return statements. -
WPS325— Enforce consistent yield statements. -
covered by ISC001WPS326— Forbid implicit string concatenation. -
WPS327— Forbid meaninglesscontinuein loops. -
WPS328— Forbid meaningless nodes. (like an immediately broken loop) -
WPS329— Forbid meaningless (= immediately reraised)exceptcases. -
WPS330— Forbid unnecessary operators in your code. -
WPS331— Forbid local variables that are only used inreturnstatements. -
WPS332— Forbid walrus operator. -
WPS333— Forbid implicit complex comparison expressions. -
WPS334— Forbid reversed order complex comparison expressions.- potentially fixable:
a > b > c->c < b < a
- potentially fixable:
-
WPS335— Forbid wrongforloop iter targets. Use either variables or literal tuples, not literal sets/dicts/lists -
WPS336— Forbid explicit string concatanation in favour of.format()method. -
WPS337— Forbid multiline conditions. -
WPS338— Forbid incorrect order of methods inside a class.We follow “Newspaper order” where the most important things come first.
- init_subclass
- new
- init
- call
- await
- public and magic methods
- protected methods
- private methods (we discourage using them)
-
WPS339— Forbid meaningless (traling, leading) zeros. -
WPS340— Forbid redundant+signs in the exponent. -
WPS341— Forbid lowercase letters in hex numbers. -
WPS342— Forbid\\escape sequences inside regular strings. Use raw strings. -
WPS343— Forbid uppercase complex number suffix. -
WPS344— Forbid explicit division (or modulo) by zero. -
WPS345— Forbid meaningless math operations with 0 and 1. -
WPS346— Forbid double minus operations. -
WPS347— Forbid imports that may cause confusion outside of the module.Names that we forbid to import:
- Common names like
dumpsandloads - Names starting with
to_andfrom_ - Too short names like
QorF, but we are fine with_
- Common names like
-
WPS348— Forbid starting lines with a dot. -
WPS349— Forbid redundant components in a subscript's slice. -
WPS350— Enforce using augmented assign (x += 1instead ofx = x + 1) pattern. -
WPS351— Forbid unnecessary literals in your code.- somewhat covered by C405, C406, C408
-
WPS352— Forbid multiline loops. -
WPS353— Forbidyield fromwith several nodes. (see WPS335) -
WPS354— Forbid consecutiveyieldexpressions. Useyield from -
WPS355— Forbid useless blank lines before and after brackets. -
WPS356— Forbid unnecessary iterable unpacking. -
WPS357— Forbid using\r(carriage return) in line breaks. -
WPS358— Forbid using float zeros:0.0. Cast explicitly. -
WPS359— Forbids to unpack iterable objects to lists. -
WPS360— Forbid the use of raw strings when there is no backslash in the string. -
WPS361— Forbids inconsistent newlines in comprehensions. Either all or nothing. -
WPS362— Forbid assignment to a subscript slice.
WPS4xx — Best practices
-
WPS400— Restrict various control (such as magic) comments.- forbids
noqawithout violation number andtype:comments noqacovered by PGH004
- forbids
-
WPS401— Forbid empty doc comments (#:). -
WPS402— Forbid too many (10+)# noqacomments. -
WPS403— Forbid too many (5+)# pragma: no covercomments. -
WPS404— Forbid complex defaults. -
WPS405— Forbid anything other thanast.Nameto define loop variables. -
WPS406— Forbid anything other thanast.Nameto define contexts. -
WPS407— Forbid mutable constants on a module level. -
WPS408— Forbid using the same logical conditions in one expression. (e.g.if x or x) -
WPS409— Forbid heterogeneous operators in one comparison. (e.g.if x > y == 5) -
WPS410— Forbid some module-level variables.We discourage using module variables like
__author__, because code should not contain any metadata. -
WPS411— Forbid empty modules. -
WPS412— Forbid logic inside__init__module. -
WPS413— Forbid__getattr__and__dir__module magic methods. -
WPS414— Forbid tuple unpacking with side-effects. -
WPS415— Forbid the same exception class in multipleexceptblocks. -
WPS416— Forbidyieldkeyword inside comprehensions. -
WPS417— Forbid duplicate items in hashes (set or dict literals).- potetially fixable for sets: remove duplicate items from set literal
-
WPS418— Forbid exceptions inherited fromBaseException.- potetially fixable: replace
BaseException->Exception
- potetially fixable: replace
-
WPS419— Forbid multiple returning paths withtry/exceptcase. -
WPS420— Forbid some python keywords (del,pass,global,nonlocal). -
WPS421— Forbid calling some built-in functions. (list) -
covered by UPWPS422— Forbid old__future__imports. -
WPS423— ForbidNotImplementedexception. -
WPS424— ForbidBaseExceptionexception. -
covered by PBTWPS425— Forbid booleans as non-keyword parameters. -
WPS426— Forbid lambda inside loops. -
WPS427— Forbid unreachable code. -
WPS428— Forbid statements that do nothing. -
WPS429— Forbid multiple assignments on the same line. -
WPS430— Forbid nested functions. -
WPS431— Forbid nested classes. -
WPS432— Forbid magic numbers.- covered by PLR2004 for comparisons, but not for arithmetic operations
-
WPS433— Forbid imports nested in functions. -
WPS434— Forbid assigning a variable to itself. -
WPS435— Forbid multiplying lists. -
WPS436— Forbid importing protected modules. -
WPS437— Forbid protected attributes and methods. -
WPS438— Forbid raisingStopIterationinside generators. -
WPS439— Forbid Unicode escape sequences in binary strings. -
WPS440— Forbid overlapping local and block variables. -
WPS441— Forbid control variables after the block body. -
WPS442— Forbid shadowing variables from outer scopes. -
WPS443— Forbid explicit unhashable types of asset items anddictkeys. -
WPS444— Forbid explicit falsely-evaluated conditions with several keywords. (e.g.while False: ... -
WPS445— Forbid incorrectly named keywords in double-starred dicts. (e.g.f(**{'4': '2'})is incorrect, as it would expand tof(4=2)) -
WPS446— Forbid approximate constants (likepi,e, etc.). -
WPS447— Forbid using the alphabet as a string. Use constants fromstring -
WPS448— Forbid incorrect order of except. From most precise to less -
WPS449— Forbidfloatdictionary keys. -
WPS450— Forbid importing protected objects from modules. -
WPS451— Forbid positional only or/arguments. -
WPS452— Forbidbreakandcontinuein afinallyblock. -
covered by EXEWPS453— Forbid executing a file with shebang incorrectly set. -
covered by TRY002WPS454— Forbid raisingExceptionorBaseException. -
WPS455— Forbids using non-trivial expressions as a parameter forexcept. -
WPS456— Forbids usingfloat("NaN")construct to generateNaN. Usemath.nan -
WPS457— Forbids use of infinitewhile True:loops. -
WPS458— Forbids to import from already imported modules. -
WPS459— Forbids comparisons withfloatandcomplex. -
WPS460— Forbids to have single element destructuring. -
WPS461— Forbids to use specific inline ignore (=noqa) violations. -
WPS462— Frobids direct usage of multiline strings. Assign to a variable first -
WPS463— Forbids to have functions starting withget_without returning a value. -
WPS464— Forbid empty comments. -
WPS465— Forbid comparisons between bitwise and boolean expressions. -
WPS466— Forbid using complex grammar for using decorators. (like@some.decorator['method'] + other) -
WPS467— Forbid using a bareraisekeyword outside ofexcept. -
WPS468— Forbid using a placeholder (_) withenumerate. -
WPS469— Forbid raising an exception from itself. -
WPS470— Forbid kwarg unpacking in class definition. -
WPS471— Forbid consecutive slices.- potentially fixable: merge slices
[1:][:2]->[1:3]
- potentially fixable: merge slices
-
WPS472— Forbid getting first element using unpacking. -
WPS473— Limit empty lines in functions or methods body.
WPS5xx — Refactoring
-
covered by PLW0120WPS500— Forbidelsewithoutbreakin a loop. -
WPS501— Forbidfinallyintryblock withoutexceptblock. -
covered by SIM210WPS502— Forbid simplifiableifconditions. (e.g.x = True if y else False) -
covered by RET506WPS503— Forbid useless else cases in returning functions. -
WPS504— Forbid negated conditions together withelseclause. -
WPS505— Forbid nestedtryblocks. -
WPS506— Forbid useless proxylambdaexpressions. -
WPS507— Forbid unpythonic (not using__bool__) zero-length compare. -
WPS508— Forbidnotwith compare expressions. -
WPS509— Forbid nesting ternary expressions in certain places. -
WPS510— Forbidinwith static containers exceptset. -
covered by PLR1701 and SIM101WPS511— Forbid multiple isinstance calls on the same variable. -
WPS512— Forbid multiple isinstance calls with single-item tuples. -
covered by SIM114WPS513— Forbid implicit elif conditions. -
WPS514— Forbid multiple equality comparisons with the same variable. -
covered by SIM115WPS515— Forbidopen()without a context manager. -
WPS516— Forbid comparing types withtype()function. -
WPS517— Forbid useless (constant) starred expressions. -
WPS518— Forbid implicitenumerate()calls. -
WPS519— Forbid implicitsum()calls. -
WPS520— Forbid comparing with explicit falsy constants. -
WPS521— Forbid comparing values with constants using is or is not. -
WPS522— Forbid implicit primitives in the form of lambda functions. -
WPS523— Forbid unpythonic variable swaps. -
WPS524— Forbid misrefactored self assignment. -
WPS525— Forbid comparisons whereinis compared with single item container. -
covered by UP028WPS526— Forbidyieldinsideforloop instead ofyield from. -
WPS527— Require tuples as arguments for certain functions. -
WPS528— Enforce.items()iterator. -
WPS529— Enforce.get()dict method. -
WPS530— Forbid implicit negative indexes. -
covered by SIM103WPS531— Forbidifstatements that simply return booleans in functions or methods. -
WPS532— Forbid ast.Is in ast.Compare.ops when it's size is not zero.
WPS6xx — OOP
-
WPS600— Forbid subclassing lowercase builtins. -
WPS601— Forbid shadowing class level attributes with instance level attributes. -
WPS602— Forbid@staticmethoddecorator. -
WPS603— Forbid certain magic methods. See also WPS420 -
WPS604— Forbid incorrect nodes (e.g. loops) inside class definitions. -
WPS605— Forbid methods without any arguments. -
WPS606— Forbid anything other than a class as a base class. -
WPS607— Forbid incorrect__slots__definition. (e.g. not a tuple, with duplicates, ...) -
WPS608— Forbidsuper()with parameters or outside of methods.- partially covered by UP008
-
WPS609— Forbid directly calling certain magic attributes and methods. -
WPS610— Forbid certain async magic methods. -
WPS611— Forbidyieldinside of certain magic methods. -
WPS612— Forbid useless overwritten methods. -
WPS613— Forbidsuper()with incorrect method or property access. -
WPS614— Forbids descriptors in regular functions. -
WPS615— Forbids to use getters and setters in objects. -
WPS616— Callingsuper()in buggy context (= inside comprehensions).