Skip to content

Commit 8170954

Browse files
committed
🧪 Run Ruff checks against Python files
1 parent 99edf73 commit 8170954

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

.pre-commit-config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ ci:
44
autoupdate_schedule: quarterly
55

66
repos:
7+
- repo: https://github.com/astral-sh/ruff-pre-commit.git
8+
rev: v0.13.3
9+
hooks:
10+
- id: ruff-check
11+
args:
12+
# Ref: https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
13+
- --exit-non-zero-on-fix
14+
- --fix # NOTE: When `--fix` is used, linting should be before ruff-format
15+
- --show-fixes
16+
717
- repo: https://github.com/astral-sh/ruff-pre-commit.git
818
rev: v0.13.3
919
hooks:

.ruff.toml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,78 @@
11
line-length = 79 # Accessibility-friendly
22

3+
namespace-packages = [
4+
"docs/",
5+
"src/pylibsshext/",
6+
"tests/",
7+
]
8+
39
[format]
410
quote-style = "single"
511

12+
[lint]
13+
external = [
14+
"WPS", # Do not remove noqa for wemake-python-style (WPS) checks
15+
]
16+
ignore = [
17+
"CPY001", # Skip copyright notice requirement at top of files
18+
19+
# Legitimate cases, no need to "fix" these violations:
20+
# E501: "line too long", its function is replaced by `flake8-length`
21+
"E501",
22+
# W505: "doc line too long", its function is replaced by `flake8-length`
23+
"W505",
24+
25+
# FIXME: These `flake8-annotations` errors need fixing and removal
26+
# ANN001: Missing type annotation for function argument 'argv'
27+
"ANN001",
28+
# ANN201: Missing return type annotation for public function
29+
"ANN201",
30+
# ANN202: Missing return type annotation for protected function
31+
"ANN202",
32+
"ANN401", # any-type # FIXME
33+
34+
# Refs:
35+
# * https://github.com/astral-sh/ruff/issues/6606
36+
# * https://github.com/astral-sh/ruff/pull/13286
37+
"DOC201", # Ruff doesn't understand sphinx-native param lists
38+
"DOC402", # docstring-missing-yields # Ruff doesn't understand sphinx-native param lists
39+
"DOC501", # docstring-missing-exception # Ruff doesn't understand sphinx-native param lists
40+
41+
"FIX001", # line-contains-fixme # FIXME
42+
"FIX002", # line-contains-todo # FIXME / noqa
43+
44+
"PLR0914", # too-many-locals # FIXME / noqa
45+
"PLR2004", # magic-value-comparison # FIXME
46+
47+
"RUF100", # Ruff doesn't know about WPS
48+
49+
"SIM117", # multiple-with-statements # FIXME
50+
51+
"TD002", # missing-todo-author # FIXME
52+
"TD004", # missing-todo-colon # FIXME
53+
54+
"TRY003", # raise-vanilla-args # controversial
55+
56+
"UP024", # os-error-alias # FIXME
57+
]
58+
preview = true # Live dangerously
59+
select = [
60+
"ALL",
61+
]
62+
task-tags = [
63+
"FIXME",
64+
"NOTE",
65+
"Ref",
66+
"Refs",
67+
"TODO",
68+
]
69+
70+
[lint.flake8-pytest-style]
71+
parametrize-values-type = "tuple"
72+
73+
[lint.flake8-quotes]
74+
inline-quotes = "single"
75+
676
[lint.isort]
777
combine-as-imports = true
878
force-wrap-aliases = true
@@ -35,3 +105,30 @@ testing = [
35105
"unittest",
36106
"_service_utils",
37107
]
108+
109+
110+
[lint.per-file-ignores]
111+
# Exceptions for code samples in the docs
112+
"docs/_samples/**.py" = [
113+
"ERA001", # commented-out-code
114+
"S105", # hardcoded-password-string
115+
"S108", # hardcoded-temp-file
116+
"T201", # print
117+
]
118+
119+
# Exceptions for test files
120+
"tests/**.py" = [
121+
"ARG002", # Allow unused arguments in instance methods (required for test stubs)
122+
"ARG004", # unused-static-method-argument (hit in WSGI test apps)
123+
"PLC1901", # compare-to-empty-string (test accuracy)
124+
"PLC2701", # Allow importing internal files needed for testing
125+
# "PLR6301", # Allow 'self' parameter in method definitions (required for test stubs)
126+
"S101", # Allow use of `assert` in test files
127+
"S311", # suspicious-non-cryptographic-random-usage
128+
"S404", # Allow importing 'subprocess' module to testing call external tools needed by these hooks
129+
"S603", # subprocess-without-shell-equals-true
130+
"SLF001", # Private member accessed
131+
]
132+
133+
[lint.pydocstyle]
134+
convention = "pep257"

0 commit comments

Comments
 (0)