Repository navigation
Conversation
pre-commit passes each item in args as a single argument, so args: [--scopes api] reaches the hook as the one string "--scopes api". argparse can't match it to an option, so it took it as a commit type. The standard types were then added back and no scope rule was applied, so commits that should fail passed. The hook now fails with a message saying how to pass the option, and the README notes that each option and value go in separate items.
This branch has not been deployed
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 #129
Problem
pre-commit passes each item in
argsto the hook as one argument. With this config:the hook gets the single string
"--scopes api". argparse can't match it to an option, so it treats it as a commit type.--scopesis then never set, so the scope rule is silently skipped and a commit that should fail passes:The same thing happens for any option given with its value in one item (
--scopes api,--scopes a,b, etc.). Passing the CLI command throughentryworks, which is why the issue saw different results for the two configs.Change
conventional_pre_commit/hook.py: after parsing, if any parsed type starts with-, the hook fails with a message explaining how to pass the option:-, so this can't reject a config that works today.README.md: a note under the pre-commit usage section that an option and its value go in separateargsitems ([--scopes, api]) or are joined with=([--scopes=api]).Tests
Two tests added to
tests/test_hook.py:test_main_fail__option_and_value_in_one_arg:--scopes apias one argument fails and prints the message.test_main_success__option_and_value_with_equals:--scopes=scopestill works.Checks run locally:
tests/run.sh(pytest with coverage): 165 passedblack --checkandflake8: cleanbandit -ll(1.9.4, as pinned in.pre-commit-config.yaml): no issuesgit diff --check, LF line endings, and the commit message passes this repo's ownconventional-pre-commithook