-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruff.toml
More file actions
163 lines (147 loc) · 6.66 KB
/
ruff.toml
File metadata and controls
163 lines (147 loc) · 6.66 KB
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
159
160
161
162
163
# SPDX-License-Identifier: MIT
# Copyright 2026 Beslogic Inc.
# https://docs.astral.sh/ruff/configuration/
line-length = 100
# For the formatter we want hug_parens_with_braces_and_square_brackets
# For the linter we use `explicit-preview-rules = true` anyway
preview = true
# tool.ruff.target-version is inferred from project.requires-python
required-version = ">=0.13.0" # Keep in sync with project.dependencies in pyproject.toml
[format]
docstring-code-format = true
[lint]
future-annotations = true
# As a shared config, don't enable unstable behaviour unless we explicitly asks for it.
explicit-preview-rules = true
select = ["ALL"]
# https://docs.astral.sh/ruff/rules/
ignore = [
###
# Not needed or wanted
###
"CPY001", # missing-copyright-notice: Assume license from root OR private project
"D1", # pydocstyle Missing docstring
"D401", # pydocstyle: non-imperative-mood
"EM", # flake8-errmsg
# This is often something we can't control: https://github.com/astral-sh/ruff/issues/9497
# Also false-positive with positional-only arguments: https://github.com/astral-sh/ruff/issues/3247
"FBT003", # flake8-boolean-trap: boolean-positional-value-in-call
"INP", # flake8-no-pep420
"ISC003", # flake8-implicit-str-concat: explicit-string-concatenation
# Short messages are still considered "long" messages
"TRY003", # tryceratops : raise-vanilla-args
# Don't remove commented code, also too inconsistant
"ERA001", # eradicate: commented-out-code
# contextlib.suppress is roughly 3x slower than try/except
"SIM105", # flake8-simplify: use-contextlib-suppress
# Not colored correctly in Pylance https://github.com/microsoft/pylance-release/issues/6942
"UP047", # non-pep695-generic-function
# Checked by type-checker (pyright/mypy)
"ANN", # flake-annotations
"PGH003", # blanket-type-ignore
# Already shown by Pylance, checked by pyright, and can be caused by implementing a protocol.
"ARG002", # Unused method argument
# We want D213: multi-line-summary-second-line and D211: no-blank-line-before-class
# Disabling these two is more concise than selecting https://docs.astral.sh/ruff/settings/#lint_pydocstyle_convention
"D203", # pydocstyle: one-blank-line-before-class
"D212", # pydocstyle: multi-line-summary-first-line
# Allow differentiating between broken (FIXME) and to be done/added/completed (TODO)
"TD001", # flake8-todos: invalid-todo-tag
# Often just leads to redundant more verbose code when needing an actual str
"PTH208", # Use `pathlib.Path.iterdir()` instead.
# Typeshed doesn't want complex or non-literal defaults for maintenance and testing reasons.
# This doesn't affect us, let's have more complete stubs.
"PYI011", # typed-argument-default-in-stub
"PYI014", # argument-default-in-stub
"PYI053", # string-or-bytes-too-long
###
# These should be warnings (https://github.com/astral-sh/ruff/issues/1256 & https://github.com/astral-sh/ruff/issues/1774)
###
"FIX", # flake8-fixme
# Not all TODOs are worth an issue, this would be better as a warning
"TD003", # flake8-todos: missing-todo-link
# Python 3.11 introduced "zero cost" exception handling
# Good to watch for, but often unfixable
"PERF203", # try-except-in-loop,
# TC helps prevent circular imports, reduce runtime cost of typing symbols,
# and prevent leaking implementations details into modules
# However stdlib is not at risk of circular import, is clearly not public API,
# and assume it's gonna be included in the import chain at some point anyway
"TC003", # typing-only-standard-library-import
# Too many magic number "2" that are preferable inline. https://github.com/astral-sh/ruff/issues/10009
"PLR2004", # magic-value-comparison
###
# Conflict with formatter (you can remove this section if you don't use Ruff as a formatter)
###
"COM812", # missing-trailing-comma
###
# Rules about missing special documentation. Up to you if you wanna enable these, you must also disable D406, D407
###
"DOC201", # docstring-missing-returns
"DOC402", # docstring-missing-yields
"DOC501", # docstring-missing-exception
# "D406", # new-line-after-section-name, conflicts with DOC
# "D407", # dashed-underline-after-section, conflicts with DOC
]
[lint.per-file-ignores]
"**/typings/**/*.pyi" = [
"F811", # Re-exports false positives
# The following can't be controlled for external libraries:
"A", # Shadowing builtin names
"E741", # ambiguous variable name
"F403", # `from . import *` used; unable to detect undefined names
"FBT", # flake8-boolean-trap
"ICN001", # unconventional-import-alias
"N8", # Naming conventions
"PLC2701", # Private name import
"PLE0302", # The special method expects a given signature
"PLR0904", # Too many public methods
"PLR0913", # Argument count
"PLR0917", # Too many positional arguments
"PLW3201", # misspelled dunder method name
"SLOT", # flake8-slots
# Stubs can sometimes re-export entire modules.
# Issues with using a star-imported name will be caught by type-checkers.
"F405", # may be undefined, or defined from star imports
# It's normal to be missing annotations for local stubs.
# If they were complete, we'd upload them to typeshed!
"ANN0",
"ANN2",
]
# Ignore non-autofixable issues with auto-generated DB migrations
"**/migrations/*.py" = ["E501", "RUF012"]
# https://docs.astral.sh/ruff/settings/#flake8-implicit-str-concat
[lint.flake8-implicit-str-concat]
allow-multiline = false
# https://docs.astral.sh/ruff/settings/#lintflake8-type-checking
[lint.flake8-type-checking]
quote-annotations = true
# https://docs.astral.sh/ruff/settings/#isort
[lint.isort]
combine-as-imports = true
split-on-trailing-comma = false
# https://docs.astral.sh/ruff/settings/#mccabe
[lint.mccabe]
# Arbitrary to 2 bytes, same as SonarLint
max-complexity = 15
# https://docs.astral.sh/ruff/settings/#lintpylint
[lint.pylint]
# Arbitrary to 1 byte, same as SonarLint
max-args = 7
# At least same as max-complexity
max-branches = 15
# https://docs.astral.sh/ruff/settings/#lintflake8-self
[lint.flake8-self]
# Access Django Models and Serializers' Meta class instance
extend-ignore-names = ["_meta"]
# https://docs.astral.sh/ruff/settings/#lint_flake8-tidy-imports_banned-api
[lint.flake8-tidy-imports.banned-api]
"cv2.imread".msg = """\
it doesn't support special characters. \
Use `cv2.imdecode(np.fromfile(filename, dtype=np.uint8), flags)` instead.
https://github.com/opencv/opencv/issues/18305#issuecomment-2847972863"""
"cv2.imwrite".msg = """\
it doesn't support special characters. \
Use `cv2.imencode(os.path.splitext(filename)[1], img)[1].tofile(filename)` instead.
https://github.com/opencv/opencv/issues/18305#issuecomment-2847972863"""
"rest_framework.parsers".msg = "Use `djangorestframework_camel_case.parser` instead."