Repository navigation
fix: stop the help check at the -- end-of-options marker - #424
Merged
weibullguy merged 2 commits intoDec 3, 2026
Merged
Conversation
The -h / --help pre-check in _main scanned every command-line token, including the ones after "--". A path named -h passed after the marker printed the usage text and exited 0 without formatting or checking anything, so "docformatter --check --recursive -- -h" passed silently. Cut the token list at the first "--" before looking for the help flags.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #423
The help pre-check in
_main(src/docformatter/__main__.py) searched every command-line token for-hand--help, including the tokens after the--end-of-options marker. Tokens after--are file names, but a file or directory literally named-hgiven after--was treated as the help flag: the usage text was printed and the function returned 0 before any file was read.This change cuts the token list at the first
--before the help check runs.-hand--helpbefore--work as before.The case that matters is a recursive check (
--checkand--recursive) whose path after--is a directory named-hfull of Python files. Before this change that run printed the usage text and returned exit code 0, so the check reported nothing and exited 0.How it was tested:
test_help_flag_after_end_of_options_is_a_pathintests/test_docformatter.py, creates a directory named-hcontaining a file with a docstring that needs fixing, then runs the check with--before-h. It expects exit code 3. The new test passes with the fix and fails without it (exit code 0 instead of 3).uv run --no-sync python -m pytest -c pyproject.toml tests/: 819 passed, 3 skipped.srcanddocs/source, black --check and isort --check-only onsrcanddocs/source, docformatter --check onsrc/docformatter/__main__.py, and mypy onsrc/docformatter: all exited 0.tox -e pre-commit). The linters and formatters were run directly on the paths above rather than through pre-commit.