diff options
| author | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-03-14 20:23:03 -0500 |
|---|---|---|
| committer | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-03-14 20:23:03 -0500 |
| commit | daf5c4d80d576b23d4b43feee356b736a216573d (patch) | |
| tree | 8dce1e7207c40e30225236a6d5c7d9749530ee51 /flake8/processor.py | |
| parent | 2c17b4342f8a6f24d0e034b322cefec4f7f5d5df (diff) | |
| download | flake8-daf5c4d80d576b23d4b43feee356b736a216573d.tar.gz | |
Add ability to check if a file is ignored inline
Check for ``# flake8: noqa`` lines inside a file.
Diffstat (limited to 'flake8/processor.py')
| -rw-r--r-- | flake8/processor.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/flake8/processor.py b/flake8/processor.py index 52d7ab1..f2f5b00 100644 --- a/flake8/processor.py +++ b/flake8/processor.py @@ -1,6 +1,7 @@ """Module containing our file processor that tokenizes a file for checks.""" import contextlib import io +import re import sys import tokenize @@ -41,6 +42,8 @@ class FileProcessor(object): - verbose """ + NOQA_FILE = re.compile(r'\s*# flake8[:=]\s*noqa', re.I) + def __init__(self, filename, options): """Initialice our file processor. @@ -269,6 +272,19 @@ class FileProcessor(object): """Read the lines from standard in.""" return utils.stdin_get_value().splitlines(True) + def should_ignore_file(self): + # type: () -> bool + """Check if ``# flake8: noqa`` is in the file to be ignored. + + :returns: + True if a line matches :attr:`FileProcessor.NOQA_FILE`, + otherwise False + :rtype: + bool + """ + ignore_file = self.NOQA_FILE.search + return any(ignore_file(line) for line in self.lines) + def strip_utf_bom(self): # type: () -> NoneType """Strip the UTF bom from the lines of the file.""" |
