-
Notifications
You must be signed in to change notification settings - Fork 13
/
.sourcery.yaml
158 lines (147 loc) · 4.42 KB
/
.sourcery.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
rule_settings:
enable:
- default
- snake-case-functions
- no-wildcard-imports
- no-long-functions
- docstrings-for-modules
# - docstrings-for-functions
- require-parameter-annotation
disable:
- require-return-annotation # Pylance does infer this quite well already
- use-contextlib-suppress
- use-fstring-for-formatting
- use-fstring-for-concatenation
- do-not-use-staticmethod
- name-type-suffix
- invert-any-all
python_version: "3.8"
rule_types:
- refactoring
- suggestion
- comment
# Specific folders and files to ignore
ignore:
- src/stubber/board
- src/stubber/minified
- src/stubber/tools
- mip/
- snippets/
- tests/*
- "*_test.py"
- tests/codemods/codemod_test_cases/**/*.*
- repos/
- "*.ipynb"
- .venv/
- .git/
- .github/
metrics:
quality_threshold: 25
clone_detection:
min_lines: 3
min_duplicates: 2
identical_clones_only: false
rules:
- id: no-wildcard-imports
pattern: from ${module} import *
description: Do not use wildcard imports
explanation: |
Use import statements for packages and modules only, not for individual classes or functions.
- Use `import x` for importing packages and modules.
- Use `from x import y` where `x` is the package prefix and `y` is the module name with no prefix.
- Use `from x import y as z` if two modules named `y` are to be imported, if `y` conflicts with a top-level name defined in the current module, or if `y` is an inconveniently long name.
- Use `import y as z` only when `z` is a standard abbreviation (e.g., np for numpy).
tags:
- google-python-style-guide
- gpsg
- gpsg-import
tests:
- match: from numpy import *
- match: from pandas.series import *
- match: from .something import *
- no-match: from math import sin
# Quick Fix https://github.com/sourcery-ai/sourcery/issues/314
- id: require-parameter-annotation
pattern: |
def ${name}(..., ${arg}: !!!=${default?}, ...):
...
condition: |
not name.starts_with("_")
and not arg.equals("self")
and not arg.equals("cls")
and not arg.equals("*")
and not arg.equals("/")
paths:
exclude:
- test_*.py
- "*_test.py"
description: Annotate parameter `${arg}` in public function/method `${name}` with a type annotation
explanation: |
Adding type annotations has several benefits:
1. It improves the documentation of the function
2. It allows the function to be checked for correctness
3. It allows checking that the function callers are passing the correct params
These [mypy docs](https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html#functions) describe how to
annotate function arguments and return types.
From Google Style Guide [2.21](https://google.github.io/styleguide/pyguide#221-type-annotated-code)
tags:
- google-python-style-guide
- gpsg
- gpsg-type-annotations
tests:
- match: |
def add(a, b: int):
return a + b
- match: |
def f(a=1):
return a * 2
- no-match: |
def f() -> int:
pass
- no-match: |
def f(a: int, b: str):
pass
- no-match: |
def f(self, a: int, b: str):
pass
- no-match: |
def f(cls, a: int, b: str):
pass
- no-match: |
def f(a: int, *, b: str):
pass
- no-match: |
def f(a: int, /, b: str):
pass
- id: docstrings-for-modules
pattern: |
'''!!!'''
...
condition: pattern.in_module_scope()
paths:
exclude:
- test_*.py
- "*_test.py"
- "__init__.py"
description: Modules should have docstrings
explanation: |
Modules (Python files) should start with docstrings describing the contents and usage of the module.
From Google Style Guide [3.8.2](https://google.github.io/styleguide/pyguide.html#382-modules)
tags:
- google-python-style-guide
- gpsg
- gpsg-docstrings
tests:
- match: |
def hello():
print("hello")
- match: |
class Hello:
"""Hello"""
def hello():
"""Prints 'hello'"""
print("hello")
- no-match: |
"""Hello module"""
def hello():
print("hello")