From 8c9c462154d3971d9f1ed6e6d38098845d8901a1 Mon Sep 17 00:00:00 2001 From: Tomer Keren Date: Thu, 27 Dec 2018 18:07:04 +0200 Subject: [PATCH 1/3] Add tests for noqa without a space --- tests/unit/test_file_processor.py | 4 ++++ tests/unit/test_violation.py | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/tests/unit/test_file_processor.py b/tests/unit/test_file_processor.py index 0c2dc99..7d64f6e 100644 --- a/tests/unit/test_file_processor.py +++ b/tests/unit/test_file_processor.py @@ -69,9 +69,13 @@ def test_strip_utf_bom(first_line): ([u'\uFEFF"""Module docstring."""\n'], False), (['#!/usr/bin/python', '# flake8 is great', 'a = 1'], False), (['#!/usr/bin/python', '# flake8: noqa', 'a = 1'], True), + (['#!/usr/bin/python', '# flake8:noqa', 'a = 1'], True), (['# flake8: noqa', '#!/usr/bin/python', 'a = 1'], True), + (['# flake8:noqa', '#!/usr/bin/python', 'a = 1'], True), (['#!/usr/bin/python', 'a = 1', '# flake8: noqa'], True), + (['#!/usr/bin/python', 'a = 1', '# flake8:noqa'], True), (['#!/usr/bin/python', 'a = 1 # flake8: noqa'], False), + (['#!/usr/bin/python', 'a = 1 # flake8:noqa'], False), ]) def test_should_ignore_file(lines, expected): """Verify that we ignore a file if told to.""" diff --git a/tests/unit/test_violation.py b/tests/unit/test_violation.py index c4b56b1..e29d874 100644 --- a/tests/unit/test_violation.py +++ b/tests/unit/test_violation.py @@ -13,10 +13,16 @@ from flake8 import style_guide ('W123', 'a = 1 # noqa: E111,W123,F821', True), ('W123', 'a = 1 # noqa: E111, W123,F821', True), ('E111', 'a = 1 # noqa: E11,W123,F821', True), + ('E121', 'a = 1 # noqa:E111,W123,F821', False), + ('E111', 'a = 1 # noqa:E111,W123,F821', True), + ('W123', 'a = 1 # noqa:E111,W123,F821', True), + ('W123', 'a = 1 # noqa:E111, W123,F821', True), + ('E111', 'a = 1 # noqa:E11,W123,F821', True), ('E111', 'a = 1 # noqa, analysis:ignore', True), ('E111', 'a = 1 # noqa analysis:ignore', True), ('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), ]) def test_is_inline_ignored(error_code, physical_line, expected_result): """Verify that we detect inline usage of ``# noqa``.""" From 08492ee857a16a1f6d3b942456de7010e3f0d03f Mon Sep 17 00:00:00 2001 From: Tomer Keren Date: Thu, 27 Dec 2018 18:18:52 +0200 Subject: [PATCH 2/3] Update regex to allow no space noqa --- src/flake8/defaults.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/flake8/defaults.py b/src/flake8/defaults.py index ec68067..1b5d091 100644 --- a/src/flake8/defaults.py +++ b/src/flake8/defaults.py @@ -28,12 +28,14 @@ NOQA_INLINE_REGEXP = re.compile( # ``# noqa`` # ``# noqa: E123`` # ``# noqa: E123,W451,F921`` + # ``# noqa:E123,W451,F921`` # ``# NoQA: E123,W451,F921`` # ``# NOQA: E123,W451,F921`` + # ``# NOQA: E123,W451,F921`` # We do not want to capture the ``: `` that follows ``noqa`` # We do not care about the casing of ``noqa`` # We want a comma-separated list of errors - r"# noqa(?:: (?P([A-Z][0-9]+(?:[,\s]+)?)+))?", + r"# noqa(?::[\s]?(?P([A-Z][0-9]+(?:[,\s]+)?)+))?", re.IGNORECASE, ) From 445d19b9de7cd87138a4d4fb07e666720625c484 Mon Sep 17 00:00:00 2001 From: Tomer Keren Date: Thu, 27 Dec 2018 18:28:08 +0200 Subject: [PATCH 3/3] Add link to regex101 for noqa regex This provides a step by step doc for the regular expression, and makes iterating on it much easier --- src/flake8/defaults.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/flake8/defaults.py b/src/flake8/defaults.py index 1b5d091..22304a9 100644 --- a/src/flake8/defaults.py +++ b/src/flake8/defaults.py @@ -35,6 +35,7 @@ NOQA_INLINE_REGEXP = re.compile( # We do not want to capture the ``: `` that follows ``noqa`` # 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]+)?)+))?", re.IGNORECASE, )