diff --git a/detect_secrets/core/secrets_collection.py b/detect_secrets/core/secrets_collection.py index 30e14040a..a0a4bce4a 100644 --- a/detect_secrets/core/secrets_collection.py +++ b/detect_secrets/core/secrets_collection.py @@ -214,7 +214,14 @@ def __iter__(self) -> Generator[Tuple[str, PotentialSecret], None, None]: secrets = self[filename] # NOTE: If line numbers aren't supplied, they are supposed to default to 0. - for secret in sorted(secrets, key=lambda x: (x.get(line_number, 0), x.secret_hash, x.type)): + for secret in sorted( + secrets, + key=lambda secret: ( + getattr(secret, 'line_number', 0), + secret.secret_hash, + secret.type + ) + ): yield filename, secret def __bool__(self) -> bool: