Merge branch 'noqa_without_space_470' into 'master'

Accept Noqa without space

Closes #470

See merge request pycqa/flake8!273
This commit is contained in:
Anthony Sottile 2018-12-27 16:54:47 +00:00
commit d3d1b19aec
3 changed files with 14 additions and 1 deletions

View file

@ -28,12 +28,15 @@ 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<codes>([A-Z][0-9]+(?:[,\s]+)?)+))?",
# https://regex101.com/r/4XUuax/2 full explenation of the regex
r"# noqa(?::[\s]?(?P<codes>([A-Z][0-9]+(?:[,\s]+)?)+))?",
re.IGNORECASE,
)

View file

@ -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."""

View file

@ -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``."""