Skip to content

Commit

Permalink
Add length override to secrets collection to fix pretty output of pre…
Browse files Browse the repository at this point in the history
…-commit hook diagnostic total secrets
  • Loading branch information
jpdakran committed Dec 20, 2024
1 parent 5ed9de6 commit b0123c9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions detect_secrets/core/secrets_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ def __sub__(self, other: Any) -> 'SecretsCollection':

return output

def __len__(self) -> int:
"""Returns the total number of secrets in the collection."""
return sum(len(secrets) for secrets in self.data.values())


def _scan_file_and_serialize(filename: str) -> List[PotentialSecret]:
"""Used for multiprocessing, since lambdas can't be serialized."""
Expand Down
1 change: 1 addition & 0 deletions tests/pre_commit_hook_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def test_console_output():
# Assert formatting
output = capturedOutput.getvalue()
assert output.startswith('ERROR: Potential secrets about to be committed to git repo!')
assert 'Total secrets detected: 1' in output


def test_console_output_json_formatting():
Expand Down

0 comments on commit b0123c9

Please sign in to comment.