mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-06 20:16:53 +00:00
double-quote-string-fixer
This commit is contained in:
parent
4575652bd2
commit
8626e266dd
8 changed files with 27 additions and 26 deletions
|
|
@ -10,6 +10,7 @@ repos:
|
||||||
- id: check-yaml
|
- id: check-yaml
|
||||||
- id: debug-statements
|
- id: debug-statements
|
||||||
- id: name-tests-test
|
- id: name-tests-test
|
||||||
|
- id: double-quote-string-fixer
|
||||||
- id: requirements-txt-fixer
|
- id: requirements-txt-fixer
|
||||||
- repo: https://gitlab.com/pycqa/flake8
|
- repo: https://gitlab.com/pycqa/flake8
|
||||||
rev: 3.7.1
|
rev: 3.7.1
|
||||||
|
|
|
||||||
|
|
@ -147,5 +147,5 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
|
||||||
return retv
|
return retv
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == '__main__':
|
||||||
exit(main())
|
exit(main())
|
||||||
|
|
|
||||||
|
|
@ -115,9 +115,9 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
|
||||||
new_lines = sort(lines)
|
new_lines = sort(lines)
|
||||||
|
|
||||||
if lines != new_lines:
|
if lines != new_lines:
|
||||||
print("Fixing file `{filename}`".format(filename=filename))
|
print('Fixing file `{filename}`'.format(filename=filename))
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
f.write("\n".join(new_lines) + "\n")
|
f.write('\n'.join(new_lines) + '\n')
|
||||||
f.truncate()
|
f.truncate()
|
||||||
retval = 1
|
retval = 1
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
|
||||||
for ext in md_exts:
|
for ext in md_exts:
|
||||||
if any(c in ext[1:] for c in r'./\:'):
|
if any(c in ext[1:] for c in r'./\:'):
|
||||||
parser.error(
|
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')"
|
" (probably filename; use '--markdown-linebreak-ext=EXT')"
|
||||||
.format(ext),
|
.format(ext),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -47,36 +47,36 @@ def visitor():
|
||||||
# see #285
|
# see #285
|
||||||
('x[0]()', []),
|
('x[0]()', []),
|
||||||
# complex
|
# complex
|
||||||
("0j", []),
|
('0j', []),
|
||||||
("complex()", [Call('complex', 1, 0)]),
|
('complex()', [Call('complex', 1, 0)]),
|
||||||
("complex(0, 0)", []),
|
('complex(0, 0)', []),
|
||||||
("complex('0+0j')", []),
|
("complex('0+0j')", []),
|
||||||
('builtins.complex()', []),
|
('builtins.complex()', []),
|
||||||
# float
|
# float
|
||||||
("0.0", []),
|
('0.0', []),
|
||||||
("float()", [Call('float', 1, 0)]),
|
('float()', [Call('float', 1, 0)]),
|
||||||
("float('0.0')", []),
|
("float('0.0')", []),
|
||||||
('builtins.float()', []),
|
('builtins.float()', []),
|
||||||
# int
|
# int
|
||||||
("0", []),
|
('0', []),
|
||||||
("int()", [Call('int', 1, 0)]),
|
('int()', [Call('int', 1, 0)]),
|
||||||
("int('0')", []),
|
("int('0')", []),
|
||||||
('builtins.int()', []),
|
('builtins.int()', []),
|
||||||
# list
|
# list
|
||||||
("[]", []),
|
('[]', []),
|
||||||
("list()", [Call('list', 1, 0)]),
|
('list()', [Call('list', 1, 0)]),
|
||||||
("list('abc')", []),
|
("list('abc')", []),
|
||||||
("list([c for c in 'abc'])", []),
|
("list([c for c in 'abc'])", []),
|
||||||
("list(c for c in 'abc')", []),
|
("list(c for c in 'abc')", []),
|
||||||
('builtins.list()', []),
|
('builtins.list()', []),
|
||||||
# str
|
# str
|
||||||
("''", []),
|
("''", []),
|
||||||
("str()", [Call('str', 1, 0)]),
|
('str()', [Call('str', 1, 0)]),
|
||||||
("str('0')", []),
|
("str('0')", []),
|
||||||
('builtins.str()', []),
|
('builtins.str()', []),
|
||||||
# tuple
|
# tuple
|
||||||
("()", []),
|
('()', []),
|
||||||
("tuple()", [Call('tuple', 1, 0)]),
|
('tuple()', [Call('tuple', 1, 0)]),
|
||||||
("tuple('abc')", []),
|
("tuple('abc')", []),
|
||||||
("tuple([c for c in 'abc'])", []),
|
("tuple([c for c in '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(
|
@pytest.mark.parametrize(
|
||||||
('expression', 'calls'),
|
('expression', 'calls'),
|
||||||
[
|
[
|
||||||
("{}", []),
|
('{}', []),
|
||||||
("dict()", [Call('dict', 1, 0)]),
|
('dict()', [Call('dict', 1, 0)]),
|
||||||
("dict(a=1, b=2, c=3)", []),
|
('dict(a=1, b=2, c=3)', []),
|
||||||
("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)]])", []),
|
||||||
("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(
|
@pytest.mark.parametrize(
|
||||||
('expression', 'calls'),
|
('expression', 'calls'),
|
||||||
[
|
[
|
||||||
("dict()", [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)]),
|
||||||
("dict(**{'a': 1, 'b': 2, 'c': 3})", [Call('dict', 1, 0)]),
|
("dict(**{'a': 1, 'b': 2, 'c': 3})", [Call('dict', 1, 0)]),
|
||||||
('builtins.dict()', []),
|
('builtins.dict()', []),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ def test_non_existent_credentials(mock_secrets_env, mock_secrets_file, capsys):
|
||||||
mock_secrets_file.return_value = set()
|
mock_secrets_file.return_value = set()
|
||||||
ret = main((
|
ret = main((
|
||||||
get_resource_path('aws_config_without_secrets.ini'),
|
get_resource_path('aws_config_without_secrets.ini'),
|
||||||
"--credentials-file=testing/resources/credentailsfilethatdoesntexist",
|
'--credentials-file=testing/resources/credentailsfilethatdoesntexist',
|
||||||
))
|
))
|
||||||
assert ret == 2
|
assert ret == 2
|
||||||
out, _ = capsys.readouterr()
|
out, _ = capsys.readouterr()
|
||||||
|
|
@ -143,7 +143,7 @@ def test_non_existent_credentials_with_allow_flag(
|
||||||
mock_secrets_file.return_value = set()
|
mock_secrets_file.return_value = set()
|
||||||
ret = main((
|
ret = main((
|
||||||
get_resource_path('aws_config_without_secrets.ini'),
|
get_resource_path('aws_config_without_secrets.ini'),
|
||||||
"--credentials-file=testing/resources/credentailsfilethatdoesntexist",
|
'--credentials-file=testing/resources/credentailsfilethatdoesntexist',
|
||||||
"--allow-missing-credentials",
|
'--allow-missing-credentials',
|
||||||
))
|
))
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ def test_unsorted_main(filename, expected_retval):
|
||||||
assert ret == expected_retval
|
assert ret == expected_retval
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(PY2, reason="Requires Python3")
|
@pytest.mark.skipif(PY2, reason='Requires Python3')
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
('filename', 'expected_retval'), (
|
('filename', 'expected_retval'), (
|
||||||
('not_pretty_formatted_json.json', 1),
|
('not_pretty_formatted_json.json', 1),
|
||||||
|
|
|
||||||
|
|
@ -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')
|
file_path = os.path.join(tmpdir.strpath, 'foo.yaml')
|
||||||
|
|
||||||
with open(file_path, 'w') as f:
|
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
|
assert main([file_path]) == retval
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue