一个ruff配置,去除了部分关系不大的检查项目,以及单元测试代码因有些特殊性,也需要过滤掉部分检测项目。

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
[tool.ruff]
line-length = 100
show-fixes = true

[tool.ruff.format]
docstring-code-format = true
docstring-code-line-length = 60

[tool.ruff.lint]
# rules: https://docs.astral.sh/ruff/rules/
select = [
"E", # pycodestyle error
"W", # pycodestyle warning
"F", # pyflakes
"UP", # pyupgrade
"D", # pydocstyle
"I", # isort
"C90", # mccabe
"N", # pep8-naming
"ANN", # flake8-annotations
"ASYNC", # flake8-async
"S", # flake8-bandit
"B", # flake8-bugbear
"A", # flake8-builtins
"COM", # flake8-commas
"C4", # flake8-comprehensions
"DTZ", # flake8-datetimez
"T10", # flake8-debugger
"EM", # flake8-errmsg
"ISC", # flake8-implicit-str-concat
"ICN", # flake8-import-conventions
"LOG", # flake8-logging
"G", # flake8-logging-format
"PIE", # flake8-pie
"T20", # flake8-print
"PYI", # flake8-pyi
"PT", # flake8-pytest-style
"Q", # flake8-quotes
"RSE", # flake8-raise
"RET", # flake8-return
"SIM", # flake8-simplify
"TCH", # flake8-type-checking
"PL", # Pylint
"PERF", # Perflint
"RUF", # Ruff-specific rules
]
ignore = [
"UP009", # UTF-8 encoding declaration is unnecessary
"D100", # Missing docstring in public module
"D104", # Missing docstring in public package
"D105", # Missing docstring in magic method
"D107", # Missing docstring in __init__
"B008", # Do not perform function call in argument defaults (not fastapi style)
"ANN101", # self arguments have type annotations, deprecated
"ANN102", # cls arguments have type annotations, deprecated
"RUF001", # String contains ambiguous unicode character (chinese char)
"RUF002", # Docstring contains ambiguous unicode character (chinese comment)
"RUF003", # Comment contains ambiguous unicode character (chinese comment)
]

[tool.ruff.lint.mccabe]
max-complexity = 15

[tool.ruff.lint.per-file-ignores]
"**/app/tests/*" = ["D", "S", "T20", "ANN"] # Don't check this rules in unittest
"__init__.py" = ["F401"] # Allow unused import in __init__.py

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.lint.pylint]
max-args = 20 # some api callbacks need lots of args