diff options
| author | Leonardo Rochael Almeida <leorochael@gmail.com> | 2016-07-20 16:43:34 -0300 |
|---|---|---|
| committer | Leonardo Rochael Almeida <leorochael@gmail.com> | 2016-07-20 18:45:01 -0300 |
| commit | b2b4cae8e3ef27b8545a8d98a35dc7b07b1b132f (patch) | |
| tree | 74530cf6d656d52804b83f6eb03756f15da41219 /src/flake8/checker.py | |
| parent | d69cb0564ada817b1cda5af49a552684466eb2dc (diff) | |
| download | flake8-b2b4cae8e3ef27b8545a8d98a35dc7b07b1b132f.tar.gz | |
Allow stdin and directly named files to be excluded from check
For the sake of IDEs, check filename for exclusion even if the file is directly
named in the command line.
Also, if the filename is "-" (stdin) check the provided display name for
exclusion.
Also, avoid calling path checking functions on the "-" filename:
* fnmatch.fnmatch()
* os.path.isdir()
* os.path.exists()
Diffstat (limited to 'src/flake8/checker.py')
| -rw-r--r-- | src/flake8/checker.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/flake8/checker.py b/src/flake8/checker.py index f7bd540..d5132ff 100644 --- a/src/flake8/checker.py +++ b/src/flake8/checker.py @@ -237,6 +237,12 @@ class Manager(object): exclude = self.options.exclude if not exclude: return False + if path == '-': + # stdin, use display name to check exclusion, if present + path = self.options.stdin_display_name + if path is None: + LOG.debug("unnamed stdin has not been excluded") + return False basename = os.path.basename(path) if utils.fnmatch(basename, exclude): LOG.debug('"%s" has been excluded', basename) @@ -263,12 +269,11 @@ class Manager(object): # best solution right now. def should_create_file_checker(filename): """Determine if we should create a file checker.""" - matches_filename_patterns = utils.fnmatch( - filename, filename_patterns + return ( + filename == '-' or # stdin + utils.fnmatch(filename, filename_patterns) and + os.path.exists(filename) ) - is_stdin = filename == '-' - file_exists = os.path.exists(filename) - return (file_exists and matches_filename_patterns) or is_stdin self.checkers = [ FileChecker(filename, self.checks, self.style_guide) |
