Rule Settings¶
Configuration of rules to enable or disable, specified in the .sourcery.yaml
file (parent reference).
Fields Overview¶
All fields are optional.
Field | Type | Description |
---|---|---|
enable | list of string | List of rule IDs/tags Sourcery will exclusively suggest. |
disable | list of string | List of rule IDs/tags Sourcery will never suggest. |
rule_types | list of string | Types of rules Sourcery will suggest. |
python_version | string | The minimum Python version your project supports. |
Default¶
rule_settings:
enable: [default]
disable: []
rule_types:
- refactoring
- suggestion
- comment
python_version: '3.9'
Complete Example¶
With the following configuration, Sourcery will
- never suggest
for-append-to-extend
orraise-from-previous-error
rules - not suggest any comments
- not suggest any rules requiring Python 3.9 or later
rule_settings:
disable:
- for-append-to-extend
- raise-from-previous-error
rule_types:
- refactoring
- suggestion
python_version: 3.8
Fields¶
enable
¶
list of string
List of rule IDs/tags Sourcery will exclusively suggest.
enable
will be overridden by any disable
configuration.
The default value is the tag default
.
Note
The rules with the default
tag are the ones that are automatically run in
the IDE and command line if there is no config.
Default
[default]
Example
With the following configuration, Sourcery will only suggest
assign-if-exp
and
de-morgan
refactorings.
rule_settings:
enable:
- assign-if-exp
- de-morgan
disable
¶
list of string
If empty (default), Sourcery may suggest any rule.
List of rule IDs/tags Sourcery will never suggest.
disable
will override any enable
configuration.
Default
(Empty list)
Example
With the following configuration, Sourcery will never suggest
assign-if-exp
and
de-morgan
refactorings.
rule_settings:
disable:
- assign-if-exp
- de-morgan
rule_types
¶
list of string
The types of rule Sourcery will suggest.
Default
rule_settings:
rule_types:
- refactoring
- suggestion
- comment
Example
With the following configuration, Sourcery will only suggest refactorings and suggestions, never comments.
rule_settings:
rule_types:
- refactoring
- suggestion
python_version
¶
string
The minimum Python version your project supports.
Sourcery will not suggest any refactorings requiring Python features introduced after this version.
If undefined, Sourcery will suggest refactorings for any Python version.
The mimimum Python version Sourcery supports is 3.3
. Any value lower than this will
result in all Sourcery refactorings and metrics not being suggested/appearing.
Default
rule_settings:
python_version: '3.9'
Example
rule_settings:
python_version: '3.7'
Use Case
Python 3.8 introduced the named expression, also known as the "walrus" operator. By default, Sourcery will assume
you are using the latest version of Python, and so it will suggest refactorings (such as
use-named-expression
) which use the walrus operator.
If your project supports Python 3.7 or lower, you should set python_version
in the refactor
configuration to
prevent this refactoring (and others).