Use asottile/add-trailing-comma
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index f39150b..9467acf 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -23,6 +23,10 @@
- id: reorder-python-imports
language_version: python2.7
- repo: https://github.com/asottile/pyupgrade
- sha: v1.0.0
+ sha: v1.1.2
hooks:
- id: pyupgrade
+- repo: https://github.com/asottile/add-trailing-comma
+ sha: v0.3.0
+ hooks:
+ - id: add-trailing-comma
diff --git a/pre_commit_hooks/check_added_large_files.py b/pre_commit_hooks/check_added_large_files.py
index 8d5f4c4..193b910 100644
--- a/pre_commit_hooks/check_added_large_files.py
+++ b/pre_commit_hooks/check_added_large_files.py
@@ -51,7 +51,7 @@
parser = argparse.ArgumentParser()
parser.add_argument(
'filenames', nargs='*',
- help='Filenames pre-commit believes are changed.'
+ help='Filenames pre-commit believes are changed.',
)
parser.add_argument(
'--maxkb', type=int, default=500,
diff --git a/pre_commit_hooks/check_ast.py b/pre_commit_hooks/check_ast.py
index 9809a3f..1090300 100644
--- a/pre_commit_hooks/check_ast.py
+++ b/pre_commit_hooks/check_ast.py
@@ -26,7 +26,7 @@
sys.version.partition(' ')[0],
))
print('\n{}'.format(
- ' ' + traceback.format_exc().replace('\n', '\n ')
+ ' ' + traceback.format_exc().replace('\n', '\n '),
))
retval = 1
return retval
diff --git a/pre_commit_hooks/check_case_conflict.py b/pre_commit_hooks/check_case_conflict.py
index 3d6cf74..0f78296 100644
--- a/pre_commit_hooks/check_case_conflict.py
+++ b/pre_commit_hooks/check_case_conflict.py
@@ -45,7 +45,7 @@
parser = argparse.ArgumentParser()
parser.add_argument(
'filenames', nargs='*',
- help='Filenames pre-commit believes are changed.'
+ help='Filenames pre-commit believes are changed.',
)
args = parser.parse_args(argv)
diff --git a/pre_commit_hooks/check_docstring_first.py b/pre_commit_hooks/check_docstring_first.py
index 8e658a1..f2f5b72 100644
--- a/pre_commit_hooks/check_docstring_first.py
+++ b/pre_commit_hooks/check_docstring_first.py
@@ -1,4 +1,5 @@
from __future__ import absolute_import
+from __future__ import print_function
from __future__ import unicode_literals
import argparse
@@ -30,7 +31,7 @@
'{}:{} Multiple module docstrings '
'(first docstring on line {}).'.format(
filename, sline, found_docstring_line,
- )
+ ),
)
return 1
elif found_code_line is not None:
@@ -38,7 +39,7 @@
'{}:{} Module docstring appears after code '
'(code seen on line {}).'.format(
filename, sline, found_code_line,
- )
+ ),
)
return 1
else:
diff --git a/pre_commit_hooks/check_merge_conflict.py b/pre_commit_hooks/check_merge_conflict.py
index 7d87efc..5035b6d 100644
--- a/pre_commit_hooks/check_merge_conflict.py
+++ b/pre_commit_hooks/check_merge_conflict.py
@@ -7,7 +7,7 @@
b'<<<<<<< ',
b'======= ',
b'=======\n',
- b'>>>>>>> '
+ b'>>>>>>> ',
]
WARNING_MSG = 'Merge conflict string "{0}" found in {1}:{2}'
diff --git a/pre_commit_hooks/debug_statement_hook.py b/pre_commit_hooks/debug_statement_hook.py
index 902198f..d76e6e6 100644
--- a/pre_commit_hooks/debug_statement_hook.py
+++ b/pre_commit_hooks/debug_statement_hook.py
@@ -29,7 +29,7 @@
def visit_ImportFrom(self, node):
if node.module in DEBUG_STATEMENTS:
self.debug_import_statements.append(
- DebugStatement(node.module, node.lineno, node.col_offset)
+ DebugStatement(node.module, node.lineno, node.col_offset),
)
@@ -52,7 +52,7 @@
debug_statement.line,
debug_statement.col,
debug_statement.name,
- )
+ ),
)
return 1
else:
diff --git a/pre_commit_hooks/detect_aws_credentials.py b/pre_commit_hooks/detect_aws_credentials.py
index 42758f0..b2afd71 100644
--- a/pre_commit_hooks/detect_aws_credentials.py
+++ b/pre_commit_hooks/detect_aws_credentials.py
@@ -12,7 +12,7 @@
files = set()
for env_var in (
'AWS_CONFIG_FILE', 'AWS_CREDENTIAL_FILE', 'AWS_SHARED_CREDENTIALS_FILE',
- 'BOTO_CONFIG'
+ 'BOTO_CONFIG',
):
if env_var in os.environ:
files.add(os.environ[env_var])
@@ -23,7 +23,7 @@
"""Extract AWS secrets from environment variables."""
keys = set()
for env_var in (
- 'AWS_SECRET_ACCESS_KEY', 'AWS_SECURITY_TOKEN', 'AWS_SESSION_TOKEN'
+ 'AWS_SECRET_ACCESS_KEY', 'AWS_SECURITY_TOKEN', 'AWS_SESSION_TOKEN',
):
if env_var in os.environ:
keys.add(os.environ[env_var])
@@ -50,7 +50,7 @@
for section in parser.sections():
for var in (
'aws_secret_access_key', 'aws_security_token',
- 'aws_session_token'
+ 'aws_session_token',
):
try:
keys.add(parser.get(section, var))
@@ -93,13 +93,13 @@
help=(
'Location of additional AWS credential files from which to get '
'secret keys from'
- )
+ ),
)
parser.add_argument(
'--allow-missing-credentials',
dest='allow_missing_credentials',
action='store_true',
- help='Allow hook to pass when no credentials are detected.'
+ help='Allow hook to pass when no credentials are detected.',
)
args = parser.parse_args(argv)
@@ -124,7 +124,7 @@
print(
'No AWS keys were found in the configured credential files and '
'environment variables.\nPlease ensure you have the correct '
- 'setting for --credentials-file'
+ 'setting for --credentials-file',
)
return 2
diff --git a/pre_commit_hooks/pretty_format_json.py b/pre_commit_hooks/pretty_format_json.py
index 5e04230..bb7a3d0 100644
--- a/pre_commit_hooks/pretty_format_json.py
+++ b/pre_commit_hooks/pretty_format_json.py
@@ -120,7 +120,7 @@
except simplejson.JSONDecodeError:
print(
"Input File {} is not a valid JSON, consider using check-json"
- .format(json_file)
+ .format(json_file),
)
return 1
diff --git a/pre_commit_hooks/tests_should_end_in_test.py b/pre_commit_hooks/tests_should_end_in_test.py
index 5f9bbac..9bea20d 100644
--- a/pre_commit_hooks/tests_should_end_in_test.py
+++ b/pre_commit_hooks/tests_should_end_in_test.py
@@ -11,7 +11,7 @@
parser.add_argument('filenames', nargs='*')
parser.add_argument(
'--django', default=False, action='store_true',
- help='Use Django-style test naming pattern (test*.py)'
+ help='Use Django-style test naming pattern (test*.py)',
)
args = parser.parse_args(argv)
@@ -27,8 +27,8 @@
retcode = 1
print(
'{} does not match pattern "{}"'.format(
- filename, test_name_pattern
- )
+ filename, test_name_pattern,
+ ),
)
return retcode
diff --git a/pre_commit_hooks/trailing_whitespace_fixer.py b/pre_commit_hooks/trailing_whitespace_fixer.py
index 1ae15a9..d44750d 100644
--- a/pre_commit_hooks/trailing_whitespace_fixer.py
+++ b/pre_commit_hooks/trailing_whitespace_fixer.py
@@ -36,7 +36,7 @@
const=[],
default=argparse.SUPPRESS,
dest='markdown_linebreak_ext',
- help='Do not preserve linebreak spaces in Markdown'
+ help='Do not preserve linebreak spaces in Markdown',
)
parser.add_argument(
'--markdown-linebreak-ext',
@@ -45,7 +45,7 @@
default=['md,markdown'],
metavar='*|EXT[,EXT,...]',
nargs='?',
- help='Markdown extensions (or *) for linebreak spaces'
+ help='Markdown extensions (or *) for linebreak spaces',
)
parser.add_argument('filenames', nargs='*', help='Filenames to fix')
args = parser.parse_args(argv)
@@ -69,7 +69,7 @@
parser.error(
"bad --markdown-linebreak-ext extension '{}' (has . / \\ :)\n"
" (probably filename; use '--markdown-linebreak-ext=EXT')"
- .format(ext)
+ .format(ext),
)
return_code = 0
diff --git a/tests/check_docstring_first_test.py b/tests/check_docstring_first_test.py
index f14880b..aa9898d 100644
--- a/tests/check_docstring_first_test.py
+++ b/tests/check_docstring_first_test.py
@@ -19,7 +19,7 @@
'"foo"\n',
1,
'{filename}:2 Module docstring appears after code '
- '(code seen on line 1).\n'
+ '(code seen on line 1).\n',
),
# Test double docstring
(
@@ -28,7 +28,7 @@
'"fake docstring"\n',
1,
'{filename}:3 Multiple module docstrings '
- '(first docstring on line 1).\n'
+ '(first docstring on line 1).\n',
),
# Test multiple lines of code above
(
diff --git a/tests/check_merge_conflict_test.py b/tests/check_merge_conflict_test.py
index 5a2e82a..a999aca 100644
--- a/tests/check_merge_conflict_test.py
+++ b/tests/check_merge_conflict_test.py
@@ -45,7 +45,7 @@
'child\n'
'=======\n'
'parent\n'
- '>>>>>>>'
+ '>>>>>>>',
) or f1.startswith(
'<<<<<<< HEAD\n'
'child\n'
@@ -53,7 +53,7 @@
'||||||| merged common ancestors\n'
'=======\n'
'parent\n'
- '>>>>>>>'
+ '>>>>>>>',
) or f1.startswith(
# .gitconfig with [pull] rebase = preserve causes a rebase which
# flips parent / child
@@ -61,7 +61,7 @@
'parent\n'
'=======\n'
'child\n'
- '>>>>>>>'
+ '>>>>>>>',
)
assert os.path.exists(os.path.join('.git', 'MERGE_MSG'))
yield
diff --git a/tests/debug_statement_hook_test.py b/tests/debug_statement_hook_test.py
index c318346..7891eac 100644
--- a/tests/debug_statement_hook_test.py
+++ b/tests/debug_statement_hook_test.py
@@ -46,7 +46,7 @@
visitor = ImportStatementParser()
visitor.visit(ast_with_debug_import_form_1)
assert visitor.debug_import_statements == [
- DebugStatement('ipdb', 3, 0)
+ DebugStatement('ipdb', 3, 0),
]
@@ -54,7 +54,7 @@
visitor = ImportStatementParser()
visitor.visit(ast_with_debug_import_form_2)
assert visitor.debug_import_statements == [
- DebugStatement('pudb', 3, 0)
+ DebugStatement('pudb', 3, 0),
]
diff --git a/tests/detect_aws_credentials_test.py b/tests/detect_aws_credentials_test.py
index 943a3f8..beb382f 100644
--- a/tests/detect_aws_credentials_test.py
+++ b/tests/detect_aws_credentials_test.py
@@ -21,14 +21,14 @@
(
{
'AWS_DUMMY_KEY': '/foo', 'AWS_CONFIG_FILE': '/bar',
- 'AWS_CREDENTIAL_FILE': '/baz'
+ 'AWS_CREDENTIAL_FILE': '/baz',
},
{'/bar', '/baz'}
),
(
{
'AWS_CONFIG_FILE': '/foo', 'AWS_CREDENTIAL_FILE': '/bar',
- 'AWS_SHARED_CREDENTIALS_FILE': '/baz'
+ 'AWS_SHARED_CREDENTIALS_FILE': '/baz',
},
{'/foo', '/bar', '/baz'}
),
@@ -51,7 +51,7 @@
({'AWS_DUMMY_KEY': 'foo', 'AWS_SECRET_ACCESS_KEY': 'bar'}, {'bar'}),
(
{'AWS_SECRET_ACCESS_KEY': 'foo', 'AWS_SECURITY_TOKEN': 'bar'},
- {'foo', 'bar'}
+ {'foo', 'bar'},
),
),
)
@@ -66,7 +66,7 @@
(
(
'aws_config_with_secret.ini',
- {'z2rpgs5uit782eapz5l1z0y2lurtsyyk6hcfozlb'}
+ {'z2rpgs5uit782eapz5l1z0y2lurtsyyk6hcfozlb'},
),
('aws_config_with_session_token.ini', {'foo'}),
('aws_config_with_secret_and_session_token.ini',
@@ -77,8 +77,8 @@
'7xebzorgm5143ouge9gvepxb2z70bsb2rtrh099e',
'z2rpgs5uit782eapz5l1z0y2lurtsyyk6hcfozlb',
'ixswosj8gz3wuik405jl9k3vdajsnxfhnpui38ez',
- 'foo'
- }
+ 'foo',
+ },
),
('aws_config_without_secrets.ini', set()),
('nonsense.txt', set()),
@@ -121,7 +121,7 @@
mock_secrets_file.return_value = set()
ret = main((
get_resource_path('aws_config_without_secrets.ini'),
- "--credentials-file=testing/resources/credentailsfilethatdoesntexist"
+ "--credentials-file=testing/resources/credentailsfilethatdoesntexist",
))
assert ret == 2
out, _ = capsys.readouterr()
@@ -141,6 +141,6 @@
ret = main((
get_resource_path('aws_config_without_secrets.ini'),
"--credentials-file=testing/resources/credentailsfilethatdoesntexist",
- "--allow-missing-credentials"
+ "--allow-missing-credentials",
))
assert ret == 0
diff --git a/tests/file_contents_sorter_test.py b/tests/file_contents_sorter_test.py
index 2c85c8a..1f9a14b 100644
--- a/tests/file_contents_sorter_test.py
+++ b/tests/file_contents_sorter_test.py
@@ -21,7 +21,7 @@
(b'@\n-\n_\n#\n', FAIL, b'#\n-\n@\n_\n'),
(b'extra\n\n\nwhitespace\n', FAIL, b'extra\nwhitespace\n'),
(b'whitespace\n\n\nextra\n', FAIL, b'extra\nwhitespace\n'),
- )
+ ),
)
def test_integration(input_s, expected_retval, output, tmpdir):
path = tmpdir.join('file.txt')
diff --git a/tests/fix_encoding_pragma_test.py b/tests/fix_encoding_pragma_test.py
index d49f1ba..7288bfa 100644
--- a/tests/fix_encoding_pragma_test.py
+++ b/tests/fix_encoding_pragma_test.py
@@ -56,7 +56,7 @@
b'# -*- coding: utf-8 -*-\n'
b'foo = "bar"\n'
),
- )
+ ),
)
def test_ok_inputs(input_str):
bytesio = io.BytesIO(input_str)
@@ -100,7 +100,7 @@
(b'#!/usr/bin/env python\n', b''),
(b'#!/usr/bin/env python\n#coding: utf8\n', b''),
(b'#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n', b''),
- )
+ ),
)
def test_not_ok_inputs(input_str, output):
bytesio = io.BytesIO(input_str)
diff --git a/tests/requirements_txt_fixer_test.py b/tests/requirements_txt_fixer_test.py
index 3681cc6..dcf7a76 100644
--- a/tests/requirements_txt_fixer_test.py
+++ b/tests/requirements_txt_fixer_test.py
@@ -24,9 +24,9 @@
(
b'-e git+ssh://git_url@tag#egg=ocflib\nDjango\nPyMySQL\n',
FAIL,
- b'Django\n-e git+ssh://git_url@tag#egg=ocflib\nPyMySQL\n'
+ b'Django\n-e git+ssh://git_url@tag#egg=ocflib\nPyMySQL\n',
),
- )
+ ),
)
def test_integration(input_s, expected_retval, output, tmpdir):
path = tmpdir.join('file.txt')
diff --git a/tests/trailing_whitespace_fixer_test.py b/tests/trailing_whitespace_fixer_test.py
index eb2a1d0..a771e67 100644
--- a/tests/trailing_whitespace_fixer_test.py
+++ b/tests/trailing_whitespace_fixer_test.py
@@ -69,7 +69,7 @@
path = tmpdir.join(filename)
path.write(input_s)
ret = fix_trailing_whitespace((
- '--markdown-linebreak-ext=TxT', path.strpath
+ '--markdown-linebreak-ext=TxT', path.strpath,
))
assert ret == 1
assert path.read() == output