Skip to content

Commit 76c604c

Browse files
authored
Merge pull request #364 from asottile/remove_flake8_config
Use default flake8 config
2 parents 634383c + 8626e26 commit 76c604c

19 files changed

+137
-98
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ repos:
1010
- id: check-yaml
1111
- id: debug-statements
1212
- id: name-tests-test
13+
- id: double-quote-string-fixer
1314
- id: requirements-txt-fixer
1415
- repo: https://gitlab.com/pycqa/flake8
1516
rev: 3.7.1

pre_commit_hooks/check_builtin_literals.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,23 @@
2121
}
2222

2323

24-
BuiltinTypeCall = collections.namedtuple('BuiltinTypeCall', ['name', 'line', 'column'])
24+
Call = collections.namedtuple('Call', ['name', 'line', 'column'])
2525

2626

27-
class BuiltinTypeVisitor(ast.NodeVisitor):
27+
class Visitor(ast.NodeVisitor):
2828
def __init__(self, ignore=None, allow_dict_kwargs=True):
2929
# type: (Optional[Sequence[str]], bool) -> None
30-
self.builtin_type_calls = [] # type: List[BuiltinTypeCall]
30+
self.builtin_type_calls = [] # type: List[Call]
3131
self.ignore = set(ignore) if ignore else set()
3232
self.allow_dict_kwargs = allow_dict_kwargs
3333

3434
def _check_dict_call(self, node): # type: (ast.Call) -> bool
35-
36-
return self.allow_dict_kwargs and (getattr(node, 'kwargs', None) or getattr(node, 'keywords', None))
35+
return (
36+
self.allow_dict_kwargs and
37+
(getattr(node, 'kwargs', None) or getattr(node, 'keywords', None))
38+
)
3739

3840
def visit_Call(self, node): # type: (ast.Call) -> None
39-
4041
if not isinstance(node.func, ast.Name):
4142
# Ignore functions that are object attributes (`foo.bar()`).
4243
# Assume that if the user calls `builtins.list()`, they know what
@@ -49,15 +50,15 @@ def visit_Call(self, node): # type: (ast.Call) -> None
4950
elif node.args:
5051
return
5152
self.builtin_type_calls.append(
52-
BuiltinTypeCall(node.func.id, node.lineno, node.col_offset),
53+
Call(node.func.id, node.lineno, node.col_offset),
5354
)
5455

5556

56-
def check_file_for_builtin_type_constructors(filename, ignore=None, allow_dict_kwargs=True):
57-
# type: (str, Optional[Sequence[str]], bool) -> List[BuiltinTypeCall]
57+
def check_file(filename, ignore=None, allow_dict_kwargs=True):
58+
# type: (str, Optional[Sequence[str]], bool) -> List[Call]
5859
with open(filename, 'rb') as f:
5960
tree = ast.parse(f.read(), filename=filename)
60-
visitor = BuiltinTypeVisitor(ignore=ignore, allow_dict_kwargs=allow_dict_kwargs)
61+
visitor = Visitor(ignore=ignore, allow_dict_kwargs=allow_dict_kwargs)
6162
visitor.visit(tree)
6263
return visitor.builtin_type_calls
6364

@@ -73,14 +74,17 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
7374

7475
mutex = parser.add_mutually_exclusive_group(required=False)
7576
mutex.add_argument('--allow-dict-kwargs', action='store_true')
76-
mutex.add_argument('--no-allow-dict-kwargs', dest='allow_dict_kwargs', action='store_false')
77+
mutex.add_argument(
78+
'--no-allow-dict-kwargs',
79+
dest='allow_dict_kwargs', action='store_false',
80+
)
7781
mutex.set_defaults(allow_dict_kwargs=True)
7882

7983
args = parser.parse_args(argv)
8084

8185
rc = 0
8286
for filename in args.filenames:
83-
calls = check_file_for_builtin_type_constructors(
87+
calls = check_file(
8488
filename,
8589
ignore=args.ignore,
8690
allow_dict_kwargs=args.allow_dict_kwargs,
@@ -89,7 +93,8 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
8993
rc = rc or 1
9094
for call in calls:
9195
print(
92-
'{filename}:{call.line}:{call.column} - Replace {call.name}() with {replacement}'.format(
96+
'{filename}:{call.line}:{call.column}: '
97+
'replace {call.name}() with {replacement}'.format(
9398
filename=filename,
9499
call=call,
95100
replacement=BUILTIN_TYPES[call.name],

pre_commit_hooks/check_executables_have_shebangs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def check_has_shebang(path): # type: (str) -> int
1818
print(
1919
'{path}: marked executable but has no (or invalid) shebang!\n'
2020
" If it isn't supposed to be executable, try: chmod -x {quoted}\n"
21-
' If it is supposed to be executable, double-check its shebang.'.format(
21+
' If it is supposed to be executable, double-check its shebang.'
22+
.format(
2223
path=path,
2324
quoted=pipes.quote(path),
2425
),

pre_commit_hooks/check_json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
def main(argv=None): # type: (Optional[Sequence[str]]) -> int
1212
parser = argparse.ArgumentParser()
13-
parser.add_argument('filenames', nargs='*', help='JSON filenames to check.')
13+
parser.add_argument('filenames', nargs='*', help='Filenames to check.')
1414
args = parser.parse_args(argv)
1515

1616
retval = 0

pre_commit_hooks/check_yaml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
5050
'Implies --allow-multiple-documents'
5151
),
5252
)
53-
parser.add_argument('filenames', nargs='*', help='Yaml filenames to check.')
53+
parser.add_argument('filenames', nargs='*', help='Filenames to check.')
5454
args = parser.parse_args(argv)
5555

5656
load_fn = LOAD_FNS[Key(multi=args.multi, unsafe=args.unsafe)]

pre_commit_hooks/detect_aws_credentials.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
from six.moves import configparser
1313

1414

15-
def get_aws_credential_files_from_env(): # type: () -> Set[str]
15+
def get_aws_cred_files_from_env(): # type: () -> Set[str]
1616
"""Extract credential file paths from environment variables."""
17-
files = set()
18-
for env_var in (
19-
'AWS_CONFIG_FILE', 'AWS_CREDENTIAL_FILE', 'AWS_SHARED_CREDENTIALS_FILE',
20-
'BOTO_CONFIG',
21-
):
22-
if env_var in os.environ:
23-
files.add(os.environ[env_var])
24-
return files
17+
return {
18+
os.environ[env_var]
19+
for env_var in (
20+
'AWS_CONFIG_FILE', 'AWS_CREDENTIAL_FILE',
21+
'AWS_SHARED_CREDENTIALS_FILE', 'BOTO_CONFIG',
22+
)
23+
if env_var in os.environ
24+
}
2525

2626

2727
def get_aws_secrets_from_env(): # type: () -> Set[str]
@@ -115,7 +115,7 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
115115

116116
# Add the credentials files configured via environment variables to the set
117117
# of files to to gather AWS secrets from.
118-
credential_files |= get_aws_credential_files_from_env()
118+
credential_files |= get_aws_cred_files_from_env()
119119

120120
keys = set() # type: Set[str]
121121
for credential_file in credential_files:

pre_commit_hooks/fix_encoding_pragma.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ def _to_disp(pragma): # type: (bytes) -> str
110110

111111

112112
def main(argv=None): # type: (Optional[Sequence[str]]) -> int
113-
parser = argparse.ArgumentParser('Fixes the encoding pragma of python files')
113+
parser = argparse.ArgumentParser(
114+
'Fixes the encoding pragma of python files',
115+
)
114116
parser.add_argument('filenames', nargs='*', help='Filenames to fix')
115117
parser.add_argument(
116118
'--pragma', default=DEFAULT_PRAGMA, type=_normalize_pragma,
@@ -145,5 +147,5 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
145147
return retv
146148

147149

148-
if __name__ == "__main__":
150+
if __name__ == '__main__':
149151
exit(main())

pre_commit_hooks/pretty_format_json.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
from six import text_type
1616

1717

18-
def _get_pretty_format(contents, indent, ensure_ascii=True, sort_keys=True, top_keys=()):
19-
# type: (str, str, bool, bool, Sequence[str]) -> str
18+
def _get_pretty_format(
19+
contents, indent, ensure_ascii=True, sort_keys=True, top_keys=(),
20+
): # type: (str, str, bool, bool, Sequence[str]) -> str
2021
def pairs_first(pairs):
2122
# type: (Sequence[Tuple[str, str]]) -> Mapping[str, str]
2223
before = [pair for pair in pairs if pair[0] in top_keys]
@@ -29,7 +30,8 @@ def pairs_first(pairs):
2930
json.loads(contents, object_pairs_hook=pairs_first),
3031
indent=indent,
3132
ensure_ascii=ensure_ascii,
32-
separators=(',', ': '), # Workaround for https://bugs.python.org/issue16333
33+
# Workaround for https://bugs.python.org/issue16333
34+
separators=(',', ': '),
3335
)
3436
# Ensure unicode (Py2) and add the newline that dumps does not end with.
3537
return text_type(json_pretty) + '\n'
@@ -75,7 +77,10 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
7577
action='store_true',
7678
dest='no_ensure_ascii',
7779
default=False,
78-
help='Do NOT convert non-ASCII characters to Unicode escape sequences (\\uXXXX)',
80+
help=(
81+
'Do NOT convert non-ASCII characters to Unicode escape sequences '
82+
'(\\uXXXX)'
83+
),
7984
)
8085
parser.add_argument(
8186
'--no-sort-keys',

pre_commit_hooks/requirements_txt_fixer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ def fix_requirements(f): # type: (IO[bytes]) -> int
6161
# If we see a newline before any requirements, then this is a
6262
# top of file comment.
6363
if len(requirements) == 1 and line.strip() == b'':
64-
if len(requirement.comments) and requirement.comments[0].startswith(b'#'):
64+
if (
65+
len(requirement.comments) and
66+
requirement.comments[0].startswith(b'#')
67+
):
6568
requirement.value = b'\n'
6669
else:
6770
requirement.comments.append(line)

pre_commit_hooks/sort_simple_yaml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
115115
new_lines = sort(lines)
116116

117117
if lines != new_lines:
118-
print("Fixing file `{filename}`".format(filename=filename))
118+
print('Fixing file `{filename}`'.format(filename=filename))
119119
f.seek(0)
120-
f.write("\n".join(new_lines) + "\n")
120+
f.write('\n'.join(new_lines) + '\n')
121121
f.truncate()
122122
retval = 1
123123

0 commit comments

Comments
 (0)