Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #472 #476

Merged
merged 2 commits into from
Aug 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions detect_secrets/core/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def scan_file(filename: str) -> Generator[PotentialSecret, None, None]:
has_secret = False
for lines in _get_lines_from_file(filename):
for secret in _process_line_based_plugins(
lines=list(enumerate(lines, 1)),
lines=list(enumerate(lines, start=1)),
filename=filename,
):
has_secret = True
Expand Down Expand Up @@ -197,7 +197,7 @@ def scan_for_allowlisted_secrets_in_file(filename: str) -> Generator[PotentialSe
# know which lines we want to scan.
try:
for lines in _get_lines_from_file(filename):
yield from _scan_for_allowlisted_secrets_in_lines(enumerate(lines, 1), filename)
yield from _scan_for_allowlisted_secrets_in_lines(enumerate(lines, start=1), filename)
break
except IOError:
log.warning(f'Unable to open file: {filename}')
Expand Down
11 changes: 9 additions & 2 deletions detect_secrets/core/secrets_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def trim(
]

if not filelist:
fileset = set([])
fileset = set()
else:
fileset = set(filelist)

Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion detect_secrets/plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def analyze_line(
**kwargs: Any
) -> Set[PotentialSecret]:
"""This examines a line and finds all possible secret values in it."""
output = set([])
output = set()
for match in self.analyze_string(line, **kwargs): # type: ignore
output.add(
PotentialSecret(
Expand Down
2 changes: 1 addition & 1 deletion detect_secrets/util/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_tracked_files(root: str) -> Set[str]:

:raises: CalledProcessError
"""
output = set([])
output = set()
try:
files = subprocess.check_output(
['git', '-C', root, 'ls-files'],
Expand Down