Last time we introduced custom rules into Sourcery.
This time they're becoming even more powerful as you can filter pattern matches with a condition.
Let's say we want to stop global variables being declared. First let's write down what a global variable is:
DAYS_IN_WEEK = 7
_
Here's a rule to identify global variables:
rules:
- id: no-global-variables
pattern: ${var} = ${value}
condition: |
var.in_module_scope()
and not var.is_upper_case()
and not var.starts_with("_")
description: Don't declare `${var}` as a global variable
Check out the conditions reference to see what conditions are available.
condition
field that means the rule only matches
when the condition is satisfieduse-file-iterator
refactoringreintroduce-else
will now trigger more oftenlist-literal
and dict-literal
will now trigger in every
instance of list()
and dict()
, instead of only in assignmentsreview
command instead of refactor
dict-assign-update-to-union
doesn't trigger for global variables