Skip to content

Commit

Permalink
feat: Ensure that filters is not empty
Browse files Browse the repository at this point in the history
  • Loading branch information
trallnag committed Jan 1, 2025
1 parent ef3c680 commit f63a5e9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0).

## Unreleased

Nothing.
### Added

- Ensure that at least one filter is provided to script (in any mode).

## [1.0.0](https://github.com/trallnag/filter-pre-commit-hooks/compare/6014a859fec1b8842ea1dc573e096609e61ceecd...v1.0.0) / 2025-01-01

Expand Down
9 changes: 9 additions & 0 deletions src/filter_pre_commit_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import re
from argparse import ArgumentParser, BooleanOptionalAction
from pathlib import Path
from typing import Literal

VERSION = "1.0.0"

Expand Down Expand Up @@ -89,6 +90,14 @@
if __name__ == "__main__":
args = parser.parse_args()

config: Path = args.config
fail_unknown: bool = args.fail_unknown
mode: Literal["id", "tag"] = args.mode
filters: list[str] = args.filters

if not filters:
parser.error("No filters provided.")

with open(args.config) as pre_commit_config:
pre_commit_config_content: str = pre_commit_config.read()

Expand Down
10 changes: 10 additions & 0 deletions tests/test_filter_pre_commit_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ def test_get_version() -> None:
assert result.returncode == 0


def test_filter_empty() -> None:
"""
Tests that the script errors when no filters are provided.
"""

result = run_with()
assert result.returncode != 0
assert "No filters provided." in result.stderr


def test_unknown_fail_default() -> None:
"""
Tests that the script by default fails when an unknown hook is specified to
Expand Down

0 comments on commit f63a5e9

Please sign in to comment.