codedoctor 0.1.5__tar.gz → 0.1.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {codedoctor-0.1.5 → codedoctor-0.1.6}/.pre-commit-config.yaml +89 -21
- {codedoctor-0.1.5 → codedoctor-0.1.6}/CHANGELOG.md +12 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/PKG-INFO +9 -6
- {codedoctor-0.1.5 → codedoctor-0.1.6}/README.md +8 -5
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/affected/affected.py +3 -3
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/affected/affected_test.py +20 -12
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/assert_isinstance/unnecessary_assert_isinstance.py +28 -11
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/assert_isinstance/unnecessary_assert_isinstance_test.py +15 -4
- codedoctor-0.1.6/codedoctor/cargo/__init__.py +1 -0
- codedoctor-0.1.6/codedoctor/cargo/__main__.py +17 -0
- codedoctor-0.1.6/codedoctor/cargo/cargo.py +81 -0
- codedoctor-0.1.6/codedoctor/cargo/cargo_test.py +135 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/cli.py +1 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/cli_test.py +1 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/coverage_floor/coverage_floor_test.py +9 -4
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/export_leaks/check_export_leaks.py +212 -4
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/export_leaks/check_export_leaks_test.py +264 -13
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/gate/gate.py +3 -3
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/install.py +71 -32
- codedoctor-0.1.6/codedoctor/install_biome.json +59 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/install_hooks.yaml +70 -160
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/install_test.py +179 -17
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/files/glob.py +153 -72
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/files/glob_test.py +150 -57
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/files/grep.py +290 -141
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/files/grep_test.py +387 -120
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/files/tempclaim.py +16 -2
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/files/tempclaim_test.py +30 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/pyproject_flags.py +5 -1
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/testing/resources.py +36 -9
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/testing/wheel.py +14 -3
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/userdirs.py +1 -1
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/worker_count_test.py +1 -1
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lint/checker.py +137 -26
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lint/checker_test.py +111 -4
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lint/house_ignore.py +28 -3
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lint/house_ignore_test.py +24 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lint/rules.py +465 -65
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lint/rules_test.py +222 -26
- codedoctor-0.1.6/codedoctor/mutation/README.md +55 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/mutation/mutated.py +179 -128
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/mutation/mutated_test.py +1096 -414
- codedoctor-0.1.6/codedoctor/mutation/mutmut_adapter.py +627 -0
- codedoctor-0.1.6/codedoctor/mutation/mutmut_adapter_test.py +743 -0
- codedoctor-0.1.6/codedoctor/mutation/mutmut_cli.py +20 -0
- codedoctor-0.1.6/codedoctor/mutation/mutmut_cli_test.py +40 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/mutation/mutmut_dynamo_test.py +63 -33
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/mutation/mutmut_outcome_test.py +17 -35
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/mutation/mutmut_param_ids_test.py +39 -42
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/policy.py +8 -6
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/policy_test.py +77 -1
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/testing/listing_test.py +215 -289
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/testing/outcomes.py +3 -3
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/testing/outcomes_test.py +12 -6
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/testing/testing_test.py +56 -51
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/typecheck/typecheck.py +5 -5
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/typecheck/typecheck_test.py +14 -1
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/yamlcheck/checker_test.py +22 -13
- {codedoctor-0.1.5 → codedoctor-0.1.6}/pyproject.toml +11 -7
- {codedoctor-0.1.5 → codedoctor-0.1.6}/tests/lib/testing/resources_test.py +142 -66
- {codedoctor-0.1.5 → codedoctor-0.1.6}/tests/lib/testing/wheel_test.py +20 -1
- {codedoctor-0.1.5 → codedoctor-0.1.6}/uv.lock +94 -73
- {codedoctor-0.1.5 → codedoctor-0.1.6}/.gitignore +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/.python-version +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/AI_POLICY.md +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/CODE_OF_CONDUCT.md +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/CONTRIBUTING.md +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/LICENSE +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/RELEASING.md +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/SECURITY.md +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/__init__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/__main__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/affected/__init__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/affected/__main__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/affected/backbone.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/affected/backbone_test.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/affected/codegraph_sync.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/affected/codegraph_sync_test.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/assert_isinstance/__init__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/assert_isinstance/__main__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/codegraph.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/codegraph_test.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/coverage_floor/__init__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/coverage_floor/__main__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/coverage_floor/coverage_floor.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/export_leaks/__init__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/export_leaks/__main__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/export_leaks/check_pr_text.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/export_leaks/check_pr_text_test.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/gate/__init__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/gate/__main__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/gate/fakes.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/gate/fakes_test.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/gate/gate_test.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/gate/spool.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/gate/spool_test.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/__init__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/files/__init__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/files/owner_only.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/files/owner_only_test.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/files/source_version.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/files/source_version_test.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/files/walk.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/files/walk_test.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/kernel_pins.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/kernel_pins_test.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/pyproject_flags_test.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/sidecars.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/sidecars_test.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/testing/__init__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/testing/basetemp.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/testing/checks.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/testing/checks_test.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/testing/runner.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/testing/runner_test.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lib/worker_count.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lint/__init__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lint/__main__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lint/custom_types.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/lint/custom_types_test.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/mutation/__init__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/mutation/__main__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/mutation/mutmut_dynamo.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/mutation/mutmut_kill_guard.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/mutation/mutmut_kill_guard_test.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/mutation/mutmut_outcome.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/mutation/mutmut_param_ids.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/nbstripout/__init__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/nbstripout/__main__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/nbstripout/nbstripout_hook.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/nbstripout/nbstripout_hook_test.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/py.typed +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/testing/__init__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/testing/__main__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/testing/coverage_summary.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/testing/coverage_summary_test.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/testing/listing.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/testing/testing.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/testing/tiers.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/testing/tiers_test.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/typecheck/__init__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/typecheck/__main__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/typecheck/scope.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/typecheck/scope_test.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/yamlcheck/__init__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/yamlcheck/__main__.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/yamlcheck/checker.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/conftest.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/tests/lib/testing/basetemp_test.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/tests/lib/userdirs_test.py +0 -0
- {codedoctor-0.1.5 → codedoctor-0.1.6}/typings/.gitkeep +0 -0
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
# scratch project). Name it anyway so the command does not depend on that
|
|
12
12
|
# chain staying intact.
|
|
13
13
|
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
14
|
+
# uvr --group pre-commit pre-commit install
|
|
15
|
+
# uvr --group pre-commit pre-commit autoupdate
|
|
16
|
+
# uvr --group pre-commit pre-commit run --all-files
|
|
17
17
|
#
|
|
18
18
|
# May need: git config --unset-all core.hooksPath
|
|
19
19
|
# if: [ERROR] Cowardly refusing to install hooks with `core.hooksPath` set.
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
# the pre-commit hooks; the heavy ones (ty-check-global, basedpyright-global,
|
|
23
23
|
# pytest*) declare `stages: [pre-push]` and need it named explicitly:
|
|
24
24
|
#
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
25
|
+
# uvr --group pre-commit pre-commit run --all-files
|
|
26
|
+
# uvr --group pre-commit pre-commit run --all-files --hook-stage pre-push
|
|
27
|
+
# uvr --group pre-commit pre-commit run --all-files --hook-stage commit-msg
|
|
28
28
|
#
|
|
29
29
|
# Always pass --files or --all-files. Bare `run` (and the hook `git commit`
|
|
30
30
|
# fires on a dirty tree) STASHES your changes -- a git mutation, and this
|
|
@@ -50,42 +50,47 @@
|
|
|
50
50
|
# arguments under `$(...)` or a bare `xargs`, and a rename record yields the
|
|
51
51
|
# name that no longer exists.
|
|
52
52
|
#
|
|
53
|
+
# # Run only the diffed files from the CWD (the AGENTS.md gate).
|
|
54
|
+
# { git --no-pager diff -z --name-only --relative --diff-filter=d --merge-base origin/main .
|
|
55
|
+
# git ls-files -z --others --exclude-standard .
|
|
56
|
+
# } | xargs -0 -r uvr --group pre-commit pre-commit run --files
|
|
57
|
+
#
|
|
53
58
|
# # Harvest all changed files from the perspective of CWD.
|
|
54
59
|
# git -C "$(git rev-parse --show-toplevel)" diff -z --name-only --diff-filter=d HEAD \
|
|
55
|
-
# | xargs -0 --no-run-if-empty
|
|
60
|
+
# | xargs -0 --no-run-if-empty uvr --group pre-commit pre-commit run --files
|
|
56
61
|
#
|
|
57
|
-
# # Run only the files from the CWD.
|
|
62
|
+
# # Run only the staged files from the CWD.
|
|
58
63
|
# git --no-pager diff -z --name-only --cached --relative \
|
|
59
|
-
# | xargs -0 --no-run-if-empty
|
|
64
|
+
# | xargs -0 --no-run-if-empty uvr --group pre-commit pre-commit run --files
|
|
60
65
|
#
|
|
61
66
|
# # Run all the files from CWD.
|
|
62
|
-
#
|
|
67
|
+
# git ls-files -z . | xargs -0 -r uvr --group pre-commit pre-commit run --files
|
|
63
68
|
#
|
|
64
69
|
# One hook at a time, by id (`ruff-check`, `ty-check`, `pytest-global`, ...):
|
|
65
|
-
#
|
|
66
|
-
#
|
|
70
|
+
# uvr --group pre-commit pre-commit run ruff-check --all-files
|
|
71
|
+
# uvr --group pre-commit pre-commit run pytest-global --hook-stage pre-push
|
|
67
72
|
#
|
|
68
73
|
# Force full pytest tiers despite testmon's warm dependency database:
|
|
69
|
-
# PYTEST_FORCE_ALL=1
|
|
74
|
+
# PYTEST_FORCE_ALL=1 uvr --group pre-commit pre-commit run pytest-global --hook-stage pre-push
|
|
70
75
|
#
|
|
71
76
|
# Individual tests: the pytest hooks take no test selector, so call pytest
|
|
72
77
|
# directly.
|
|
73
78
|
#
|
|
74
|
-
#
|
|
75
|
-
#
|
|
76
|
-
#
|
|
77
|
-
#
|
|
79
|
+
# uvr --group pre-commit pytest path/to/thing_test.py
|
|
80
|
+
# uvr --group pre-commit pytest path/to/thing_test.py::test_name
|
|
81
|
+
# uvr --group pre-commit pytest -k some_substring path/to/
|
|
82
|
+
# uvr --group pre-commit pytest -n 5 path/to/
|
|
78
83
|
#
|
|
79
84
|
# Marker tiers mirror the pytest-slow-global / -ci-smoke-global /
|
|
80
85
|
# -integration-global hooks; the
|
|
81
86
|
# default `-m` filter lives in pyproject addopts, so ask for them by name:
|
|
82
87
|
#
|
|
83
|
-
#
|
|
88
|
+
# uvr --group pre-commit pytest -m slow path/to/
|
|
84
89
|
#
|
|
85
90
|
# Skipping. SKIP takes hook ids, comma-separated, and reports "Skipped":
|
|
86
91
|
#
|
|
87
|
-
# SKIP=ruff-check
|
|
88
|
-
# SKIP=pytest-global,pytest-slow-global
|
|
92
|
+
# SKIP=ruff-check uvr --group pre-commit pre-commit run --all-files
|
|
93
|
+
# SKIP=pytest-global,pytest-slow-global uvr --group pre-commit pre-commit run --hook-stage pre-push --all-files
|
|
89
94
|
#
|
|
90
95
|
# `git commit --no-verify` / `git push --no-verify` bypass every hook. Both
|
|
91
96
|
# are a last resort, not a way past a red gate -- the gates are house rules
|
|
@@ -308,7 +313,7 @@ repos:
|
|
|
308
313
|
# serial vs 0.30s pooled; 50 files 0.92s vs 0.50s; the full tree (4094
|
|
309
314
|
# files) 21.8s serial vs 1.46s at 24 workers.
|
|
310
315
|
- id: codedoctor-lint
|
|
311
|
-
name: codedoctor
|
|
316
|
+
name: codedoctor-lint
|
|
312
317
|
language: system
|
|
313
318
|
stages: [pre-commit]
|
|
314
319
|
require_serial: true
|
|
@@ -587,6 +592,69 @@ repos:
|
|
|
587
592
|
- --fixer
|
|
588
593
|
- codedoctor.assert_isinstance
|
|
589
594
|
|
|
595
|
+
# TypeScript, JavaScript and CSS: `biome check --write` formats, applies the
|
|
596
|
+
# safe lint fixes, and fails on any lint error left. Settings and exclusions
|
|
597
|
+
# live in biome.json. `files` narrows upstream's list, which also covers JSON
|
|
598
|
+
# goldens and OpenAPI schemas that drift tests compare byte for byte. HTML
|
|
599
|
+
# stays out: Biome cannot parse the Liquid and Python templates most of it
|
|
600
|
+
# holds. An export's `biome_format` transform re-wraps what its rewrites
|
|
601
|
+
# changed.
|
|
602
|
+
#
|
|
603
|
+
# Rules biome.json turns off, each wrong for this code:
|
|
604
|
+
# noDescendingSpecificity stylesheets group rules by component; a later,
|
|
605
|
+
# more specific rule is a deliberate override.
|
|
606
|
+
# useOptionalChain `x && x.y` keeps x's falsy value (0, "", false),
|
|
607
|
+
# which `x?.y` turns into undefined.
|
|
608
|
+
# noImportantStyles `!important` beats the inline styles libraries
|
|
609
|
+
# (xterm, d3, resizable panels) set.
|
|
610
|
+
# useSemanticElements the native twin cannot hold the content: an
|
|
611
|
+
# <option> holds only text, an <hr> no children.
|
|
612
|
+
# A package's own settings live in a nested biome.json beside it, which its
|
|
613
|
+
# export ships: the React packages' react domain, and where these are off:
|
|
614
|
+
# noRedundantUseStrict classic scripts, where "use strict" is not implied.
|
|
615
|
+
# useDomNodeTextContent e2e specs read innerText: the text a reader sees.
|
|
616
|
+
# noComponentHookFactories tests and router/lazy.ts build components on purpose.
|
|
617
|
+
# useExhaustiveDependencies keeps a listed dependency it finds unneeded: such
|
|
618
|
+
# a dependency re-runs the effect when it changes, by design.
|
|
619
|
+
# Installed from npm's registry, not as upstream's hook repo: pre-commit
|
|
620
|
+
# installs a hook repo as `git+file://` its clone, and npm 11.12 refuses that
|
|
621
|
+
# (EALLOWGIT), so the hook could not install and every commit failed, on any
|
|
622
|
+
# file. The version lives in `additional_dependencies`; bump it there.
|
|
623
|
+
- repo: local
|
|
624
|
+
hooks:
|
|
625
|
+
- id: biome-check
|
|
626
|
+
name: biome-check
|
|
627
|
+
language: node
|
|
628
|
+
additional_dependencies: ["@biomejs/biome@2.6.7"]
|
|
629
|
+
entry: biome check --write --files-ignore-unknown=true --no-errors-on-unmatched
|
|
630
|
+
types: [text]
|
|
631
|
+
require_serial: true
|
|
632
|
+
stages: [pre-commit]
|
|
633
|
+
files: \.(tsx?|[cm]ts|jsx?|[cm]js|css)$
|
|
634
|
+
args: [--reporter=concise]
|
|
635
|
+
|
|
636
|
+
# rustfmt rewrites in place, then clippy denies every warning, each once per
|
|
637
|
+
# crate a change touches: the nearest `Cargo.toml` above each file.
|
|
638
|
+
- repo: local
|
|
639
|
+
hooks:
|
|
640
|
+
- id: cargo-fmt
|
|
641
|
+
name: cargo-fmt
|
|
642
|
+
language: system
|
|
643
|
+
stages: [pre-commit]
|
|
644
|
+
require_serial: true
|
|
645
|
+
files: (\.rs|(^|/)Cargo\.toml)$
|
|
646
|
+
entry: uv --quiet run --frozen --group pre-commit python -m codedoctor cargo fmt
|
|
647
|
+
|
|
648
|
+
- id: cargo-clippy
|
|
649
|
+
name: cargo-clippy
|
|
650
|
+
language: system
|
|
651
|
+
stages: [pre-commit]
|
|
652
|
+
require_serial: true
|
|
653
|
+
files: (\.rs|(^|/)Cargo\.(toml|lock))$
|
|
654
|
+
entry: >-
|
|
655
|
+
nice -n 19 uv --quiet run --frozen --group pre-commit python -m codedoctor
|
|
656
|
+
cargo clippy
|
|
657
|
+
|
|
590
658
|
- repo: local
|
|
591
659
|
hooks:
|
|
592
660
|
# Each heavy hook below is a `-spool` twin, which collects pre-commit's
|
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
All notable codedoctor changes are documented here. This project follows
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
5
5
|
|
|
6
|
+
## 0.1.6 - 2026-11-18
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- `biome-check` hook formats and lints TypeScript, JavaScript and CSS;
|
|
11
|
+
`codedoctor install` writes a `biome.json` when the project has none.
|
|
12
|
+
- `codedoctor cargo` stage for Rust projects.
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- Update lint rules, mutation testing, typecheck, and affected-file selection.
|
|
17
|
+
|
|
6
18
|
## 0.1.5 - 2026-11-08
|
|
7
19
|
|
|
8
20
|
### Changed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: codedoctor
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.6
|
|
4
4
|
Summary: Pre-commit gates that run each heavy check once, sized to the machine.
|
|
5
5
|
Project-URL: Homepage, https://www.rekursiv.ai
|
|
6
6
|
Project-URL: Repository, https://github.com/rekursiv-ai/codedoctor
|
|
@@ -109,10 +109,12 @@ uses the project name for `userdirs-namespace.namespace`; set it explicitly in
|
|
|
109
109
|
`[tool.codedoctor.lint]` to choose another namespace. `xdg-literal.helper` is unset
|
|
110
110
|
unless the project requires a shared helper.
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
basedpyright;
|
|
112
|
+
The hooks come from the package's `install_hooks.yaml`. Commits autofix
|
|
113
|
+
whitespace, spelling, Codedoctor lint, Ruff formatting, Biome formatting of
|
|
114
|
+
TypeScript, JavaScript and CSS, and rustfmt; check types with ty, pyrefly, and
|
|
115
|
+
basedpyright; run clippy once per touched crate; and run paired tests, coverage
|
|
116
|
+
checks, and sampled mutation tests. A project without `biome.json` gets the
|
|
117
|
+
package's Biome settings; an existing one is left alone.
|
|
116
118
|
Pre-push checks are opt-in: install them with `pre-commit install --hook-type
|
|
117
119
|
pre-push` to run repository-wide type checks and all test tiers.
|
|
118
120
|
Dependency-graph setup precedes affected-file checks.
|
|
@@ -198,11 +200,12 @@ every gate and is the fullest example.
|
|
|
198
200
|
| `codedoctor testing` | paired tests and whole-suite tiers |
|
|
199
201
|
| `codedoctor coverage-floor` | per-source coverage from the pytest gate |
|
|
200
202
|
| `codedoctor mutation` | changed-function mutation tests (`codedoctor[mutation]`) |
|
|
201
|
-
| `codedoctor lint` | AST rules configured in `[tool.codedoctor.lint]` |
|
|
203
|
+
| `codedoctor lint` | AST rules configured in `[tool.codedoctor.lint]`; `--explain RULE` says why a rule exists; `--suppressions` counts the `house-ignore` markers for each rule |
|
|
202
204
|
| `codedoctor assert-isinstance` | redundant `assert isinstance` removal |
|
|
203
205
|
| `codedoctor affected` | files and tests reached through CodeGraph |
|
|
204
206
|
| `codedoctor nbstripout` | notebook output stripping |
|
|
205
207
|
| `codedoctor yamlcheck` | YAML validation, including Compose tags |
|
|
208
|
+
| `codedoctor cargo` | `cargo fmt` or `cargo clippy` once per touched crate |
|
|
206
209
|
| `codedoctor export-leaks` | exported-package leak checks |
|
|
207
210
|
| `codedoctor codegraph-sync` | dependency-graph refresh |
|
|
208
211
|
| `codedoctor check-pr-text` | pull-request text validation |
|
|
@@ -41,10 +41,12 @@ uses the project name for `userdirs-namespace.namespace`; set it explicitly in
|
|
|
41
41
|
`[tool.codedoctor.lint]` to choose another namespace. `xdg-literal.helper` is unset
|
|
42
42
|
unless the project requires a shared helper.
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
basedpyright;
|
|
44
|
+
The hooks come from the package's `install_hooks.yaml`. Commits autofix
|
|
45
|
+
whitespace, spelling, Codedoctor lint, Ruff formatting, Biome formatting of
|
|
46
|
+
TypeScript, JavaScript and CSS, and rustfmt; check types with ty, pyrefly, and
|
|
47
|
+
basedpyright; run clippy once per touched crate; and run paired tests, coverage
|
|
48
|
+
checks, and sampled mutation tests. A project without `biome.json` gets the
|
|
49
|
+
package's Biome settings; an existing one is left alone.
|
|
48
50
|
Pre-push checks are opt-in: install them with `pre-commit install --hook-type
|
|
49
51
|
pre-push` to run repository-wide type checks and all test tiers.
|
|
50
52
|
Dependency-graph setup precedes affected-file checks.
|
|
@@ -130,11 +132,12 @@ every gate and is the fullest example.
|
|
|
130
132
|
| `codedoctor testing` | paired tests and whole-suite tiers |
|
|
131
133
|
| `codedoctor coverage-floor` | per-source coverage from the pytest gate |
|
|
132
134
|
| `codedoctor mutation` | changed-function mutation tests (`codedoctor[mutation]`) |
|
|
133
|
-
| `codedoctor lint` | AST rules configured in `[tool.codedoctor.lint]` |
|
|
135
|
+
| `codedoctor lint` | AST rules configured in `[tool.codedoctor.lint]`; `--explain RULE` says why a rule exists; `--suppressions` counts the `house-ignore` markers for each rule |
|
|
134
136
|
| `codedoctor assert-isinstance` | redundant `assert isinstance` removal |
|
|
135
137
|
| `codedoctor affected` | files and tests reached through CodeGraph |
|
|
136
138
|
| `codedoctor nbstripout` | notebook output stripping |
|
|
137
139
|
| `codedoctor yamlcheck` | YAML validation, including Compose tags |
|
|
140
|
+
| `codedoctor cargo` | `cargo fmt` or `cargo clippy` once per touched crate |
|
|
138
141
|
| `codedoctor export-leaks` | exported-package leak checks |
|
|
139
142
|
| `codedoctor codegraph-sync` | dependency-graph refresh |
|
|
140
143
|
| `codedoctor check-pr-text` | pull-request text validation |
|
|
@@ -43,7 +43,7 @@ from codedoctor.lib.files import walk
|
|
|
43
43
|
from codedoctor.lib.worker_count import worker_count
|
|
44
44
|
|
|
45
45
|
|
|
46
|
-
_THIS: Final = Path(__file__).resolve()
|
|
46
|
+
_THIS: Final[Path] = Path(__file__).resolve()
|
|
47
47
|
_CWD: Final = _THIS.parent
|
|
48
48
|
|
|
49
49
|
if TYPE_CHECKING:
|
|
@@ -316,7 +316,7 @@ def _connect(database: Path) -> sqlite3.Connection | None:
|
|
|
316
316
|
# name there and took `mode=ro` with it. SQLite does not fail on that --
|
|
317
317
|
# it CREATES the truncated name, writable and empty, so the walk read a
|
|
318
318
|
# file that is not the index and left a stray one in the tree.
|
|
319
|
-
# pragma: no mutate start
|
|
319
|
+
# pragma: no mutate[truthiness] start
|
|
320
320
|
return sqlite3.connect(
|
|
321
321
|
f"file:{pathname2url(str(database))}?mode=ro",
|
|
322
322
|
uri=True,
|
|
@@ -537,7 +537,7 @@ def _globs(value: object, *, default: list[str]) -> list[str]:
|
|
|
537
537
|
# hand it a ``list[Unknown]`` and lose the element type the conversion
|
|
538
538
|
# establishes.
|
|
539
539
|
try:
|
|
540
|
-
words = from_plain(value, list[object], default=[])
|
|
540
|
+
words = from_plain(value, list[object], default=list[object]())
|
|
541
541
|
except ReadError:
|
|
542
542
|
return default
|
|
543
543
|
return [str(word) for word in words] or default
|
|
@@ -6,8 +6,7 @@ from concurrent.futures import ThreadPoolExecutor
|
|
|
6
6
|
from contextlib import closing
|
|
7
7
|
from pathlib import Path
|
|
8
8
|
from types import SimpleNamespace
|
|
9
|
-
from typing import TYPE_CHECKING, Final, cast
|
|
10
|
-
from unittest.mock import Mock
|
|
9
|
+
from typing import TYPE_CHECKING, Final, NoReturn, cast
|
|
11
10
|
|
|
12
11
|
import argparse
|
|
13
12
|
import os
|
|
@@ -28,7 +27,7 @@ if TYPE_CHECKING:
|
|
|
28
27
|
from collections.abc import Callable, Sequence
|
|
29
28
|
|
|
30
29
|
|
|
31
|
-
_CWD: Final = Path(__file__).resolve().parent
|
|
30
|
+
_CWD: Final[Path] = Path(__file__).resolve().parent
|
|
32
31
|
|
|
33
32
|
|
|
34
33
|
@pytest.fixture(autouse=True)
|
|
@@ -44,10 +43,14 @@ def in_tmp_path(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
|
44
43
|
"""
|
|
45
44
|
monkeypatch.chdir(tmp_path)
|
|
46
45
|
monkeypatch.setattr(codegraph, "executable", lambda: "codegraph")
|
|
46
|
+
|
|
47
|
+
def sync_worktree(*_args: object, **_kwargs: object) -> object:
|
|
48
|
+
return "index unavailable"
|
|
49
|
+
|
|
47
50
|
monkeypatch.setattr(
|
|
48
51
|
backbone,
|
|
49
52
|
"sync_worktree",
|
|
50
|
-
|
|
53
|
+
sync_worktree,
|
|
51
54
|
)
|
|
52
55
|
|
|
53
56
|
|
|
@@ -1244,12 +1247,12 @@ def test_the_command_line_never_runs_a_subprocess(
|
|
|
1244
1247
|
"""Changed lines and the file universe come from the caller and the tree, not git."""
|
|
1245
1248
|
database = _index(tmp_path)
|
|
1246
1249
|
_tree(tmp_path)
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
)
|
|
1250
|
+
|
|
1251
|
+
def spawned(*args: object, **kwargs: object) -> NoReturn:
|
|
1252
|
+
raise AssertionError(f"spawned: {args} {kwargs}")
|
|
1253
|
+
|
|
1254
|
+
monkeypatch.setattr(subprocess, "run", spawned)
|
|
1255
|
+
monkeypatch.setattr(subprocess, "Popen", spawned)
|
|
1253
1256
|
monkeypatch.setattr(
|
|
1254
1257
|
sys,
|
|
1255
1258
|
"argv",
|
|
@@ -2195,7 +2198,12 @@ def test_a_missing_cli_selects_without_indexing_or_diagnostics(
|
|
|
2195
2198
|
(tmp_path / "lib_test.py").touch()
|
|
2196
2199
|
monkeypatch.delenv("SKIP", raising=False)
|
|
2197
2200
|
monkeypatch.setattr(codegraph, "executable", lambda: None)
|
|
2198
|
-
|
|
2201
|
+
synced: list[object] = []
|
|
2202
|
+
|
|
2203
|
+
def sync(*args: object, **kwargs: object) -> NoReturn:
|
|
2204
|
+
synced.append((args, kwargs))
|
|
2205
|
+
raise AssertionError("missing CodeGraph was invoked")
|
|
2206
|
+
|
|
2199
2207
|
monkeypatch.setattr(backbone, "sync_worktree", sync)
|
|
2200
2208
|
monkeypatch.setattr(
|
|
2201
2209
|
sys,
|
|
@@ -2206,7 +2214,7 @@ def test_a_missing_cli_selects_without_indexing_or_diagnostics(
|
|
|
2206
2214
|
assert affected.main() == 0
|
|
2207
2215
|
expected = "lib.py\n" if emit == "files" else "lib_test.py\n"
|
|
2208
2216
|
assert capsys.readouterr() == (expected, "")
|
|
2209
|
-
|
|
2217
|
+
assert synced == []
|
|
2210
2218
|
|
|
2211
2219
|
|
|
2212
2220
|
def test_a_missing_index_cli_exits_127_like_a_shell(
|
{codedoctor-0.1.5 → codedoctor-0.1.6}/codedoctor/assert_isinstance/unnecessary_assert_isinstance.py
RENAMED
|
@@ -17,9 +17,10 @@ is redundant.
|
|
|
17
17
|
|
|
18
18
|
An assert the checker calls unnecessary may still narrow for another gate
|
|
19
19
|
checker, so it is only unnecessary when ty and each ``--typechecker`` other
|
|
20
|
-
than ``--checker`` (default: pyrefly
|
|
21
|
-
candidate replaced by ``pass``, report
|
|
22
|
-
|
|
20
|
+
than ``--checker`` (default: pyrefly and basedpyright, every checker the gate
|
|
21
|
+
runs), run once over copies with every candidate replaced by ``pass``, report
|
|
22
|
+
nothing new on those files. Those runs happen only when the checker flagged
|
|
23
|
+
something, and a crash fails the run.
|
|
23
24
|
|
|
24
25
|
Findings follow checker's contract: each is rule ``unnecessary-assert-isinstance``,
|
|
25
26
|
a ``house-ignore`` marker naming it suppresses it (and is reported once it
|
|
@@ -172,7 +173,7 @@ def project_root(start: Path, *, tool: str) -> Path:
|
|
|
172
173
|
if path.is_file() and tool in from_plain(
|
|
173
174
|
tomllib.loads(path.read_text()).get("tool"),
|
|
174
175
|
dict[str, object],
|
|
175
|
-
default=
|
|
176
|
+
default=dict[str, object](),
|
|
176
177
|
):
|
|
177
178
|
return directory
|
|
178
179
|
return start
|
|
@@ -310,8 +311,16 @@ def diagnostics(report: str, *, overlay: Path, root: Path) -> list[Diagnostic]:
|
|
|
310
311
|
else checked
|
|
311
312
|
)
|
|
312
313
|
# A file-level finding (an import cycle) carries no ``range``.
|
|
313
|
-
where = from_plain(
|
|
314
|
-
|
|
314
|
+
where = from_plain(
|
|
315
|
+
item.get("range"),
|
|
316
|
+
dict[str, object],
|
|
317
|
+
default=dict[str, object](),
|
|
318
|
+
)
|
|
319
|
+
start = from_plain(
|
|
320
|
+
where.get("start"),
|
|
321
|
+
dict[str, object],
|
|
322
|
+
default=dict[str, object](),
|
|
323
|
+
)
|
|
315
324
|
line = from_plain(start.get("line"), int, default=0) + 1
|
|
316
325
|
column = from_plain(start.get("character"), int, default=0)
|
|
317
326
|
rule = from_plain(item.get("rule"), str, default="")
|
|
@@ -445,7 +454,7 @@ def still_needed(
|
|
|
445
454
|
match = _ASSERT.fullmatch(source[line - 1])
|
|
446
455
|
if match is None:
|
|
447
456
|
raise ValueError(
|
|
448
|
-
"Expected match is not None.", # pragma: no mutate
|
|
457
|
+
"Expected match is not None.", # pragma: no mutate[diagnostic-text]
|
|
449
458
|
)
|
|
450
459
|
source[line - 1] = f"{match['indent']}pass"
|
|
451
460
|
target.write_text("\n".join(source))
|
|
@@ -625,9 +634,9 @@ def _add_arguments(parser: argparse.ArgumentParser) -> None:
|
|
|
625
634
|
"--typechecker",
|
|
626
635
|
nargs="+",
|
|
627
636
|
choices=["pyrefly", "basedpyright"],
|
|
628
|
-
default=["pyrefly"],
|
|
637
|
+
default=["pyrefly", "basedpyright"],
|
|
629
638
|
help="Checkers that, with ty, must agree an assert is unnecessary "
|
|
630
|
-
"(default: %(default)s).",
|
|
639
|
+
"(default: every gated one, %(default)s).",
|
|
631
640
|
)
|
|
632
641
|
parser.add_argument(
|
|
633
642
|
"paths",
|
|
@@ -684,8 +693,16 @@ def _diagnostic_keys(
|
|
|
684
693
|
list[dict[str, object]],
|
|
685
694
|
)
|
|
686
695
|
for item in items:
|
|
687
|
-
where = from_plain(
|
|
688
|
-
|
|
696
|
+
where = from_plain(
|
|
697
|
+
item.get("range"),
|
|
698
|
+
dict[str, object],
|
|
699
|
+
default=dict[str, object](),
|
|
700
|
+
)
|
|
701
|
+
start = from_plain(
|
|
702
|
+
where.get("start"),
|
|
703
|
+
dict[str, object],
|
|
704
|
+
default=dict[str, object](),
|
|
705
|
+
)
|
|
689
706
|
line = from_plain(start.get("line"), int, default=0)
|
|
690
707
|
column = from_plain(start.get("character"), int, default=0)
|
|
691
708
|
rule = from_plain(item.get("rule"), str, default="")
|
|
@@ -1035,7 +1035,7 @@ def test_the_defaults_check_loop_and_leave_sizing_to_the_run(
|
|
|
1035
1035
|
"fix": fix,
|
|
1036
1036
|
"threads": threads,
|
|
1037
1037
|
"checker": "pyrefly",
|
|
1038
|
-
"typechecker": ["pyrefly"],
|
|
1038
|
+
"typechecker": ["pyrefly", "basedpyright"],
|
|
1039
1039
|
"paths": [],
|
|
1040
1040
|
}
|
|
1041
1041
|
|
|
@@ -1196,7 +1196,17 @@ def test_pyrefly_flags_only_the_redundant_assert(
|
|
|
1196
1196
|
source = _PYREFLY_REDUNDANT
|
|
1197
1197
|
_pyrefly_project(tmp_path, monkeypatch, source)
|
|
1198
1198
|
_replay_clean_ty(monkeypatch)
|
|
1199
|
-
|
|
1199
|
+
# Pyrefly's verdict is the subject; the other checkers have tests of their own.
|
|
1200
|
+
argv = [
|
|
1201
|
+
"check.py",
|
|
1202
|
+
"--threads",
|
|
1203
|
+
"1",
|
|
1204
|
+
"--typechecker",
|
|
1205
|
+
"pyrefly",
|
|
1206
|
+
*(["--fix"] * fix),
|
|
1207
|
+
"--",
|
|
1208
|
+
"m.py",
|
|
1209
|
+
]
|
|
1200
1210
|
monkeypatch.setattr(sys, "argv", argv)
|
|
1201
1211
|
|
|
1202
1212
|
assert unnecessary_assert_isinstance.main() == 1
|
|
@@ -1308,14 +1318,15 @@ def shared_pyrefly(
|
|
|
1308
1318
|
@pytest.mark.parametrize(
|
|
1309
1319
|
("typechecker", "kept"),
|
|
1310
1320
|
[
|
|
1311
|
-
([], False),
|
|
1321
|
+
(["--typechecker", "pyrefly"], False),
|
|
1322
|
+
pytest.param([], True, marks=pytest.mark.cli_node),
|
|
1312
1323
|
pytest.param(
|
|
1313
1324
|
["--typechecker", "basedpyright"],
|
|
1314
1325
|
True,
|
|
1315
1326
|
marks=pytest.mark.cli_node,
|
|
1316
1327
|
),
|
|
1317
1328
|
],
|
|
1318
|
-
ids=["default", "typechecker-basedpyright"],
|
|
1329
|
+
ids=["pyrefly-alone", "default", "typechecker-basedpyright"],
|
|
1319
1330
|
)
|
|
1320
1331
|
def test_typechecker_basedpyright_keeps_an_assert_it_still_narrows(
|
|
1321
1332
|
tmp_path: Path,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Run rustfmt and clippy over the crates a change touches."""
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# ruff: noqa: EXE003, D300, D205 -- Polyglot shell/Python script.
|
|
3
|
+
# fmt: off
|
|
4
|
+
'''' 2>/dev/null #
|
|
5
|
+
exec uv --quiet --project "$(dirname "$0")" run --frozen --no-sync python3 -P "$0" "$@"
|
|
6
|
+
Executable entry point. Dispatches to the cargo hook's ``main``.
|
|
7
|
+
'''
|
|
8
|
+
# fmt: on
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from codedoctor.cargo.cargo import main
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
if __name__ == "__main__":
|
|
16
|
+
raise SystemExit(main())
|
|
17
|
+
# vim: ft=python
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""Run a cargo command once per crate the supplied files belong to."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import TYPE_CHECKING, Protocol, cast
|
|
7
|
+
|
|
8
|
+
import argparse
|
|
9
|
+
import shutil
|
|
10
|
+
import subprocess
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
if TYPE_CHECKING:
|
|
14
|
+
from collections.abc import Sequence
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def main() -> int:
|
|
18
|
+
"""Run the cargo command once for each crate the supplied files belong to.
|
|
19
|
+
|
|
20
|
+
Returns:
|
|
21
|
+
exit_code: The first nonzero cargo status, or zero when every crate passed.
|
|
22
|
+
|
|
23
|
+
"""
|
|
24
|
+
parser = argparse.ArgumentParser(description=(__doc__ or "").strip())
|
|
25
|
+
_add_arguments(parser)
|
|
26
|
+
flags = cast(Flags, parser.parse_args())
|
|
27
|
+
command, *options = {
|
|
28
|
+
"fmt": ["fmt"],
|
|
29
|
+
"clippy": ["clippy", "--all-targets", "--locked", "--", "-D", "warnings"],
|
|
30
|
+
}[flags.command]
|
|
31
|
+
result = 0
|
|
32
|
+
for manifest in manifests(flags.files):
|
|
33
|
+
completed = subprocess.run( # noqa: S603 -- Fixed cargo arguments.
|
|
34
|
+
[
|
|
35
|
+
shutil.which("cargo") or "cargo",
|
|
36
|
+
command,
|
|
37
|
+
"--manifest-path",
|
|
38
|
+
str(manifest),
|
|
39
|
+
*options,
|
|
40
|
+
],
|
|
41
|
+
check=False,
|
|
42
|
+
)
|
|
43
|
+
result = result or completed.returncode
|
|
44
|
+
return result
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class Flags(Protocol):
|
|
48
|
+
"""Cargo command and the files pre-commit supplied."""
|
|
49
|
+
|
|
50
|
+
command: str
|
|
51
|
+
files: list[Path]
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def manifests(paths: Sequence[Path]) -> list[Path]:
|
|
55
|
+
"""Return the nearest ``Cargo.toml`` above each path, each once, in path order.
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
paths: Files relative to the repository root, as pre-commit supplies them.
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
manifests: One manifest per crate; files outside every crate add none.
|
|
62
|
+
|
|
63
|
+
"""
|
|
64
|
+
found: list[Path] = []
|
|
65
|
+
for path in paths:
|
|
66
|
+
manifest = next(
|
|
67
|
+
(
|
|
68
|
+
folder / "Cargo.toml"
|
|
69
|
+
for folder in path.parents
|
|
70
|
+
if (folder / "Cargo.toml").is_file()
|
|
71
|
+
),
|
|
72
|
+
None,
|
|
73
|
+
)
|
|
74
|
+
if manifest is not None and manifest not in found:
|
|
75
|
+
found.append(manifest)
|
|
76
|
+
return found
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _add_arguments(parser: argparse.ArgumentParser) -> None:
|
|
80
|
+
parser.add_argument("command", choices=["fmt", "clippy"])
|
|
81
|
+
parser.add_argument("files", type=Path, nargs="*")
|