mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-30 10:46:54 +00:00
Add ability to check if a file is ignored inline
Check for ``# flake8: noqa`` lines inside a file.
This commit is contained in:
parent
2c17b4342f
commit
daf5c4d80d
2 changed files with 19 additions and 0 deletions
|
|
@ -291,6 +291,9 @@ class FileChecker(object):
|
|||
|
||||
def run_checks(self):
|
||||
"""Run checks against the file."""
|
||||
if self.processor.should_ignore_file():
|
||||
return
|
||||
|
||||
try:
|
||||
self.process_tokens()
|
||||
except exceptions.InvalidSyntax as exc:
|
||||
|
|
|
|||
|
|
@ -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."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue