Skip to content

Commit

Permalink
Merge branch 'flake8_noqa_line_by_self' into 'master'
Browse files Browse the repository at this point in the history
Only skip a file if `# flake8: noqa` is on a line by itself

See merge request pycqa/flake8!219
  • Loading branch information
sigmavirus24 committed Jul 1, 2018
2 parents eb6228b + e730554 commit 9631dac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/flake8/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def __init__(self, filename, options, lines=None):

@property
def file_tokens(self):
"""The complete set of tokens for a file.
"""Return the complete set of tokens for a file.
Accessing this attribute *may* raise an InvalidSyntax exception.
Expand Down Expand Up @@ -334,16 +334,24 @@ def read_lines_from_stdin(self):

def should_ignore_file(self):
# type: () -> bool
"""Check if ``# flake8: noqa`` is in the file to be ignored.
"""Check if ``flake8: noqa`` is in the file to be ignored.
:returns:
True if a line matches :attr:`defaults.NOQA_FILE`,
otherwise False
:rtype:
bool
"""
ignore_file = defaults.NOQA_FILE.search
return any(ignore_file(line) for line in self.lines)
if any(defaults.NOQA_FILE.match(line) for line in self.lines):
return True
elif any(defaults.NOQA_FILE.search(line) for line in self.lines):
LOG.warning(
'Detected `flake8: noqa` on line with code. To ignore an '
'error on a line use `noqa` instead.',
)
return False
else:
return False

def strip_utf_bom(self):
# type: () -> NoneType
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_file_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def test_strip_utf_bom(first_line):
(['#!/usr/bin/python', '# flake8: noqa', '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'], False),
])
def test_should_ignore_file(lines, expected):
"""Verify that we ignore a file if told to."""
Expand Down

0 comments on commit 9631dac

Please sign in to comment.