Skip to content

Commit 5bc10a0

Browse files
committed
chore(lint): consolidate lint scripts and tidy ruff config
Follow-up to #174 based on review feedback: - Keep the existing ruff ruleset (per review, the strict set is fine). - Remove only dead config: the D-rule ignores/per-file-ignores and the pydocstyle section referenced rules that were never in select, so they had no effect. No change to what is actually enforced. - Collapse scripts/lint + scripts/format + scripts/ruff-common.sh into a single 'scripts/ruff {check|fix}'. - Fix scripts/ruff fix: 'ruff check --fix' exits non-zero on remaining unfixable lints, which under 'set -e' aborted before formatting ran, leaving files unformatted. Now formatting always runs. - Point CI, README, and pre-commit at the single script.
1 parent 3c98d3b commit 5bc10a0

8 files changed

Lines changed: 48 additions & 56 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,8 @@ jobs:
3030
python-version: "3.11"
3131
- name: Install ruff
3232
run: pip install --no-cache-dir -r requirements-dev.txt
33-
- name: Run ruff format check
34-
run: ruff format --check .
35-
- name: Run ruff lint check
36-
if: success() || failure()
37-
run: ruff check .
33+
- name: Run ruff (format + lint check)
34+
run: ./scripts/ruff check
3835
ddprof:
3936
uses: ./.github/workflows/test.yml
4037
with:

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# Optional git hooks for Python scenario files (same checks as CI — see scripts/lint).
1+
# Optional git hooks for Python scenario files (same checks as CI — see scripts/ruff).
22
# Setup: pip install -r requirements-dev.txt pre-commit && pre-commit install
3-
# On Datadog laptops with global core.hooksPath, use ./scripts/lint instead of pre-commit install.
3+
# On Datadog laptops with global core.hooksPath, run ./scripts/ruff check manually instead.
44
repos:
55
- repo: local
66
hooks:
77
- id: ruff
8-
name: ruff (scripts/lint)
9-
entry: scripts/lint
8+
name: ruff (scripts/ruff check)
9+
entry: scripts/ruff check
1010
language: system
1111
types: [python]

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ pip install -r requirements-dev.txt
1919
```
2020

2121
```sh
22-
./scripts/lint # check (matches the ci.yml ruff job)
23-
./scripts/format # auto-fix formatting and lint
22+
./scripts/ruff check # what CI runs (format --check + lint)
23+
./scripts/ruff fix # auto-fix formatting and lint in place
2424
```
2525

26-
Optional git hooks (skip on Datadog laptops that use global `core.hooksPath` — run `./scripts/lint` manually instead):
26+
Optional git hooks (skip on Datadog laptops that use global `core.hooksPath` — run `./scripts/ruff check` manually instead):
2727

2828
```sh
2929
pip install pre-commit

pyproject.toml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,13 @@ select = [
4040
"RUF", # Ruff-specific rules
4141
]
4242
ignore = [
43-
"D203", # one-blank-line-before-class (conflicts with D211)
44-
"D213", # multi-line-summary-second-line (conflicts with D212)
4543
"T201", # print statement used
4644
"PLR2004", # constant variable
4745
]
4846

4947
[tool.ruff.lint.per-file-ignores]
50-
"**/__init__.py" = ["D104"] # missing docstring in public package
51-
"**/test_*.py" = ["S101", "D"] # allow assert in tests, skip docstrings
52-
"**/tests/**/*.py" = ["S101", "D"] # allow assert in tests, skip docstrings
53-
54-
[tool.ruff.lint.pydocstyle]
55-
convention = "google"
48+
"**/test_*.py" = ["S101"] # allow assert in tests
49+
"**/tests/**/*.py" = ["S101"] # allow assert in tests
5650

5751
[tool.ruff.lint.mccabe]
5852
max-complexity = 10

scripts/format

Lines changed: 0 additions & 9 deletions
This file was deleted.

scripts/lint

Lines changed: 0 additions & 10 deletions
This file was deleted.

scripts/ruff

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
# Python lint/format for scenario workloads. Uses the ruff pinned in requirements-dev.txt.
3+
#
4+
# scripts/ruff check [paths...] # what CI runs (see .github/workflows/ci.yml)
5+
# scripts/ruff fix [paths...] # auto-fix lint + format in place
6+
#
7+
# With no paths, runs on the whole repo (".").
8+
set -euo pipefail
9+
10+
cd "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
11+
12+
if ! command -v ruff >/dev/null 2>&1; then
13+
echo "ruff not found; install with: pip install -r requirements-dev.txt" >&2
14+
exit 1
15+
fi
16+
17+
mode="${1:-check}"
18+
[ $# -gt 0 ] && shift
19+
targets=("$@")
20+
[ ${#targets[@]} -eq 0 ] && targets=(".")
21+
22+
case "$mode" in
23+
check)
24+
ruff format --check "${targets[@]}"
25+
ruff check "${targets[@]}"
26+
;;
27+
fix)
28+
# `ruff check --fix` exits non-zero when unfixable lints remain; `|| true` keeps
29+
# `set -e` from aborting before we format. Fix first, format last, so output converges.
30+
ruff check --fix "${targets[@]}" || true
31+
ruff format "${targets[@]}"
32+
;;
33+
*)
34+
echo "usage: scripts/ruff {check|fix} [paths...]" >&2
35+
exit 2
36+
;;
37+
esac

scripts/ruff-common.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)