From 65ec19073f6e9dd8d67c0a0a8fe02ad669b43288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthew=20Shafer=20=F0=9F=90=8D?= Date: Thu, 27 Apr 2023 07:58:53 -0500 Subject: [PATCH 01/16] debugging: give test name based on input folder --- tests/test_cli/test_acknowledge_existing_errors.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/test_cli/test_acknowledge_existing_errors.py b/tests/test_cli/test_acknowledge_existing_errors.py index 9b2401fd..3fc6071a 100644 --- a/tests/test_cli/test_acknowledge_existing_errors.py +++ b/tests/test_cli/test_acknowledge_existing_errors.py @@ -10,7 +10,9 @@ ) -@pytest.mark.parametrize("test_dir", [x for x in TEST_CASE_DIR.iterdir() if x.is_dir()]) +@pytest.mark.parametrize( + "test_dir", [x for x in TEST_CASE_DIR.iterdir() if x.is_dir()], ids=lambda o: o.name +) def test_given_bad_input_produces_expected_output_simple( test_dir, snapshot, tmp_path, styleguide_command ): @@ -27,7 +29,9 @@ def test_given_bad_input_produces_expected_output_simple( snapshot.assert_match(result, "output.py") -@pytest.mark.parametrize("test_dir", [x for x in TEST_CASE_DIR.iterdir() if x.is_dir()]) +@pytest.mark.parametrize( + "test_dir", [x for x in TEST_CASE_DIR.iterdir() if x.is_dir()], ids=lambda o: o.name +) def test_given_bad_input_produces_expected_output_aggressive( test_dir, snapshot, tmp_path, styleguide_command ): @@ -46,7 +50,9 @@ def test_given_bad_input_produces_expected_output_aggressive( snapshot.assert_match(result, "output__aggressive.py") -@pytest.mark.parametrize("test_dir", [x for x in TEST_CASE_DIR.iterdir() if x.is_dir()]) +@pytest.mark.parametrize( + "test_dir", [x for x in TEST_CASE_DIR.iterdir() if x.is_dir()], ids=lambda o: o.name +) @pytest.mark.parametrize( "test_file,additional_args", [ From ab7672a099e01a4b320e351e262fdc1d1a0ef852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthew=20Shafer=20=F0=9F=90=8D?= Date: Thu, 27 Apr 2023 09:13:53 -0500 Subject: [PATCH 02/16] change LintError to typing.NamedTuple for type info --- ni_python_styleguide/_utils/lint.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ni_python_styleguide/_utils/lint.py b/ni_python_styleguide/_utils/lint.py index c78472db..c4749d56 100644 --- a/ni_python_styleguide/_utils/lint.py +++ b/ni_python_styleguide/_utils/lint.py @@ -1,6 +1,6 @@ import logging import re -from collections import namedtuple +import typing from ni_python_styleguide import _lint @@ -23,7 +23,12 @@ def get_errors_to_process(exclude, app_import_names, extend_ignore, file_or_dir, return lint_errors_to_process -LintError = namedtuple("LintError", ["file", "line", "column", "code", "explanation"]) +class LintError(typing.NamedTuple): + file: str + line: int + column: int + code: str + explanation: str def parse(line): From d0f61244ac522f930ce303dfc886cb7d9fd5f67f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthew=20Shafer=20=F0=9F=90=8D?= Date: Thu, 27 Apr 2023 09:14:04 -0500 Subject: [PATCH 03/16] add some more test ids --- tests/test_cli/test_acknowledge_existing_errors.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_cli/test_acknowledge_existing_errors.py b/tests/test_cli/test_acknowledge_existing_errors.py index 3fc6071a..ca23cb6b 100644 --- a/tests/test_cli/test_acknowledge_existing_errors.py +++ b/tests/test_cli/test_acknowledge_existing_errors.py @@ -56,11 +56,12 @@ def test_given_bad_input_produces_expected_output_aggressive( @pytest.mark.parametrize( "test_file,additional_args", [ - ( + pytest.param( "output.py", ["--extend-ignore=BLK100"], + id="output_ignore_black", ), # we don't suppress BLK100, so it's not one we expect to pass - ("output__aggressive.py", []), + pytest.param("output__aggressive.py", [], id="output_aggressive"), ], ) def test_given_suppressed_file_linter_does_not_error( From 7a4d983bfd9ee3013889d5ef66e4b20654ef6246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthew=20Shafer=20=F0=9F=90=8D?= Date: Thu, 27 Apr 2023 09:15:37 -0500 Subject: [PATCH 04/16] update format --- .../_acknowledge_existing_errors/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ni_python_styleguide/_acknowledge_existing_errors/__init__.py b/ni_python_styleguide/_acknowledge_existing_errors/__init__.py index fee6e7ce..f09ad25b 100644 --- a/ni_python_styleguide/_acknowledge_existing_errors/__init__.py +++ b/ni_python_styleguide/_acknowledge_existing_errors/__init__.py @@ -18,16 +18,17 @@ def _add_noqa_to_line(lineno, code_lines, error_code, explanation): old_line_ending = "\n" if line.endswith("\n") else "" line = line.rstrip("\n") - if f"noqa {error_code}" not in line: + if f"noqa: {error_code}" not in line: prefix = " " if line.strip() else "" - line += f"{prefix}# noqa {error_code}: {explanation} (auto-generated noqa)" + + line = f"{code.rstrip()}{prefix}# noqa: {error_code} - {explanation}" code_lines[lineno] = line + old_line_ending def _filter_suppresion_from_line(line: str): if "(auto-generated noqa)" in line: - return re.sub(r"# noqa .+\(auto-generated noqa\)", "", line).rstrip() + return re.sub(r"# noqa: .+\(auto-generated noqa\)$", "", line).rstrip() else: return line From 9f729ee84436be5461a59b1daf966db2841be11e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthew=20Shafer=20=F0=9F=90=8D?= Date: Thu, 27 Apr 2023 09:16:09 -0500 Subject: [PATCH 05/16] handle new way of dealing with multiple violations on a line --- .../_acknowledge_existing_errors/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ni_python_styleguide/_acknowledge_existing_errors/__init__.py b/ni_python_styleguide/_acknowledge_existing_errors/__init__.py index f09ad25b..044dd754 100644 --- a/ni_python_styleguide/_acknowledge_existing_errors/__init__.py +++ b/ni_python_styleguide/_acknowledge_existing_errors/__init__.py @@ -20,6 +20,14 @@ def _add_noqa_to_line(lineno, code_lines, error_code, explanation): if f"noqa: {error_code}" not in line: prefix = " " if line.strip() else "" + code, _, existing = line.partition("# noqa:") + + existing_codes, _, existing_explanations = existing.partition(" - ") + if existing_codes: + error_code = existing_codes + ", " + error_code + explanation = f"{existing_explanations}, {explanation} (auto-generated noqa)" + else: + explanation = explanation + " (auto-generated noqa)" line = f"{code.rstrip()}{prefix}# noqa: {error_code} - {explanation}" From 79970f371793b35c5883489b1bc37eea7ec0bb12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthew=20Shafer=20=F0=9F=90=8D?= Date: Thu, 27 Apr 2023 09:17:14 -0500 Subject: [PATCH 06/16] handle that comments can trigger W505. --- .../_acknowledge_existing_errors/__init__.py | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/ni_python_styleguide/_acknowledge_existing_errors/__init__.py b/ni_python_styleguide/_acknowledge_existing_errors/__init__.py index 044dd754..51afff3c 100644 --- a/ni_python_styleguide/_acknowledge_existing_errors/__init__.py +++ b/ni_python_styleguide/_acknowledge_existing_errors/__init__.py @@ -65,6 +65,8 @@ def acknowledge_lint_errors( for bad_file, errors_in_file in lint_errors_by_file.items(): _suppress_errors_in_file(bad_file, errors_in_file, encoding=_utils.DEFAULT_ENCODING) + _handle_emergent_violations(exclude, app_import_names, extend_ignore, file_or_dir, bad_file) + if aggressive: # some cases are expected to take up to 4 passes, making this 2x rounded per_file_format_iteration_limit = 10 @@ -90,8 +92,16 @@ def acknowledge_lint_errors( bad_file, current_lint_errors, encoding=_utils.DEFAULT_ENCODING ) + remaining_errors = _handle_emergent_violations( + exclude=exclude, + app_import_names=app_import_names, + extend_ignore=extend_ignore, + file_or_dir=file_or_dir, + bad_file=bad_file, + ) + changed = _format.format_check(bad_file) - if not changed: # are we done? + if not changed and not remaining_errors: # are we done? break else: failed_files.append( @@ -102,6 +112,23 @@ def acknowledge_lint_errors( raise RuntimeError("Could not handle some files:\n" + "\n\n".join(failed_files) + "\n\n\n") +def _handle_emergent_violations(exclude, app_import_names, extend_ignore, file_or_dir, bad_file): + """Some errors can be created by adding the acknowledge comments (e.g., W505), handle those now.""" + current_lint_errors = set( + _utils.lint.get_errors_to_process( + exclude=exclude, + app_import_names=app_import_names, + extend_ignore=extend_ignore, + file_or_dir=file_or_dir, + excluded_errors=EXCLUDED_ERRORS, + ) + ) + errors_to_process_now = set(filter(lambda o: o.code in {"W505"}, current_lint_errors)) + _suppress_errors_in_file(bad_file, errors_to_process_now, encoding=_utils.DEFAULT_ENCODING) + remaining_errors = current_lint_errors - errors_to_process_now + return remaining_errors + + def remove_auto_suppressions_from_file(file: pathlib.Path): """Removes auto-suppressions from file.""" lines = file.read_text(encoding=_utils.DEFAULT_ENCODING).splitlines() From 45f2fb0b7f4ee199f8d04e7e6935b94c0f638fce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthew=20Shafer=20=F0=9F=90=8D?= Date: Thu, 27 Apr 2023 09:17:23 -0500 Subject: [PATCH 07/16] format --- ni_python_styleguide/_acknowledge_existing_errors/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ni_python_styleguide/_acknowledge_existing_errors/__init__.py b/ni_python_styleguide/_acknowledge_existing_errors/__init__.py index 51afff3c..cb21cd97 100644 --- a/ni_python_styleguide/_acknowledge_existing_errors/__init__.py +++ b/ni_python_styleguide/_acknowledge_existing_errors/__init__.py @@ -3,8 +3,7 @@ import re from collections import defaultdict -from ni_python_styleguide import _format -from ni_python_styleguide import _utils +from ni_python_styleguide import _format, _utils _module_logger = logging.getLogger(__name__) From fe35e76c4da1301f32f052bfef6a6f8be03f73ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthew=20Shafer=20=F0=9F=90=8D?= Date: Thu, 27 Apr 2023 09:17:44 -0500 Subject: [PATCH 08/16] update tests --- .../blank_file_tests/output.py | 2 +- .../blank_file_tests/output__aggressive.py | 2 +- .../doc_line_tests/output.py | 12 +++---- .../doc_line_tests/output__aggressive.py | 12 +++---- .../function_signature_tests/output.py | 30 ++++++++-------- .../output__aggressive.py | 34 +++++++++--------- .../import_line_tests/output.py | 16 ++++----- .../import_line_tests/output__aggressive.py | 16 ++++----- .../line_continuation_tests/output.py | 8 ++--- .../output__aggressive.py | 8 ++--- .../structural_tests/output.py | 36 +++++++++---------- .../structural_tests/output__aggressive.py | 36 +++++++++---------- .../unicode_in_files/output.py | 2 +- .../unicode_in_files/output__aggressive.py | 4 +-- .../basic_example/input.py | 2 +- .../basic_example/output.py | 2 +- 16 files changed, 111 insertions(+), 111 deletions(-) diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/blank_file_tests/output.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/blank_file_tests/output.py index 3283018e..465dbed6 100644 --- a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/blank_file_tests/output.py +++ b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/blank_file_tests/output.py @@ -1 +1 @@ -# noqa D100: Missing docstring in public module (auto-generated noqa) +# noqa: D100 - Missing docstring in public module (auto-generated noqa) diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/blank_file_tests/output__aggressive.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/blank_file_tests/output__aggressive.py index 3283018e..465dbed6 100644 --- a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/blank_file_tests/output__aggressive.py +++ b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/blank_file_tests/output__aggressive.py @@ -1 +1 @@ -# noqa D100: Missing docstring in public module (auto-generated noqa) +# noqa: D100 - Missing docstring in public module (auto-generated noqa) diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/doc_line_tests/output.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/doc_line_tests/output.py index c2a4ebfc..98387282 100644 --- a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/doc_line_tests/output.py +++ b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/doc_line_tests/output.py @@ -1,4 +1,4 @@ -def method1(): # noqa D100: Missing docstring in public module (auto-generated noqa) # noqa D103: Missing docstring in public function (auto-generated noqa) +def method1(): # noqa: D100, D103 - Missing docstring in public module (auto-generated noqa), Missing docstring in public function (auto-generated noqa) return 7 @@ -6,19 +6,19 @@ def method2(): """Provide an examples of doc strings that are too long. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. - """ # noqa W505: doc line too long (127 > 100 characters) (auto-generated noqa) + """ # noqa: W505 - doc line too long (127 > 100 characters) (auto-generated noqa) return 7 # Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. -class Foo: # noqa D101: Missing docstring in public class (auto-generated noqa) - def __init__(self): # noqa D107: Missing docstring in __init__ (auto-generated noqa) +class Foo: # noqa: D101 - Missing docstring in public class (auto-generated noqa) + def __init__(self): # noqa: D107 - Missing docstring in __init__ (auto-generated noqa) pass def add(self, o): """Provide an examples of doc strings that are too long. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. - """ # noqa W505: doc line too long (131 > 100 characters) (auto-generated noqa) + """ # noqa: W505 - doc line too long (131 > 100 characters) (auto-generated noqa) return 7 # Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. @@ -30,5 +30,5 @@ def add(self, o): """Provide an examples of doc strings that are too long. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. - """ # noqa W505: doc line too long (131 > 100 characters) (auto-generated noqa) + """ # noqa: W505 - doc line too long (131 > 100 characters) (auto-generated noqa) return 7 # Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/doc_line_tests/output__aggressive.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/doc_line_tests/output__aggressive.py index c2a4ebfc..98387282 100644 --- a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/doc_line_tests/output__aggressive.py +++ b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/doc_line_tests/output__aggressive.py @@ -1,4 +1,4 @@ -def method1(): # noqa D100: Missing docstring in public module (auto-generated noqa) # noqa D103: Missing docstring in public function (auto-generated noqa) +def method1(): # noqa: D100, D103 - Missing docstring in public module (auto-generated noqa), Missing docstring in public function (auto-generated noqa) return 7 @@ -6,19 +6,19 @@ def method2(): """Provide an examples of doc strings that are too long. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. - """ # noqa W505: doc line too long (127 > 100 characters) (auto-generated noqa) + """ # noqa: W505 - doc line too long (127 > 100 characters) (auto-generated noqa) return 7 # Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. -class Foo: # noqa D101: Missing docstring in public class (auto-generated noqa) - def __init__(self): # noqa D107: Missing docstring in __init__ (auto-generated noqa) +class Foo: # noqa: D101 - Missing docstring in public class (auto-generated noqa) + def __init__(self): # noqa: D107 - Missing docstring in __init__ (auto-generated noqa) pass def add(self, o): """Provide an examples of doc strings that are too long. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. - """ # noqa W505: doc line too long (131 > 100 characters) (auto-generated noqa) + """ # noqa: W505 - doc line too long (131 > 100 characters) (auto-generated noqa) return 7 # Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. @@ -30,5 +30,5 @@ def add(self, o): """Provide an examples of doc strings that are too long. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. - """ # noqa W505: doc line too long (131 > 100 characters) (auto-generated noqa) + """ # noqa: W505 - doc line too long (131 > 100 characters) (auto-generated noqa) return 7 # Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/function_signature_tests/output.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/function_signature_tests/output.py index a9c2207b..bbcd9d36 100644 --- a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/function_signature_tests/output.py +++ b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/function_signature_tests/output.py @@ -35,68 +35,68 @@ def method_with_parameters_on_multiple_lines(x, y): return x + y -def method_with_bad_names_on_single_line(myBadlyNamedParam, my_other_Bad_name): # noqa N803: argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) +def method_with_bad_names_on_single_line(myBadlyNamedParam, my_other_Bad_name): # noqa: N803 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) """Provide parameters with bad names on single line.""" return myBadlyNamedParam + my_other_Bad_name def method_with_bad_names_on_multiple_lines_1( - myBadlyNamedParam, # noqa N803: argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) + myBadlyNamedParam, # noqa: N803 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) ): """Provide parameters with bad names on multiple lines.""" return myBadlyNamedParam + 5 def method_with_bad_names_on_multiple_lines_2( - myBadlyNamedParam, # noqa N803: argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) + myBadlyNamedParam, # noqa: N803 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) my_other_Bad_name, ): """Provide parameters with bad names on multiple lines.""" return myBadlyNamedParam + my_other_Bad_name -def method_withBadName_with_shadow(input): # noqa N802: function name 'method_withBadName_with_shadow' should be lowercase (auto-generated noqa) +def method_withBadName_with_shadow(input): # noqa: N802 - function name 'method_withBadName_with_shadow' should be lowercase (auto-generated noqa) """Shadow a builtin.""" return input -def method_withBadName_with_unused_param(unused_input): # noqa N802: function name 'method_withBadName_with_unused_param' should be lowercase (auto-generated noqa) +def method_withBadName_with_unused_param(unused_input): # noqa: N802 - function name 'method_withBadName_with_unused_param' should be lowercase (auto-generated noqa) """Provide and unused param.""" return 5 -def method_withBadName_with_parameters_on_multiple_lines(x, y): # noqa N802: function name 'method_withBadName_with_parameters_on_multiple_lines' should be lowercase (auto-generated noqa) +def method_withBadName_with_parameters_on_multiple_lines(x, y): # noqa: N802 - function name 'method_withBadName_with_parameters_on_multiple_lines' should be lowercase (auto-generated noqa) """Provide parameters on multiple lines test case.""" return x + y -def method_withBadName_with_bad_params_on_single_line(myBadlyNamedParam, my_other_Bad_name): # noqa N803: argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) # noqa N802: function name 'method_withBadName_with_bad_params_on_single_line' should be lowercase (auto-generated noqa) +def method_withBadName_with_bad_params_on_single_line(myBadlyNamedParam, my_other_Bad_name): # noqa: N803, N802 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa), function name 'method_withBadName_with_bad_params_on_single_line' should be lowercase (auto-generated noqa) """Provide parameters with bad names on single line.""" return myBadlyNamedParam + my_other_Bad_name -def method_withBadName_with_bad_params_on_multiple_lines_1( # noqa N802: function name 'method_withBadName_with_bad_params_on_multiple_lines_1' should be lowercase (auto-generated noqa) - myBadlyNamedParam, # noqa N803: argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) +def method_withBadName_with_bad_params_on_multiple_lines_1( # noqa: N802 - function name 'method_withBadName_with_bad_params_on_multiple_lines_1' should be lowercase (auto-generated noqa) + myBadlyNamedParam, # noqa: N803 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) ): """Provide parameters with bad names on multiple lines.""" return myBadlyNamedParam + 5 -def method_withBadName_with_bad_params_on_multiple_lines_2( # noqa N802: function name 'method_withBadName_with_bad_params_on_multiple_lines_2' should be lowercase (auto-generated noqa) - myBadlyNamedParam, # noqa N803: argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) +def method_withBadName_with_bad_params_on_multiple_lines_2( # noqa: N802 - function name 'method_withBadName_with_bad_params_on_multiple_lines_2' should be lowercase (auto-generated noqa) + myBadlyNamedParam, # noqa: N803 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) my_other_Bad_name, ): """Provide parameters with bad names on multiple lines.""" return myBadlyNamedParam + my_other_Bad_name -def method_withBadName_andParams(my_normal_param, myBadlyNamedParam, my_other_Bad_param): # noqa N803: argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) # noqa N802: function name 'method_withBadName_andParams' should be lowercase (auto-generated noqa) +def method_withBadName_andParams(my_normal_param, myBadlyNamedParam, my_other_Bad_param): # noqa: N803, N802 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa), function name 'method_withBadName_andParams' should be lowercase (auto-generated noqa) """Provide example where black will want to split out result.""" return 5 + 7 -def method_withBadName_and_bad_param_with_long_name( # noqa N802: function name 'method_withBadName_and_bad_param_with_long_name' should be lowercase (auto-generated noqa) - my_normal_param, myBadlyNamedParam, my_other_Bad_param # noqa N803: argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) +def method_withBadName_and_bad_param_with_long_name( # noqa: N802 - function name 'method_withBadName_and_bad_param_with_long_name' should be lowercase (auto-generated noqa) + my_normal_param, myBadlyNamedParam, my_other_Bad_param # noqa: N803 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) ): - """Provide example where black will want to split out result even more""" # noqa D415: First line should end with a period, question mark, or exclamation point (auto-generated noqa) + """Provide example where black will want to split out result even more""" # noqa: D415, W505 - First line should end with a period, question mark, or exclamation point (auto-generated noqa), doc line too long (188 > 100 characters) (auto-generated noqa) return 5 + 7 diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/function_signature_tests/output__aggressive.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/function_signature_tests/output__aggressive.py index 8aea8a29..68ead7c0 100644 --- a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/function_signature_tests/output__aggressive.py +++ b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/function_signature_tests/output__aggressive.py @@ -36,7 +36,7 @@ def method_with_parameters_on_multiple_lines(x, y): def method_with_bad_names_on_single_line( - myBadlyNamedParam, # noqa N803: argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) + myBadlyNamedParam, # noqa: N803 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) my_other_Bad_name, ): """Provide parameters with bad names on single line.""" @@ -44,77 +44,77 @@ def method_with_bad_names_on_single_line( def method_with_bad_names_on_multiple_lines_1( - myBadlyNamedParam, # noqa N803: argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) + myBadlyNamedParam, # noqa: N803 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) ): """Provide parameters with bad names on multiple lines.""" return myBadlyNamedParam + 5 def method_with_bad_names_on_multiple_lines_2( - myBadlyNamedParam, # noqa N803: argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) + myBadlyNamedParam, # noqa: N803 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) my_other_Bad_name, ): """Provide parameters with bad names on multiple lines.""" return myBadlyNamedParam + my_other_Bad_name -def method_withBadName_with_shadow( # noqa N802: function name 'method_withBadName_with_shadow' should be lowercase (auto-generated noqa) +def method_withBadName_with_shadow( # noqa: N802 - function name 'method_withBadName_with_shadow' should be lowercase (auto-generated noqa) input, ): """Shadow a builtin.""" return input -def method_withBadName_with_unused_param( # noqa N802: function name 'method_withBadName_with_unused_param' should be lowercase (auto-generated noqa) +def method_withBadName_with_unused_param( # noqa: N802 - function name 'method_withBadName_with_unused_param' should be lowercase (auto-generated noqa) unused_input, ): """Provide and unused param.""" return 5 -def method_withBadName_with_parameters_on_multiple_lines( # noqa N802: function name 'method_withBadName_with_parameters_on_multiple_lines' should be lowercase (auto-generated noqa) +def method_withBadName_with_parameters_on_multiple_lines( # noqa: N802 - function name 'method_withBadName_with_parameters_on_multiple_lines' should be lowercase (auto-generated noqa) x, y ): """Provide parameters on multiple lines test case.""" return x + y -def method_withBadName_with_bad_params_on_single_line( # noqa N802: function name 'method_withBadName_with_bad_params_on_single_line' should be lowercase (auto-generated noqa) - myBadlyNamedParam, # noqa N803: argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) +def method_withBadName_with_bad_params_on_single_line( # noqa: N802 - function name 'method_withBadName_with_bad_params_on_single_line' should be lowercase (auto-generated noqa) + myBadlyNamedParam, # noqa: N803 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) my_other_Bad_name, ): """Provide parameters with bad names on single line.""" return myBadlyNamedParam + my_other_Bad_name -def method_withBadName_with_bad_params_on_multiple_lines_1( # noqa N802: function name 'method_withBadName_with_bad_params_on_multiple_lines_1' should be lowercase (auto-generated noqa) - myBadlyNamedParam, # noqa N803: argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) +def method_withBadName_with_bad_params_on_multiple_lines_1( # noqa: N802 - function name 'method_withBadName_with_bad_params_on_multiple_lines_1' should be lowercase (auto-generated noqa) + myBadlyNamedParam, # noqa: N803 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) ): """Provide parameters with bad names on multiple lines.""" return myBadlyNamedParam + 5 -def method_withBadName_with_bad_params_on_multiple_lines_2( # noqa N802: function name 'method_withBadName_with_bad_params_on_multiple_lines_2' should be lowercase (auto-generated noqa) - myBadlyNamedParam, # noqa N803: argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) +def method_withBadName_with_bad_params_on_multiple_lines_2( # noqa: N802 - function name 'method_withBadName_with_bad_params_on_multiple_lines_2' should be lowercase (auto-generated noqa) + myBadlyNamedParam, # noqa: N803 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) my_other_Bad_name, ): """Provide parameters with bad names on multiple lines.""" return myBadlyNamedParam + my_other_Bad_name -def method_withBadName_andParams( # noqa N802: function name 'method_withBadName_andParams' should be lowercase (auto-generated noqa) +def method_withBadName_andParams( # noqa: N802 - function name 'method_withBadName_andParams' should be lowercase (auto-generated noqa) my_normal_param, - myBadlyNamedParam, # noqa N803: argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) + myBadlyNamedParam, # noqa: N803 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) my_other_Bad_param, ): """Provide example where black will want to split out result.""" return 5 + 7 -def method_withBadName_and_bad_param_with_long_name( # noqa N802: function name 'method_withBadName_and_bad_param_with_long_name' should be lowercase (auto-generated noqa) +def method_withBadName_and_bad_param_with_long_name( # noqa: N802 - function name 'method_withBadName_and_bad_param_with_long_name' should be lowercase (auto-generated noqa) my_normal_param, - myBadlyNamedParam, # noqa N803: argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) + myBadlyNamedParam, # noqa: N803 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) my_other_Bad_param, ): - """Provide example where black will want to split out result even more""" # noqa D415: First line should end with a period, question mark, or exclamation point (auto-generated noqa) + """Provide example where black will want to split out result even more""" # noqa: D415, W505 - First line should end with a period, question mark, or exclamation point (auto-generated noqa), doc line too long (188 > 100 characters) (auto-generated noqa) return 5 + 7 diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/import_line_tests/output.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/import_line_tests/output.py index ddfdd6ae..59227745 100644 --- a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/import_line_tests/output.py +++ b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/import_line_tests/output.py @@ -1,11 +1,11 @@ """example of a python file with linter errors. """ -import pathlib, glob # noqa E401: multiple imports on one line (auto-generated noqa) # noqa F401: 'glob' imported but unused (auto-generated noqa) -import os # noqa I100: Import statements are in the wrong order. 'import os' should be before 'import pathlib, glob' (auto-generated noqa) -from os import path # noqa F401: 'os.path' imported but unused (auto-generated noqa) -from os.path import * # noqa F403: 'from os.path import *' used; unable to detect undefined names (auto-generated noqa) -from os.path.lorem.ipsum.dolor.sit.amet.consectetur.adipiscing.elit.sed.do.eiusmod.tempor.incididunt.ut.labore.et.dolore.magna import ( # noqa F401: 'os.path.lorem.ipsum.dolor.sit.amet.consectetur.adipiscing.elit.sed.do.eiusmod.tempor.incididunt.ut.labore.et.dolore.magna.lorem' imported but unused (auto-generated noqa) +import pathlib, glob # noqa: E401, F401 - multiple imports on one line (auto-generated noqa), 'glob' imported but unused (auto-generated noqa) +import os # noqa: I100 - Import statements are in the wrong order. 'import os' should be before 'import pathlib, glob' (auto-generated noqa) +from os import path # noqa: F401 - 'os.path' imported but unused (auto-generated noqa) +from os.path import * # noqa: F403 - 'from os.path import *' used; unable to detect undefined names (auto-generated noqa) +from os.path.lorem.ipsum.dolor.sit.amet.consectetur.adipiscing.elit.sed.do.eiusmod.tempor.incididunt.ut.labore.et.dolore.magna import ( # noqa: F401 - 'os.path.lorem.ipsum.dolor.sit.amet.consectetur.adipiscing.elit.sed.do.eiusmod.tempor.incididunt.ut.labore.et.dolore.magna.lorem' imported but unused (auto-generated noqa) aliqua, dolor, ipsum, @@ -17,14 +17,14 @@ ipsum() dolor() -listdir() # noqa F405: 'listdir' may be undefined, or defined from star imports: os.path (auto-generated noqa) +listdir() # noqa: F405 - 'listdir' may be undefined, or defined from star imports: os.path (auto-generated noqa) os.listdir() def _test_os_name(): - for os in range(3): # noqa F402: import 'os' from line 5 shadowed by loop variable (auto-generated noqa) + for os in range(3): # noqa: F402 - import 'os' from line 5 shadowed by loop variable (auto-generated noqa) print(os) -import collections # noqa E402: module level import not at top of file (auto-generated noqa) # noqa F401: 'collections' imported but unused (auto-generated noqa) # noqa I100: Import statements are in the wrong order. 'import collections' should be before 'from os.path.lorem.ipsum.dolor.sit.amet.consectetur.adipiscing.elit.sed.do.eiusmod.tempor.incididunt.ut.labore.et.dolore.magna import aliqua, dolor, ipsum, lorem' (auto-generated noqa) # noqa I202: Additional newline in a group of imports. 'import collections' is identified as Stdlib and 'from os.path.lorem.ipsum.dolor.sit.amet.consectetur.adipiscing.elit.sed.do.eiusmod.tempor.incididunt.ut.labore.et.dolore.magna import aliqua, dolor, ipsum, lorem' is identified as Stdlib. (auto-generated noqa) +import collections # noqa: E402, F401, I100, I202 - module level import not at top of file (auto-generated noqa), 'collections' imported but unused (auto-generated noqa), Import statements are in the wrong order. 'import collections' should be before 'from os.path.lorem.ipsum.dolor.sit.amet.consectetur.adipiscing.elit.sed.do.eiusmod.tempor.incididunt.ut.labore.et.dolore.magna import aliqua, dolor, ipsum, lorem' (auto-generated noqa), Additional newline in a group of imports. 'import collections' is identified as Stdlib and 'from os.path.lorem.ipsum.dolor.sit.amet.consectetur.adipiscing.elit.sed.do.eiusmod.tempor.incididunt.ut.labore.et.dolore.magna import aliqua, dolor, ipsum, lorem' is identified as Stdlib. (auto-generated noqa) diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/import_line_tests/output__aggressive.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/import_line_tests/output__aggressive.py index 577ab251..f0a3b60d 100644 --- a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/import_line_tests/output__aggressive.py +++ b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/import_line_tests/output__aggressive.py @@ -1,11 +1,11 @@ """example of a python file with linter errors. """ -import pathlib, glob # noqa E401: multiple imports on one line (auto-generated noqa) # noqa F401: 'glob' imported but unused (auto-generated noqa) -import os # noqa I100: Import statements are in the wrong order. 'import os' should be before 'import pathlib, glob' (auto-generated noqa) -from os import path # noqa F401: 'os.path' imported but unused (auto-generated noqa) -from os.path import * # noqa F403: 'from os.path import *' used; unable to detect undefined names (auto-generated noqa) -from os.path.lorem.ipsum.dolor.sit.amet.consectetur.adipiscing.elit.sed.do.eiusmod.tempor.incididunt.ut.labore.et.dolore.magna import ( # noqa F401: 'os.path.lorem.ipsum.dolor.sit.amet.consectetur.adipiscing.elit.sed.do.eiusmod.tempor.incididunt.ut.labore.et.dolore.magna.lorem' imported but unused (auto-generated noqa) +import pathlib, glob # noqa: E401, F401 - multiple imports on one line (auto-generated noqa), 'glob' imported but unused (auto-generated noqa) +import os # noqa: I100 - Import statements are in the wrong order. 'import os' should be before 'import pathlib, glob' (auto-generated noqa) +from os import path # noqa: F401 - 'os.path' imported but unused (auto-generated noqa) +from os.path import * # noqa: F403 - 'from os.path import *' used; unable to detect undefined names (auto-generated noqa) +from os.path.lorem.ipsum.dolor.sit.amet.consectetur.adipiscing.elit.sed.do.eiusmod.tempor.incididunt.ut.labore.et.dolore.magna import ( # noqa: F401 - 'os.path.lorem.ipsum.dolor.sit.amet.consectetur.adipiscing.elit.sed.do.eiusmod.tempor.incididunt.ut.labore.et.dolore.magna.lorem' imported but unused (auto-generated noqa) aliqua, dolor, ipsum, @@ -17,16 +17,16 @@ ipsum() dolor() -listdir() # noqa F405: 'listdir' may be undefined, or defined from star imports: os.path (auto-generated noqa) +listdir() # noqa: F405 - 'listdir' may be undefined, or defined from star imports: os.path (auto-generated noqa) os.listdir() def _test_os_name(): for ( - os # noqa F402: import 'os' from line 5 shadowed by loop variable (auto-generated noqa) + os # noqa: F402 - import 'os' from line 5 shadowed by loop variable (auto-generated noqa) ) in range(3): print(os) -import collections # noqa E402: module level import not at top of file (auto-generated noqa) # noqa F401: 'collections' imported but unused (auto-generated noqa) # noqa I100: Import statements are in the wrong order. 'import collections' should be before 'from os.path.lorem.ipsum.dolor.sit.amet.consectetur.adipiscing.elit.sed.do.eiusmod.tempor.incididunt.ut.labore.et.dolore.magna import aliqua, dolor, ipsum, lorem' (auto-generated noqa) # noqa I202: Additional newline in a group of imports. 'import collections' is identified as Stdlib and 'from os.path.lorem.ipsum.dolor.sit.amet.consectetur.adipiscing.elit.sed.do.eiusmod.tempor.incididunt.ut.labore.et.dolore.magna import aliqua, dolor, ipsum, lorem' is identified as Stdlib. (auto-generated noqa) +import collections # noqa: E402, F401, I100, I202 - module level import not at top of file (auto-generated noqa), 'collections' imported but unused (auto-generated noqa), Import statements are in the wrong order. 'import collections' should be before 'from os.path.lorem.ipsum.dolor.sit.amet.consectetur.adipiscing.elit.sed.do.eiusmod.tempor.incididunt.ut.labore.et.dolore.magna import aliqua, dolor, ipsum, lorem' (auto-generated noqa), Additional newline in a group of imports. 'import collections' is identified as Stdlib and 'from os.path.lorem.ipsum.dolor.sit.amet.consectetur.adipiscing.elit.sed.do.eiusmod.tempor.incididunt.ut.labore.et.dolore.magna import aliqua, dolor, ipsum, lorem' is identified as Stdlib. (auto-generated noqa) diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/line_continuation_tests/output.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/line_continuation_tests/output.py index cc34c74d..2e778ed5 100644 --- a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/line_continuation_tests/output.py +++ b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/line_continuation_tests/output.py @@ -1,11 +1,11 @@ some_string_with_line_continuation = f"{installPath}\\foo\\bar\\baz.exe \ - --check --this-is-cool --bacon --ipsum" # noqa D100: Missing docstring in public module (auto-generated noqa) # noqa F821: undefined name 'installPath' (auto-generated noqa) + --check --this-is-cool --bacon --ipsum" # noqa: D100, F821 - Missing docstring in public module (auto-generated noqa), undefined name 'installPath' (auto-generated noqa) # black, please leave these ridiculous line continuations in place for testing. # fmt: off if 1 < 2 == True and \ 3 < 4 and \ - 5 < 6: # noqa E712: comparison to True should be 'if cond is True:' or 'if cond:' (auto-generated noqa) + 5 < 6: # noqa: E712 - comparison to True should be 'if cond is True:' or 'if cond:' (auto-generated noqa) print("There is order in this world") else: raise Exception("There's funny going on here.") @@ -19,7 +19,7 @@ # even some like this ''' many they be, suppresion should be after -""" # noqa N816: variable 'someStringWithProblems' in global scope should not be mixedCase (auto-generated noqa) +""" # noqa: N816 - variable 'someStringWithProblems' in global scope should not be mixedCase (auto-generated noqa) -loremIpsum = "dolor" # comments however are not affected \ # noqa N816: variable 'loremIpsum' in global scope should not be mixedCase (auto-generated noqa) +loremIpsum = "dolor" # comments however are not affected \ # noqa: N816 - variable 'loremIpsum' in global scope should not be mixedCase (auto-generated noqa) # even if they have backslashes diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/line_continuation_tests/output__aggressive.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/line_continuation_tests/output__aggressive.py index cc34c74d..2e778ed5 100644 --- a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/line_continuation_tests/output__aggressive.py +++ b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/line_continuation_tests/output__aggressive.py @@ -1,11 +1,11 @@ some_string_with_line_continuation = f"{installPath}\\foo\\bar\\baz.exe \ - --check --this-is-cool --bacon --ipsum" # noqa D100: Missing docstring in public module (auto-generated noqa) # noqa F821: undefined name 'installPath' (auto-generated noqa) + --check --this-is-cool --bacon --ipsum" # noqa: D100, F821 - Missing docstring in public module (auto-generated noqa), undefined name 'installPath' (auto-generated noqa) # black, please leave these ridiculous line continuations in place for testing. # fmt: off if 1 < 2 == True and \ 3 < 4 and \ - 5 < 6: # noqa E712: comparison to True should be 'if cond is True:' or 'if cond:' (auto-generated noqa) + 5 < 6: # noqa: E712 - comparison to True should be 'if cond is True:' or 'if cond:' (auto-generated noqa) print("There is order in this world") else: raise Exception("There's funny going on here.") @@ -19,7 +19,7 @@ # even some like this ''' many they be, suppresion should be after -""" # noqa N816: variable 'someStringWithProblems' in global scope should not be mixedCase (auto-generated noqa) +""" # noqa: N816 - variable 'someStringWithProblems' in global scope should not be mixedCase (auto-generated noqa) -loremIpsum = "dolor" # comments however are not affected \ # noqa N816: variable 'loremIpsum' in global scope should not be mixedCase (auto-generated noqa) +loremIpsum = "dolor" # comments however are not affected \ # noqa: N816 - variable 'loremIpsum' in global scope should not be mixedCase (auto-generated noqa) # even if they have backslashes diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/structural_tests/output.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/structural_tests/output.py index 3d0006fd..3e5f9467 100644 --- a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/structural_tests/output.py +++ b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/structural_tests/output.py @@ -2,7 +2,7 @@ """ -l = 5 # noqa E741: ambiguous variable name 'l' (auto-generated noqa) +l = 5 # noqa: E741 - ambiguous variable name 'l' (auto-generated noqa) y = False if l is None: @@ -12,53 +12,53 @@ if l is None: print("l is None") -if y == False: # noqa E712: comparison to False should be 'if cond is False:' or 'if not cond:' (auto-generated noqa) +if y == False: # noqa: E712 - comparison to False should be 'if cond is False:' or 'if not cond:' (auto-generated noqa) print("l is False") -if y == True: # noqa E712: comparison to True should be 'if cond is True:' or 'if cond:' (auto-generated noqa) +if y == True: # noqa: E712 - comparison to True should be 'if cond is True:' or 'if cond:' (auto-generated noqa) print("l is True") if x < 5: print("x < 5") -def foo(): # noqa D103: Missing docstring in public function (auto-generated noqa) - for l in range(3): # noqa E741: ambiguous variable name 'l' (auto-generated noqa) +def foo(): # noqa: D103 - Missing docstring in public function (auto-generated noqa) + for l in range(3): # noqa: E741 - ambiguous variable name 'l' (auto-generated noqa) pass -breakfast = lambda: ["eggs"] + ["spam"] * 7 # noqa E731: do not assign a lambda expression, use a def (auto-generated noqa) +breakfast = lambda: ["eggs"] + ["spam"] * 7 # noqa: E731 - do not assign a lambda expression, use a def (auto-generated noqa) -def menu(): # noqa D103: Missing docstring in public function (auto-generated noqa) - lunch = lambda: ["ham"] + ["corned beef"] * 7 # noqa E731: do not assign a lambda expression, use a def (auto-generated noqa) +def menu(): # noqa: D103 - Missing docstring in public function (auto-generated noqa) + lunch = lambda: ["ham"] + ["corned beef"] * 7 # noqa: E731 - do not assign a lambda expression, use a def (auto-generated noqa) return breakfast, lunch try: - raise NotImplemented # noqa F901: 'raise NotImplemented' should be 'raise NotImplementedError' (auto-generated noqa) -except: # noqa E722: do not use bare 'except' (auto-generated noqa) + raise NotImplemented # noqa: F901 - 'raise NotImplemented' should be 'raise NotImplementedError' (auto-generated noqa) +except: # noqa: E722 - do not use bare 'except' (auto-generated noqa) pass -class Cheese_Shop: # noqa D101: Missing docstring in public class (auto-generated noqa) # noqa N801: class name 'Cheese_Shop' should use CapWords convention (auto-generated noqa) - def RequestCheese(self): # noqa N802: function name 'RequestCheese' should be lowercase (auto-generated noqa) +class Cheese_Shop: # noqa: D101, N801 - Missing docstring in public class (auto-generated noqa), class name 'Cheese_Shop' should use CapWords convention (auto-generated noqa) + def RequestCheese(self): # noqa: N802 - function name 'RequestCheese' should be lowercase (auto-generated noqa) """Provide method with bad name.""" pass def return_no_cheese_found(self): """Provide method with functional lint errors.""" - cheese_found = lambda o: False # noqa E731: do not assign a lambda expression, use a def (auto-generated noqa) + cheese_found = lambda o: False # noqa: E731 - do not assign a lambda expression, use a def (auto-generated noqa) try: - raise NotImplemented # noqa F901: 'raise NotImplemented' should be 'raise NotImplementedError' (auto-generated noqa) - except: # noqa E722: do not use bare 'except' (auto-generated noqa) + raise NotImplemented # noqa: F901 - 'raise NotImplemented' should be 'raise NotImplementedError' (auto-generated noqa) + except: # noqa: E722 - do not use bare 'except' (auto-generated noqa) pass - l = 5 # noqa E741: ambiguous variable name 'l' (auto-generated noqa) - i = 3 # noqa F841: local variable 'i' is assigned to but never used (auto-generated noqa) + l = 5 # noqa: E741 - ambiguous variable name 'l' (auto-generated noqa) + i = 3 # noqa: F841 - local variable 'i' is assigned to but never used (auto-generated noqa) - if l == True: # noqa E741: ambiguous variable name 'l' (auto-generated noqa) # noqa E712: comparison to True should be 'if cond is True:' or 'if cond:' (auto-generated noqa) + if l == True: # noqa: E741, E712 - ambiguous variable name 'l' (auto-generated noqa), comparison to True should be 'if cond is True:' or 'if cond:' (auto-generated noqa) return False return cheese_found diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/structural_tests/output__aggressive.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/structural_tests/output__aggressive.py index bfb68622..772dfd58 100644 --- a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/structural_tests/output__aggressive.py +++ b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/structural_tests/output__aggressive.py @@ -2,7 +2,7 @@ """ -l = 5 # noqa E741: ambiguous variable name 'l' (auto-generated noqa) +l = 5 # noqa: E741 - ambiguous variable name 'l' (auto-generated noqa) y = False if l is None: @@ -14,13 +14,13 @@ if ( y - == False # noqa E712: comparison to False should be 'if cond is False:' or 'if not cond:' (auto-generated noqa) + == False # noqa: E712 - comparison to False should be 'if cond is False:' or 'if not cond:' (auto-generated noqa) ): print("l is False") if ( y - == True # noqa E712: comparison to True should be 'if cond is True:' or 'if cond:' (auto-generated noqa) + == True # noqa: E712 - comparison to True should be 'if cond is True:' or 'if cond:' (auto-generated noqa) ): print("l is True") @@ -28,31 +28,31 @@ print("x < 5") -def foo(): # noqa D103: Missing docstring in public function (auto-generated noqa) - for l in range(3): # noqa E741: ambiguous variable name 'l' (auto-generated noqa) +def foo(): # noqa: D103 - Missing docstring in public function (auto-generated noqa) + for l in range(3): # noqa: E741 - ambiguous variable name 'l' (auto-generated noqa) pass breakfast = ( lambda: ["eggs"] + ["spam"] * 7 -) # noqa E731: do not assign a lambda expression, use a def (auto-generated noqa) +) # noqa: E731 - do not assign a lambda expression, use a def (auto-generated noqa) -def menu(): # noqa D103: Missing docstring in public function (auto-generated noqa) +def menu(): # noqa: D103 - Missing docstring in public function (auto-generated noqa) lunch = ( lambda: ["ham"] + ["corned beef"] * 7 - ) # noqa E731: do not assign a lambda expression, use a def (auto-generated noqa) + ) # noqa: E731 - do not assign a lambda expression, use a def (auto-generated noqa) return breakfast, lunch try: - raise NotImplemented # noqa F901: 'raise NotImplemented' should be 'raise NotImplementedError' (auto-generated noqa) -except: # noqa E722: do not use bare 'except' (auto-generated noqa) + raise NotImplemented # noqa: F901 - 'raise NotImplemented' should be 'raise NotImplementedError' (auto-generated noqa) +except: # noqa: E722 - do not use bare 'except' (auto-generated noqa) pass -class Cheese_Shop: # noqa D101: Missing docstring in public class (auto-generated noqa) # noqa N801: class name 'Cheese_Shop' should use CapWords convention (auto-generated noqa) - def RequestCheese( # noqa N802: function name 'RequestCheese' should be lowercase (auto-generated noqa) +class Cheese_Shop: # noqa: D101, N801 - Missing docstring in public class (auto-generated noqa), class name 'Cheese_Shop' should use CapWords convention (auto-generated noqa) + def RequestCheese( # noqa: N802 - function name 'RequestCheese' should be lowercase (auto-generated noqa) self, ): """Provide method with bad name.""" @@ -62,19 +62,19 @@ def return_no_cheese_found(self): """Provide method with functional lint errors.""" cheese_found = ( lambda o: False - ) # noqa E731: do not assign a lambda expression, use a def (auto-generated noqa) + ) # noqa: E731 - do not assign a lambda expression, use a def (auto-generated noqa) try: - raise NotImplemented # noqa F901: 'raise NotImplemented' should be 'raise NotImplementedError' (auto-generated noqa) - except: # noqa E722: do not use bare 'except' (auto-generated noqa) + raise NotImplemented # noqa: F901 - 'raise NotImplemented' should be 'raise NotImplementedError' (auto-generated noqa) + except: # noqa: E722 - do not use bare 'except' (auto-generated noqa) pass - l = 5 # noqa E741: ambiguous variable name 'l' (auto-generated noqa) - i = 3 # noqa F841: local variable 'i' is assigned to but never used (auto-generated noqa) + l = 5 # noqa: E741 - ambiguous variable name 'l' (auto-generated noqa) + i = 3 # noqa: F841 - local variable 'i' is assigned to but never used (auto-generated noqa) if ( l - == True # noqa E712: comparison to True should be 'if cond is True:' or 'if cond:' (auto-generated noqa) + == True # noqa: E712 - comparison to True should be 'if cond is True:' or 'if cond:' (auto-generated noqa) ): return False diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/unicode_in_files/output.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/unicode_in_files/output.py index 76444a4c..c4092ede 100644 --- a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/unicode_in_files/output.py +++ b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/unicode_in_files/output.py @@ -14,6 +14,6 @@ def problem_chars(self): return self._problem_chars -def method_withBadName_andParams(my_normal_param, myBadlyNamedParam, my_other_Bad_param): # noqa N803: argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) # noqa N802: function name 'method_withBadName_andParams' should be lowercase (auto-generated noqa) +def method_withBadName_andParams(my_normal_param, myBadlyNamedParam, my_other_Bad_param): # noqa: N803, N802 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa), function name 'method_withBadName_andParams' should be lowercase (auto-generated noqa) """Provide example where black will want to split out result.""" return 5 + 7 diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/unicode_in_files/output__aggressive.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/unicode_in_files/output__aggressive.py index 6e9eedb0..4cefd2d7 100644 --- a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/unicode_in_files/output__aggressive.py +++ b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/unicode_in_files/output__aggressive.py @@ -14,9 +14,9 @@ def problem_chars(self): return self._problem_chars -def method_withBadName_andParams( # noqa N802: function name 'method_withBadName_andParams' should be lowercase (auto-generated noqa) +def method_withBadName_andParams( # noqa: N802 - function name 'method_withBadName_andParams' should be lowercase (auto-generated noqa) my_normal_param, - myBadlyNamedParam, # noqa N803: argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) + myBadlyNamedParam, # noqa: N803 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) my_other_Bad_param, ): """Provide example where black will want to split out result.""" diff --git a/tests/test_cli/fix_test_cases__snapshots/basic_example/input.py b/tests/test_cli/fix_test_cases__snapshots/basic_example/input.py index 25372d48..1768b64d 100644 --- a/tests/test_cli/fix_test_cases__snapshots/basic_example/input.py +++ b/tests/test_cli/fix_test_cases__snapshots/basic_example/input.py @@ -2,7 +2,7 @@ from typing import ( Iterable, List, - Hashable, # noqa F401: un-used import comment that is actually used, should get removed in --aggressive (auto-generated noqa) + Hashable, # noqa: F401 - un-used import comment that is actually used, should get removed in --aggressive (auto-generated noqa) ) import pytest import pathlib diff --git a/tests/test_cli/fix_test_cases__snapshots/basic_example/output.py b/tests/test_cli/fix_test_cases__snapshots/basic_example/output.py index d7b8ae9c..52884603 100644 --- a/tests/test_cli/fix_test_cases__snapshots/basic_example/output.py +++ b/tests/test_cli/fix_test_cases__snapshots/basic_example/output.py @@ -1,7 +1,7 @@ """Provide example cases of imports that need sorting and a file that needs formatted.""" import pathlib from os import access, path -from typing import ( # noqa F401: un-used import comment that is actually used, should get removed in --aggressive (auto-generated noqa) +from typing import ( # noqa: F401 - un-used import comment that is actually used, should get removed in --aggressive (auto-generated noqa) Hashable, ) from typing import Iterable, List From 2752c442e7d3d88e34a773386112eb62747e6d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthew=20Shafer=20=F0=9F=90=8D?= Date: Thu, 27 Apr 2023 09:27:04 -0500 Subject: [PATCH 09/16] handle lint errors --- .../_acknowledge_existing_errors/__init__.py | 6 +++++- ni_python_styleguide/_utils/lint.py | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ni_python_styleguide/_acknowledge_existing_errors/__init__.py b/ni_python_styleguide/_acknowledge_existing_errors/__init__.py index cb21cd97..52054e36 100644 --- a/ni_python_styleguide/_acknowledge_existing_errors/__init__.py +++ b/ni_python_styleguide/_acknowledge_existing_errors/__init__.py @@ -112,7 +112,11 @@ def acknowledge_lint_errors( def _handle_emergent_violations(exclude, app_import_names, extend_ignore, file_or_dir, bad_file): - """Some errors can be created by adding the acknowledge comments (e.g., W505), handle those now.""" + """Some errors can be created by adding the acknowledge comments handle those now. + + Example emergent violations: + W505 -> due to adding comment to docstring + """ current_lint_errors = set( _utils.lint.get_errors_to_process( exclude=exclude, diff --git a/ni_python_styleguide/_utils/lint.py b/ni_python_styleguide/_utils/lint.py index c4749d56..d76746ea 100644 --- a/ni_python_styleguide/_utils/lint.py +++ b/ni_python_styleguide/_utils/lint.py @@ -24,6 +24,8 @@ def get_errors_to_process(exclude, app_import_names, extend_ignore, file_or_dir, class LintError(typing.NamedTuple): + """Class defining a lint error.""" + file: str line: int column: int From 7e52cb44defc1f107bcebd08e1ab90f9ca98f145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthew=20Shafer=20=F0=9F=90=8D?= Date: Thu, 27 Apr 2023 14:06:28 -0500 Subject: [PATCH 10/16] these aren't valid code files that can pass black --- .../blank_file_tests/{output.py => output.py.txt} | 0 .../doc_line_tests/{output.py => output.py.txt} | 0 .../function_signature_tests/{output.py => output.py.txt} | 0 .../import_line_tests/{output.py => output.py.txt} | 0 .../line_continuation_tests/{output.py => output.py.txt} | 0 .../structural_tests/{output.py => output.py.txt} | 0 .../unicode_in_files/{output.py => output.py.txt} | 0 .../basic_example/{output.py => output.py.txt} | 0 .../more_complicated_example/{output.py => output.py.txt} | 0 9 files changed, 0 insertions(+), 0 deletions(-) rename tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/blank_file_tests/{output.py => output.py.txt} (100%) rename tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/doc_line_tests/{output.py => output.py.txt} (100%) rename tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/function_signature_tests/{output.py => output.py.txt} (100%) rename tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/import_line_tests/{output.py => output.py.txt} (100%) rename tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/line_continuation_tests/{output.py => output.py.txt} (100%) rename tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/structural_tests/{output.py => output.py.txt} (100%) rename tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/unicode_in_files/{output.py => output.py.txt} (100%) rename tests/test_cli/fix_test_cases__snapshots/basic_example/{output.py => output.py.txt} (100%) rename tests/test_cli/fix_test_cases__snapshots/more_complicated_example/{output.py => output.py.txt} (100%) diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/blank_file_tests/output.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/blank_file_tests/output.py.txt similarity index 100% rename from tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/blank_file_tests/output.py rename to tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/blank_file_tests/output.py.txt diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/doc_line_tests/output.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/doc_line_tests/output.py.txt similarity index 100% rename from tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/doc_line_tests/output.py rename to tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/doc_line_tests/output.py.txt diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/function_signature_tests/output.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/function_signature_tests/output.py.txt similarity index 100% rename from tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/function_signature_tests/output.py rename to tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/function_signature_tests/output.py.txt diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/import_line_tests/output.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/import_line_tests/output.py.txt similarity index 100% rename from tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/import_line_tests/output.py rename to tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/import_line_tests/output.py.txt diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/line_continuation_tests/output.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/line_continuation_tests/output.py.txt similarity index 100% rename from tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/line_continuation_tests/output.py rename to tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/line_continuation_tests/output.py.txt diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/structural_tests/output.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/structural_tests/output.py.txt similarity index 100% rename from tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/structural_tests/output.py rename to tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/structural_tests/output.py.txt diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/unicode_in_files/output.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/unicode_in_files/output.py.txt similarity index 100% rename from tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/unicode_in_files/output.py rename to tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/unicode_in_files/output.py.txt diff --git a/tests/test_cli/fix_test_cases__snapshots/basic_example/output.py b/tests/test_cli/fix_test_cases__snapshots/basic_example/output.py.txt similarity index 100% rename from tests/test_cli/fix_test_cases__snapshots/basic_example/output.py rename to tests/test_cli/fix_test_cases__snapshots/basic_example/output.py.txt diff --git a/tests/test_cli/fix_test_cases__snapshots/more_complicated_example/output.py b/tests/test_cli/fix_test_cases__snapshots/more_complicated_example/output.py.txt similarity index 100% rename from tests/test_cli/fix_test_cases__snapshots/more_complicated_example/output.py rename to tests/test_cli/fix_test_cases__snapshots/more_complicated_example/output.py.txt From bda5a5c92bda1bee822e73a9471efad1e79004fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthew=20Shafer=20=F0=9F=90=8D?= Date: Thu, 27 Apr 2023 14:06:37 -0500 Subject: [PATCH 11/16] update tests --- tests/test_cli/test_acknowledge_existing_errors.py | 4 ++-- tests/test_cli/test_fix.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_cli/test_acknowledge_existing_errors.py b/tests/test_cli/test_acknowledge_existing_errors.py index ca23cb6b..8473c17d 100644 --- a/tests/test_cli/test_acknowledge_existing_errors.py +++ b/tests/test_cli/test_acknowledge_existing_errors.py @@ -26,7 +26,7 @@ def test_given_bad_input_produces_expected_output_simple( assert output.exit_code in (True, 0), f"Error in running:\n{output}" result = test_file.read_text(encoding="UTF-8") snapshot.snapshot_dir = test_dir - snapshot.assert_match(result, "output.py") + snapshot.assert_match(result, "output.py.txt") @pytest.mark.parametrize( @@ -57,7 +57,7 @@ def test_given_bad_input_produces_expected_output_aggressive( "test_file,additional_args", [ pytest.param( - "output.py", + "output.py.txt", ["--extend-ignore=BLK100"], id="output_ignore_black", ), # we don't suppress BLK100, so it's not one we expect to pass diff --git a/tests/test_cli/test_fix.py b/tests/test_cli/test_fix.py index d609c2a0..9b14b742 100644 --- a/tests/test_cli/test_fix.py +++ b/tests/test_cli/test_fix.py @@ -40,7 +40,7 @@ def test_given_bad_input__fix__produces_expected_output_simple( assert output.exit_code in (True, 0), f"Error in running:\n{output}" result = test_file.read_text(encoding="UTF-8") snapshot.snapshot_dir = test_dir - snapshot.assert_match(result, "output.py") + snapshot.assert_match(result, "output.py.txt") @pytest.mark.parametrize("test_dir", TEST_CASES) From b8542dc552c81a06cd5d23ba2465e58fd5d03a3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthew=20Shafer=20=F0=9F=90=8D?= Date: Thu, 27 Apr 2023 14:07:36 -0500 Subject: [PATCH 12/16] this doesn't get used like we thought it did --- pyproject.toml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 245cde1f..726b789d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,11 +50,7 @@ ni-python-styleguide = 'ni_python_styleguide._cli:main' [tool.black] line-length = 100 -extend-exclude = ''' -( -/.*__snapshots/.*output\.py # exclude the simple snapshot outputs -) -''' + [tool.pytest.ini_options] addopts = "--doctest-modules" From 9cb384a0722f9060afa8d5f7ac2389ffeec35ecd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthew=20Shafer=20=F0=9F=90=8D?= Date: Thu, 27 Apr 2023 14:08:09 -0500 Subject: [PATCH 13/16] make spacing consistent --- pyproject.toml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 726b789d..527c5c02 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,6 +11,7 @@ repository = "https://github.com/ni/python-styleguide" license = "MIT" include = ["ni_python_styleguide/config.toml"] + [tool.poetry.dependencies] python = "^3.7" @@ -24,7 +25,6 @@ click = ">=7.1.2" toml = ">=0.10.1" isort = ">=5.10" - # flake8 plugins should be listed here (in alphabetical order) flake8-black = ">=0.2.1" flake8-docstrings = ">=1.5.0" @@ -40,14 +40,17 @@ pep8-naming = ">=0.11.1" # Tooling that we're locking so our tool can run importlib-metadata = {version= "<5.0", python="<3.8"} + [tool.poetry.dev-dependencies] pytest = ">=6.0.1" pytest_click = ">=1.0.2" pytest-snapshot = ">=0.6.3" + [tool.poetry.scripts] ni-python-styleguide = 'ni_python_styleguide._cli:main' + [tool.black] line-length = 100 @@ -56,9 +59,11 @@ line-length = 100 addopts = "--doctest-modules" norecursedirs = "*__snapshots" + [tool.ni-python-styleguide] extend_exclude = "*__snapshots/*/*input.py" + [build-system] requires = ["poetry>=0.12"] build-backend = "poetry.masonry.api" From c93b1651f335773f65f9038356efa2947bb70804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthew=20Shafer=20=F0=9F=90=8D?= Date: Thu, 27 Apr 2023 14:09:39 -0500 Subject: [PATCH 14/16] bump patch version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 527c5c02..5b9b185c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ name = "ni-python-styleguide" # The -alpha.0 here denotes a source based version # This is removed when released through the Publish-Package.yml GitHub action # Official PyPI releases follow Major.Minor.Patch -version = "0.4.0-alpha.0" +version = "0.4.1-alpha.0" description = "NI's internal and external Python linter rules and plugins" authors = ["NI "] readme = "README.md" # apply the repo readme to the package as well From f982397279e0ef98397d0f4f2f7c754703c92d73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthew=20Shafer=20=F0=9F=90=8D?= Date: Thu, 27 Apr 2023 14:12:31 -0500 Subject: [PATCH 15/16] cleanup leading spaces --- .../_acknowledge_existing_errors/__init__.py | 2 +- .../doc_line_tests/output.py.txt | 2 +- .../doc_line_tests/output__aggressive.py | 2 +- .../function_signature_tests/output.py.txt | 6 +++--- .../function_signature_tests/output__aggressive.py | 2 +- .../import_line_tests/output.py.txt | 4 ++-- .../import_line_tests/output__aggressive.py | 4 ++-- .../line_continuation_tests/output.py.txt | 2 +- .../line_continuation_tests/output__aggressive.py | 2 +- .../structural_tests/output.py.txt | 4 ++-- .../structural_tests/output__aggressive.py | 2 +- .../unicode_in_files/output.py.txt | 2 +- 12 files changed, 17 insertions(+), 17 deletions(-) diff --git a/ni_python_styleguide/_acknowledge_existing_errors/__init__.py b/ni_python_styleguide/_acknowledge_existing_errors/__init__.py index 52054e36..4f052945 100644 --- a/ni_python_styleguide/_acknowledge_existing_errors/__init__.py +++ b/ni_python_styleguide/_acknowledge_existing_errors/__init__.py @@ -28,7 +28,7 @@ def _add_noqa_to_line(lineno, code_lines, error_code, explanation): else: explanation = explanation + " (auto-generated noqa)" - line = f"{code.rstrip()}{prefix}# noqa: {error_code} - {explanation}" + line = f"{code.rstrip()}{prefix}# noqa: {error_code.lstrip()} - {explanation}" code_lines[lineno] = line + old_line_ending diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/doc_line_tests/output.py.txt b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/doc_line_tests/output.py.txt index 98387282..96a1e857 100644 --- a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/doc_line_tests/output.py.txt +++ b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/doc_line_tests/output.py.txt @@ -1,4 +1,4 @@ -def method1(): # noqa: D100, D103 - Missing docstring in public module (auto-generated noqa), Missing docstring in public function (auto-generated noqa) +def method1(): # noqa: D100, D103 - Missing docstring in public module (auto-generated noqa), Missing docstring in public function (auto-generated noqa) return 7 diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/doc_line_tests/output__aggressive.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/doc_line_tests/output__aggressive.py index 98387282..96a1e857 100644 --- a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/doc_line_tests/output__aggressive.py +++ b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/doc_line_tests/output__aggressive.py @@ -1,4 +1,4 @@ -def method1(): # noqa: D100, D103 - Missing docstring in public module (auto-generated noqa), Missing docstring in public function (auto-generated noqa) +def method1(): # noqa: D100, D103 - Missing docstring in public module (auto-generated noqa), Missing docstring in public function (auto-generated noqa) return 7 diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/function_signature_tests/output.py.txt b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/function_signature_tests/output.py.txt index bbcd9d36..ff0c079b 100644 --- a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/function_signature_tests/output.py.txt +++ b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/function_signature_tests/output.py.txt @@ -70,7 +70,7 @@ def method_withBadName_with_parameters_on_multiple_lines(x, y): # noqa: N802 - return x + y -def method_withBadName_with_bad_params_on_single_line(myBadlyNamedParam, my_other_Bad_name): # noqa: N803, N802 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa), function name 'method_withBadName_with_bad_params_on_single_line' should be lowercase (auto-generated noqa) +def method_withBadName_with_bad_params_on_single_line(myBadlyNamedParam, my_other_Bad_name): # noqa: N803, N802 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa), function name 'method_withBadName_with_bad_params_on_single_line' should be lowercase (auto-generated noqa) """Provide parameters with bad names on single line.""" return myBadlyNamedParam + my_other_Bad_name @@ -90,7 +90,7 @@ def method_withBadName_with_bad_params_on_multiple_lines_2( # noqa: N802 - func return myBadlyNamedParam + my_other_Bad_name -def method_withBadName_andParams(my_normal_param, myBadlyNamedParam, my_other_Bad_param): # noqa: N803, N802 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa), function name 'method_withBadName_andParams' should be lowercase (auto-generated noqa) +def method_withBadName_andParams(my_normal_param, myBadlyNamedParam, my_other_Bad_param): # noqa: N803, N802 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa), function name 'method_withBadName_andParams' should be lowercase (auto-generated noqa) """Provide example where black will want to split out result.""" return 5 + 7 @@ -98,5 +98,5 @@ def method_withBadName_andParams(my_normal_param, myBadlyNamedParam, my_other_Ba def method_withBadName_and_bad_param_with_long_name( # noqa: N802 - function name 'method_withBadName_and_bad_param_with_long_name' should be lowercase (auto-generated noqa) my_normal_param, myBadlyNamedParam, my_other_Bad_param # noqa: N803 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) ): - """Provide example where black will want to split out result even more""" # noqa: D415, W505 - First line should end with a period, question mark, or exclamation point (auto-generated noqa), doc line too long (188 > 100 characters) (auto-generated noqa) + """Provide example where black will want to split out result even more""" # noqa: D415, W505 - First line should end with a period, question mark, or exclamation point (auto-generated noqa), doc line too long (188 > 100 characters) (auto-generated noqa) return 5 + 7 diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/function_signature_tests/output__aggressive.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/function_signature_tests/output__aggressive.py index 68ead7c0..a67e6d0c 100644 --- a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/function_signature_tests/output__aggressive.py +++ b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/function_signature_tests/output__aggressive.py @@ -116,5 +116,5 @@ def method_withBadName_and_bad_param_with_long_name( # noqa: N802 - function na myBadlyNamedParam, # noqa: N803 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa) my_other_Bad_param, ): - """Provide example where black will want to split out result even more""" # noqa: D415, W505 - First line should end with a period, question mark, or exclamation point (auto-generated noqa), doc line too long (188 > 100 characters) (auto-generated noqa) + """Provide example where black will want to split out result even more""" # noqa: D415, W505 - First line should end with a period, question mark, or exclamation point (auto-generated noqa), doc line too long (188 > 100 characters) (auto-generated noqa) return 5 + 7 diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/import_line_tests/output.py.txt b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/import_line_tests/output.py.txt index 59227745..2553d338 100644 --- a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/import_line_tests/output.py.txt +++ b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/import_line_tests/output.py.txt @@ -1,7 +1,7 @@ """example of a python file with linter errors. """ -import pathlib, glob # noqa: E401, F401 - multiple imports on one line (auto-generated noqa), 'glob' imported but unused (auto-generated noqa) +import pathlib, glob # noqa: E401, F401 - multiple imports on one line (auto-generated noqa), 'glob' imported but unused (auto-generated noqa) import os # noqa: I100 - Import statements are in the wrong order. 'import os' should be before 'import pathlib, glob' (auto-generated noqa) from os import path # noqa: F401 - 'os.path' imported but unused (auto-generated noqa) from os.path import * # noqa: F403 - 'from os.path import *' used; unable to detect undefined names (auto-generated noqa) @@ -27,4 +27,4 @@ def _test_os_name(): print(os) -import collections # noqa: E402, F401, I100, I202 - module level import not at top of file (auto-generated noqa), 'collections' imported but unused (auto-generated noqa), Import statements are in the wrong order. 'import collections' should be before 'from os.path.lorem.ipsum.dolor.sit.amet.consectetur.adipiscing.elit.sed.do.eiusmod.tempor.incididunt.ut.labore.et.dolore.magna import aliqua, dolor, ipsum, lorem' (auto-generated noqa), Additional newline in a group of imports. 'import collections' is identified as Stdlib and 'from os.path.lorem.ipsum.dolor.sit.amet.consectetur.adipiscing.elit.sed.do.eiusmod.tempor.incididunt.ut.labore.et.dolore.magna import aliqua, dolor, ipsum, lorem' is identified as Stdlib. (auto-generated noqa) +import collections # noqa: E402, F401, I100, I202 - module level import not at top of file (auto-generated noqa), 'collections' imported but unused (auto-generated noqa), Import statements are in the wrong order. 'import collections' should be before 'from os.path.lorem.ipsum.dolor.sit.amet.consectetur.adipiscing.elit.sed.do.eiusmod.tempor.incididunt.ut.labore.et.dolore.magna import aliqua, dolor, ipsum, lorem' (auto-generated noqa), Additional newline in a group of imports. 'import collections' is identified as Stdlib and 'from os.path.lorem.ipsum.dolor.sit.amet.consectetur.adipiscing.elit.sed.do.eiusmod.tempor.incididunt.ut.labore.et.dolore.magna import aliqua, dolor, ipsum, lorem' is identified as Stdlib. (auto-generated noqa) diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/import_line_tests/output__aggressive.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/import_line_tests/output__aggressive.py index f0a3b60d..86fb7361 100644 --- a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/import_line_tests/output__aggressive.py +++ b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/import_line_tests/output__aggressive.py @@ -1,7 +1,7 @@ """example of a python file with linter errors. """ -import pathlib, glob # noqa: E401, F401 - multiple imports on one line (auto-generated noqa), 'glob' imported but unused (auto-generated noqa) +import pathlib, glob # noqa: E401, F401 - multiple imports on one line (auto-generated noqa), 'glob' imported but unused (auto-generated noqa) import os # noqa: I100 - Import statements are in the wrong order. 'import os' should be before 'import pathlib, glob' (auto-generated noqa) from os import path # noqa: F401 - 'os.path' imported but unused (auto-generated noqa) from os.path import * # noqa: F403 - 'from os.path import *' used; unable to detect undefined names (auto-generated noqa) @@ -29,4 +29,4 @@ def _test_os_name(): print(os) -import collections # noqa: E402, F401, I100, I202 - module level import not at top of file (auto-generated noqa), 'collections' imported but unused (auto-generated noqa), Import statements are in the wrong order. 'import collections' should be before 'from os.path.lorem.ipsum.dolor.sit.amet.consectetur.adipiscing.elit.sed.do.eiusmod.tempor.incididunt.ut.labore.et.dolore.magna import aliqua, dolor, ipsum, lorem' (auto-generated noqa), Additional newline in a group of imports. 'import collections' is identified as Stdlib and 'from os.path.lorem.ipsum.dolor.sit.amet.consectetur.adipiscing.elit.sed.do.eiusmod.tempor.incididunt.ut.labore.et.dolore.magna import aliqua, dolor, ipsum, lorem' is identified as Stdlib. (auto-generated noqa) +import collections # noqa: E402, F401, I100, I202 - module level import not at top of file (auto-generated noqa), 'collections' imported but unused (auto-generated noqa), Import statements are in the wrong order. 'import collections' should be before 'from os.path.lorem.ipsum.dolor.sit.amet.consectetur.adipiscing.elit.sed.do.eiusmod.tempor.incididunt.ut.labore.et.dolore.magna import aliqua, dolor, ipsum, lorem' (auto-generated noqa), Additional newline in a group of imports. 'import collections' is identified as Stdlib and 'from os.path.lorem.ipsum.dolor.sit.amet.consectetur.adipiscing.elit.sed.do.eiusmod.tempor.incididunt.ut.labore.et.dolore.magna import aliqua, dolor, ipsum, lorem' is identified as Stdlib. (auto-generated noqa) diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/line_continuation_tests/output.py.txt b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/line_continuation_tests/output.py.txt index 2e778ed5..fb565d0c 100644 --- a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/line_continuation_tests/output.py.txt +++ b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/line_continuation_tests/output.py.txt @@ -1,5 +1,5 @@ some_string_with_line_continuation = f"{installPath}\\foo\\bar\\baz.exe \ - --check --this-is-cool --bacon --ipsum" # noqa: D100, F821 - Missing docstring in public module (auto-generated noqa), undefined name 'installPath' (auto-generated noqa) + --check --this-is-cool --bacon --ipsum" # noqa: D100, F821 - Missing docstring in public module (auto-generated noqa), undefined name 'installPath' (auto-generated noqa) # black, please leave these ridiculous line continuations in place for testing. # fmt: off diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/line_continuation_tests/output__aggressive.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/line_continuation_tests/output__aggressive.py index 2e778ed5..fb565d0c 100644 --- a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/line_continuation_tests/output__aggressive.py +++ b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/line_continuation_tests/output__aggressive.py @@ -1,5 +1,5 @@ some_string_with_line_continuation = f"{installPath}\\foo\\bar\\baz.exe \ - --check --this-is-cool --bacon --ipsum" # noqa: D100, F821 - Missing docstring in public module (auto-generated noqa), undefined name 'installPath' (auto-generated noqa) + --check --this-is-cool --bacon --ipsum" # noqa: D100, F821 - Missing docstring in public module (auto-generated noqa), undefined name 'installPath' (auto-generated noqa) # black, please leave these ridiculous line continuations in place for testing. # fmt: off diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/structural_tests/output.py.txt b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/structural_tests/output.py.txt index 3e5f9467..9148f008 100644 --- a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/structural_tests/output.py.txt +++ b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/structural_tests/output.py.txt @@ -41,7 +41,7 @@ except: # noqa: E722 - do not use bare 'except' (auto-generated noqa) pass -class Cheese_Shop: # noqa: D101, N801 - Missing docstring in public class (auto-generated noqa), class name 'Cheese_Shop' should use CapWords convention (auto-generated noqa) +class Cheese_Shop: # noqa: D101, N801 - Missing docstring in public class (auto-generated noqa), class name 'Cheese_Shop' should use CapWords convention (auto-generated noqa) def RequestCheese(self): # noqa: N802 - function name 'RequestCheese' should be lowercase (auto-generated noqa) """Provide method with bad name.""" pass @@ -58,7 +58,7 @@ class Cheese_Shop: # noqa: D101, N801 - Missing docstring in public class (aut l = 5 # noqa: E741 - ambiguous variable name 'l' (auto-generated noqa) i = 3 # noqa: F841 - local variable 'i' is assigned to but never used (auto-generated noqa) - if l == True: # noqa: E741, E712 - ambiguous variable name 'l' (auto-generated noqa), comparison to True should be 'if cond is True:' or 'if cond:' (auto-generated noqa) + if l == True: # noqa: E741, E712 - ambiguous variable name 'l' (auto-generated noqa), comparison to True should be 'if cond is True:' or 'if cond:' (auto-generated noqa) return False return cheese_found diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/structural_tests/output__aggressive.py b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/structural_tests/output__aggressive.py index 772dfd58..276ae42b 100644 --- a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/structural_tests/output__aggressive.py +++ b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/structural_tests/output__aggressive.py @@ -51,7 +51,7 @@ def menu(): # noqa: D103 - Missing docstring in public function (auto-generated pass -class Cheese_Shop: # noqa: D101, N801 - Missing docstring in public class (auto-generated noqa), class name 'Cheese_Shop' should use CapWords convention (auto-generated noqa) +class Cheese_Shop: # noqa: D101, N801 - Missing docstring in public class (auto-generated noqa), class name 'Cheese_Shop' should use CapWords convention (auto-generated noqa) def RequestCheese( # noqa: N802 - function name 'RequestCheese' should be lowercase (auto-generated noqa) self, ): diff --git a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/unicode_in_files/output.py.txt b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/unicode_in_files/output.py.txt index c4092ede..5aa604a2 100644 --- a/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/unicode_in_files/output.py.txt +++ b/tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/unicode_in_files/output.py.txt @@ -14,6 +14,6 @@ class Foo: return self._problem_chars -def method_withBadName_andParams(my_normal_param, myBadlyNamedParam, my_other_Bad_param): # noqa: N803, N802 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa), function name 'method_withBadName_andParams' should be lowercase (auto-generated noqa) +def method_withBadName_andParams(my_normal_param, myBadlyNamedParam, my_other_Bad_param): # noqa: N803, N802 - argument name 'myBadlyNamedParam' should be lowercase (auto-generated noqa), function name 'method_withBadName_andParams' should be lowercase (auto-generated noqa) """Provide example where black will want to split out result.""" return 5 + 7 From 3985675727fa29e64bcd8266ea6b7da357de4298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthew=20Shafer=20=F0=9F=90=8D?= Date: Thu, 27 Apr 2023 14:17:42 -0500 Subject: [PATCH 16/16] add test that old comment stile is removed on --aggressive --- .../_acknowledge_existing_errors/__init__.py | 2 +- .../fix_test_cases__snapshots/basic_example/input.py | 2 +- .../fix_test_cases__snapshots/basic_example/output.py.txt | 5 ++++- .../more_complicated_example/output__aggressive.py | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ni_python_styleguide/_acknowledge_existing_errors/__init__.py b/ni_python_styleguide/_acknowledge_existing_errors/__init__.py index 4f052945..2a693dc4 100644 --- a/ni_python_styleguide/_acknowledge_existing_errors/__init__.py +++ b/ni_python_styleguide/_acknowledge_existing_errors/__init__.py @@ -35,7 +35,7 @@ def _add_noqa_to_line(lineno, code_lines, error_code, explanation): def _filter_suppresion_from_line(line: str): if "(auto-generated noqa)" in line: - return re.sub(r"# noqa: .+\(auto-generated noqa\)$", "", line).rstrip() + return re.sub(r"# noqa:? .+\(auto-generated noqa\)$", "", line).rstrip() else: return line diff --git a/tests/test_cli/fix_test_cases__snapshots/basic_example/input.py b/tests/test_cli/fix_test_cases__snapshots/basic_example/input.py index 1768b64d..34d452ef 100644 --- a/tests/test_cli/fix_test_cases__snapshots/basic_example/input.py +++ b/tests/test_cli/fix_test_cases__snapshots/basic_example/input.py @@ -1,7 +1,7 @@ """Provide example cases of imports that need sorting and a file that needs formatted.""" from typing import ( Iterable, - List, + List, # noqa F401: un-used import comment that is actually used, should get removed in --aggressive, used to test transition of comment. (auto-generated noqa) Hashable, # noqa: F401 - un-used import comment that is actually used, should get removed in --aggressive (auto-generated noqa) ) import pytest diff --git a/tests/test_cli/fix_test_cases__snapshots/basic_example/output.py.txt b/tests/test_cli/fix_test_cases__snapshots/basic_example/output.py.txt index 52884603..0fa35385 100644 --- a/tests/test_cli/fix_test_cases__snapshots/basic_example/output.py.txt +++ b/tests/test_cli/fix_test_cases__snapshots/basic_example/output.py.txt @@ -4,7 +4,10 @@ from os import access, path from typing import ( # noqa: F401 - un-used import comment that is actually used, should get removed in --aggressive (auto-generated noqa) Hashable, ) -from typing import Iterable, List +from typing import ( # noqa F401: un-used import comment that is actually used, should get removed in --aggressive, used to test transition of comment. (auto-generated noqa) + List, +) +from typing import Iterable import pytest diff --git a/tests/test_cli/fix_test_cases__snapshots/more_complicated_example/output__aggressive.py b/tests/test_cli/fix_test_cases__snapshots/more_complicated_example/output__aggressive.py index 36d8efad..fa4978b1 100644 --- a/tests/test_cli/fix_test_cases__snapshots/more_complicated_example/output__aggressive.py +++ b/tests/test_cli/fix_test_cases__snapshots/more_complicated_example/output__aggressive.py @@ -129,7 +129,7 @@ def fix(exclude, app_import_names, extend_ignore, file_or_dir, *_, aggressive=Fa ) -class ExceptionClassWithBadName( # noqa N818: exception name 'ExceptionClassWithBadName' should be named with an Error suffix (auto-generated noqa) +class ExceptionClassWithBadName( # noqa: N818 - exception name 'ExceptionClassWithBadName' should be named with an Error suffix (auto-generated noqa) Exception ): """Error class with a bad name."""