Skip to content

Commit

Permalink
improved pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
domanchi committed Jun 18, 2019
1 parent 7b13a60 commit cd20d2f
Show file tree
Hide file tree
Showing 16 changed files with 151 additions and 149 deletions.
8 changes: 5 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.1.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-builtin-literals
args: ['--no-allow-dict-kwargs']
- id: check-docstring-first
- id: debug-statements
- id: double-quote-string-fixer
- id: end-of-file-fixer
- id: name-tests-test
exclude: tests/util
- id: flake8
args: ['--max-line-length', '100']
exclude: ^test_data/
- id: trailing-whitespace
- repo: https://github.com/asottile/reorder_python_imports
rev: v1.3.4
hooks:
Expand Down
4 changes: 2 additions & 2 deletions detect_secrets/core/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
class SecretNotFoundOnSpecifiedLineError(Exception):
def __init__(self, line):
super(SecretNotFoundOnSpecifiedLineError, self).__init__(
"ERROR: Secret not found on line {}!\n".format(line) +
"Try recreating your baseline to fix this issue.",
'ERROR: Secret not found on line {}!\n'.format(line) +
'Try recreating your baseline to fix this issue.',
)


Expand Down
4 changes: 2 additions & 2 deletions detect_secrets/core/baseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def initialize(
elif os.path.isfile(element):
files_to_scan.append(element)
else:
log.error("detect-secrets: " + element + ": No such file or directory")
log.error('detect-secrets: ' + element + ': No such file or directory')

if not files_to_scan:
return output
Expand Down Expand Up @@ -215,7 +215,7 @@ def merge_results(old_results, new_results):
if filename not in new_results:
continue

old_secrets_mapping = dict()
old_secrets_mapping = {}
for old_secret in old_secrets:
old_secrets_mapping[old_secret['hashed_secret']] = old_secret

Expand Down
4 changes: 2 additions & 2 deletions detect_secrets/core/potential_secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ def __hash__(self):

def __str__(self): # pragma: no cover
return (
"Secret Type: %s\n"
"Location: %s:%d\n"
'Secret Type: %s\n'
'Location: %s:%d\n'
) % (
self.type,
self.filename, self.lineno,
Expand Down
8 changes: 4 additions & 4 deletions detect_secrets/core/secrets_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def scan_file(self, filename, filename_key=None):

return True
except IOError:
log.warning("Unable to open file: %s", filename)
log.warning('Unable to open file: %s', filename)
return False

def get_secret(self, filename, secret, type_=None):
Expand Down Expand Up @@ -263,7 +263,7 @@ def format_for_baseline_output(self):
plugins_used = sorted(plugins_used, key=lambda x: x['name'])

return {
'generated_at': strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()),
'generated_at': strftime('%Y-%m-%dT%H:%M:%SZ', gmtime()),
'exclude': {
'files': self.exclude_files,
'lines': self.exclude_lines,
Expand Down Expand Up @@ -302,14 +302,14 @@ def _extract_secrets_from_file(self, f, filename):
:type filename: string
"""
try:
log.info("Checking file: %s", filename)
log.info('Checking file: %s', filename)

for results, plugin in self._results_accumulator(filename):
results.update(plugin.analyze(f, filename))
f.seek(0)

except UnicodeDecodeError:
log.warning("%s failed to load.", filename)
log.warning('%s failed to load.', filename)

def _extract_secrets_from_patch(self, f, plugin, filename):
"""Extract secrets from a given patch file object.
Expand Down
2 changes: 1 addition & 1 deletion detect_secrets/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def main(argv=None):

def _get_plugin_from_baseline(old_baseline):
plugins = []
if old_baseline and "plugins_used" in old_baseline:
if old_baseline and 'plugins_used' in old_baseline:
secrets_collection = SecretsCollection.load_baseline_from_dict(old_baseline)
plugins = secrets_collection.plugins
return plugins
Expand Down
4 changes: 2 additions & 2 deletions detect_secrets/plugins/common/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _remove_key(d, key):
return r

baseline_plugins_dict = {
vars(plugin)["name"]: _remove_key(vars(plugin), "name")
vars(plugin)['name']: _remove_key(vars(plugin), 'name')
for plugin in baseline_plugins
}

Expand Down Expand Up @@ -124,7 +124,7 @@ def _remove_key(d, key):
except KeyError:
log.warning(
'%s specified, but %s not configured! Ignoring...'
% ("".join(["--", param_name.replace("_", "-")]), plugin_name),
% (''.join(['--', param_name.replace('_', '-')]), plugin_name),
)

return from_parser_builder(
Expand Down
20 changes: 10 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
long_description=(
'Check out detect-secrets on `GitHub <https://github.com/Yelp/detect-secrets>`_!'
),
license="Copyright Yelp, Inc. 2018",
license='Copyright Yelp, Inc. 2018',
author='Aaron Loo',
author_email='[email protected]',
url='https://github.com/Yelp/detect-secrets',
Expand All @@ -36,14 +36,14 @@
],
},
classifiers=[
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"License :: OSI Approved :: Apache Software License",
"Intended Audience :: Developers",
"Topic :: Software Development",
"Topic :: Utilities",
"Environment :: Console",
"Operating System :: OS Independent",
"Development Status :: 5 - Production/Stable",
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
'License :: OSI Approved :: Apache Software License',
'Intended Audience :: Developers',
'Topic :: Software Development',
'Topic :: Utilities',
'Environment :: Console',
'Operating System :: OS Independent',
'Development Status :: 5 - Production/Stable',
],
)
2 changes: 1 addition & 1 deletion test_data/files/file_with_no_secrets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python
REGULAR_VALUE = "this is just a long string, like a user facing error message"
REGULAR_VALUE = 'this is just a long string, like a user facing error message'


def main():
Expand Down
2 changes: 1 addition & 1 deletion test_data/files/tmp/file_with_no_secrets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/python
# Will change this later.
SUPER_SECRET_VALUE = "this is just a long string, like a user facing error message"
SUPER_SECRET_VALUE = 'this is just a long string, like a user facing error message'


def main():
Expand Down
6 changes: 3 additions & 3 deletions tests/core/audit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,14 +692,14 @@ def test_unicode_in_output(self, mock_printer):
self.run_logic(
secret=potential_secret_factory(
type_='Base64 High Entropy String',
filename="test_data/config.md",
filename='test_data/config.md',
secret='ToCynx5Se4e2PtoZxEhW7lUJcOX15c54',
lineno=10,
).json(),
settings=[
{
"base64_limit": 4.5,
"name": "Base64HighEntropyString",
'base64_limit': 4.5,
'name': 'Base64HighEntropyString',
},
],
)
Expand Down
2 changes: 1 addition & 1 deletion tests/core/baseline_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def test_new_results_has_nothing(self):

def test_old_results_have_diff_type_will_carry_over(self):
secretA = self.get_secret()
secretA["type"] = "different type"
secretA['type'] = 'different type'
secretB = self.get_secret()

assert merge_results(
Expand Down
Loading

0 comments on commit cd20d2f

Please sign in to comment.