From 0ac337608b3d88079aa91bdcffed7b4df6fd28a8 Mon Sep 17 00:00:00 2001 From: Markus Piotrowski Date: Sun, 16 Jun 2019 15:55:37 +0000 Subject: [PATCH 1/2] This PR addresses issue #549 (noqa does only work as intended with single letter error codes). A single change in the regex `NOQA_INLINE_REGEXP` in `defaults.py` will allow to catch error codes which consist of more than one letter. This will close #549. --- src/flake8/defaults.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flake8/defaults.py b/src/flake8/defaults.py index 3fff376..72452a7 100644 --- a/src/flake8/defaults.py +++ b/src/flake8/defaults.py @@ -36,7 +36,7 @@ NOQA_INLINE_REGEXP = re.compile( # We do not care about the casing of ``noqa`` # We want a comma-separated list of errors # https://regex101.com/r/4XUuax/2 full explenation of the regex - r"# noqa(?::[\s]?(?P([A-Z][0-9]+(?:[,\s]+)?)+))?", + r"# noqa(?::[\s]?(?P([A-Z]+[0-9]+(?:[,\s]+)?)+))?", re.IGNORECASE, ) From 37964dbd848c89e0acdef7d5ea0bf812539f852c Mon Sep 17 00:00:00 2001 From: Markus Piotrowski Date: Sun, 16 Jun 2019 17:02:54 +0000 Subject: [PATCH 2/2] Update test_violation.py Added tests to check if long error codes are correctly identified. --- tests/unit/test_violation.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/unit/test_violation.py b/tests/unit/test_violation.py index e29d874..a3a56f0 100644 --- a/tests/unit/test_violation.py +++ b/tests/unit/test_violation.py @@ -23,6 +23,9 @@ from flake8 import style_guide ('E111', 'a = 1 # noqa - We do not care', True), ('E111', 'a = 1 # noqa: We do not care', True), ('E111', 'a = 1 # noqa:We do not care', True), + ('ABC123', 'a = 1 # noqa: ABC123', True), + ('E111', 'a = 1 # noqa: ABC123', False), + ('ABC123', 'a = 1 # noqa: ABC124', False), ]) def test_is_inline_ignored(error_code, physical_line, expected_result): """Verify that we detect inline usage of ``# noqa``."""