From 8626e266ddbf85ecdbd7f64d2950affd4f9ddd8b Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Mon, 11 Feb 2019 19:57:37 -0800 Subject: [PATCH] double-quote-string-fixer --- .pre-commit-config.yaml | 1 + pre_commit_hooks/fix_encoding_pragma.py | 2 +- pre_commit_hooks/sort_simple_yaml.py | 4 +-- pre_commit_hooks/trailing_whitespace_fixer.py | 2 +- tests/check_builtin_literals_test.py | 34 +++++++++---------- tests/detect_aws_credentials_test.py | 6 ++-- tests/pretty_format_json_test.py | 2 +- tests/sort_simple_yaml_test.py | 2 +- 8 files changed, 27 insertions(+), 26 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4990537..55c6f73 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,6 +10,7 @@ repos: - id: check-yaml - id: debug-statements - id: name-tests-test + - id: double-quote-string-fixer - id: requirements-txt-fixer - repo: https://gitlab.com/pycqa/flake8 rev: 3.7.1 diff --git a/pre_commit_hooks/fix_encoding_pragma.py b/pre_commit_hooks/fix_encoding_pragma.py index dbe9c6c..bde4e78 100644 --- a/pre_commit_hooks/fix_encoding_pragma.py +++ b/pre_commit_hooks/fix_encoding_pragma.py @@ -147,5 +147,5 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int return retv -if __name__ == "__main__": +if __name__ == '__main__': exit(main()) diff --git a/pre_commit_hooks/sort_simple_yaml.py b/pre_commit_hooks/sort_simple_yaml.py index 3c8ef16..a381679 100755 --- a/pre_commit_hooks/sort_simple_yaml.py +++ b/pre_commit_hooks/sort_simple_yaml.py @@ -115,9 +115,9 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int new_lines = sort(lines) if lines != new_lines: - print("Fixing file `{filename}`".format(filename=filename)) + print('Fixing file `{filename}`'.format(filename=filename)) f.seek(0) - f.write("\n".join(new_lines) + "\n") + f.write('\n'.join(new_lines) + '\n') f.truncate() retval = 1 diff --git a/pre_commit_hooks/trailing_whitespace_fixer.py b/pre_commit_hooks/trailing_whitespace_fixer.py index b2b6418..2ccc003 100644 --- a/pre_commit_hooks/trailing_whitespace_fixer.py +++ b/pre_commit_hooks/trailing_whitespace_fixer.py @@ -69,7 +69,7 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int for ext in md_exts: if any(c in ext[1:] for c in r'./\:'): parser.error( - "bad --markdown-linebreak-ext extension {!r} (has . / \\ :)\n" + 'bad --markdown-linebreak-ext extension {!r} (has . / \\ :)\n' " (probably filename; use '--markdown-linebreak-ext=EXT')" .format(ext), ) diff --git a/tests/check_builtin_literals_test.py b/tests/check_builtin_literals_test.py index dbb9cc4..19263b7 100644 --- a/tests/check_builtin_literals_test.py +++ b/tests/check_builtin_literals_test.py @@ -47,36 +47,36 @@ def visitor(): # see #285 ('x[0]()', []), # complex - ("0j", []), - ("complex()", [Call('complex', 1, 0)]), - ("complex(0, 0)", []), + ('0j', []), + ('complex()', [Call('complex', 1, 0)]), + ('complex(0, 0)', []), ("complex('0+0j')", []), ('builtins.complex()', []), # float - ("0.0", []), - ("float()", [Call('float', 1, 0)]), + ('0.0', []), + ('float()', [Call('float', 1, 0)]), ("float('0.0')", []), ('builtins.float()', []), # int - ("0", []), - ("int()", [Call('int', 1, 0)]), + ('0', []), + ('int()', [Call('int', 1, 0)]), ("int('0')", []), ('builtins.int()', []), # list - ("[]", []), - ("list()", [Call('list', 1, 0)]), + ('[]', []), + ('list()', [Call('list', 1, 0)]), ("list('abc')", []), ("list([c for c in 'abc'])", []), ("list(c for c in 'abc')", []), ('builtins.list()', []), # str ("''", []), - ("str()", [Call('str', 1, 0)]), + ('str()', [Call('str', 1, 0)]), ("str('0')", []), ('builtins.str()', []), # tuple - ("()", []), - ("tuple()", [Call('tuple', 1, 0)]), + ('()', []), + ('tuple()', [Call('tuple', 1, 0)]), ("tuple('abc')", []), ("tuple([c for c in 'abc'])", []), ("tuple(c for c in 'abc')", []), @@ -91,9 +91,9 @@ def test_non_dict_exprs(visitor, expression, calls): @pytest.mark.parametrize( ('expression', 'calls'), [ - ("{}", []), - ("dict()", [Call('dict', 1, 0)]), - ("dict(a=1, b=2, c=3)", []), + ('{}', []), + ('dict()', [Call('dict', 1, 0)]), + ('dict(a=1, b=2, c=3)', []), ("dict(**{'a': 1, 'b': 2, 'c': 3})", []), ("dict([(k, v) for k, v in [('a', 1), ('b', 2), ('c', 3)]])", []), ("dict((k, v) for k, v in [('a', 1), ('b', 2), ('c', 3)])", []), @@ -108,8 +108,8 @@ def test_dict_allow_kwargs_exprs(visitor, expression, calls): @pytest.mark.parametrize( ('expression', 'calls'), [ - ("dict()", [Call('dict', 1, 0)]), - ("dict(a=1, b=2, c=3)", [Call('dict', 1, 0)]), + ('dict()', [Call('dict', 1, 0)]), + ('dict(a=1, b=2, c=3)', [Call('dict', 1, 0)]), ("dict(**{'a': 1, 'b': 2, 'c': 3})", [Call('dict', 1, 0)]), ('builtins.dict()', []), ], diff --git a/tests/detect_aws_credentials_test.py b/tests/detect_aws_credentials_test.py index 31ba33e..777fb48 100644 --- a/tests/detect_aws_credentials_test.py +++ b/tests/detect_aws_credentials_test.py @@ -123,7 +123,7 @@ def test_non_existent_credentials(mock_secrets_env, mock_secrets_file, capsys): 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() @@ -143,7 +143,7 @@ def test_non_existent_credentials_with_allow_flag( mock_secrets_file.return_value = set() ret = main(( get_resource_path('aws_config_without_secrets.ini'), - "--credentials-file=testing/resources/credentailsfilethatdoesntexist", - "--allow-missing-credentials", + '--credentials-file=testing/resources/credentailsfilethatdoesntexist', + '--allow-missing-credentials', )) assert ret == 0 diff --git a/tests/pretty_format_json_test.py b/tests/pretty_format_json_test.py index bf7a16f..3b7b9a2 100644 --- a/tests/pretty_format_json_test.py +++ b/tests/pretty_format_json_test.py @@ -41,7 +41,7 @@ def test_unsorted_main(filename, expected_retval): assert ret == expected_retval -@pytest.mark.skipif(PY2, reason="Requires Python3") +@pytest.mark.skipif(PY2, reason='Requires Python3') @pytest.mark.parametrize( ('filename', 'expected_retval'), ( ('not_pretty_formatted_json.json', 1), diff --git a/tests/sort_simple_yaml_test.py b/tests/sort_simple_yaml_test.py index 72f5bec..4261d5d 100644 --- a/tests/sort_simple_yaml_test.py +++ b/tests/sort_simple_yaml_test.py @@ -45,7 +45,7 @@ def test_integration_good_bad_lines(tmpdir, bad_lines, good_lines, retval): file_path = os.path.join(tmpdir.strpath, 'foo.yaml') with open(file_path, 'w') as f: - f.write("\n".join(bad_lines) + "\n") + f.write('\n'.join(bad_lines) + '\n') assert main([file_path]) == retval