def lint(filename, settings): """ Run flake8 lint with internal interpreter. """ # check if active view contains file if not filename or not os.path.exists(filename): return # skip file check if 'noqa' for whole file is set if util.skip_file(filename): return # place for warnings =) warnings = [] # lint with pyflakes if settings.get('pyflakes', True): warnings.extend(pyflakes.checkPath(filename)) # lint with pep8 if settings.get('pep8', True): pep8style = pep8.StyleGuide(reporter=Pep8Report) pep8style.input_file(filename) warnings.extend(pep8style.options.report.errors) # check complexity complexity = settings.get('complexity', -1) if complexity > -1: warnings.extend(mccabe.get_module_complexity(filename, complexity)) return warnings
def lint(filename, settings): """ Run flake8 lint with internal interpreter. """ # check if active view contains file if not filename or not os.path.exists(filename): return # skip file check if 'noqa' for whole file is set if util.skip_file(filename): return # place for warnings =) warnings = [] # lint with pyflakes if settings.get('pyflakes', True): warnings.extend(pyflakes.checkPath(filename)) # lint with pep8 if settings.get('pep8', True): pep8style = pep8.StyleGuide( reporter=Pep8Report, ignore=settings.get('ignore', []), max_line_length=settings.get('pep8_max_line_length')) pep8style.input_file(filename) warnings.extend(pep8style.options.report.errors) # check complexity complexity = settings.get('complexity', -1) if complexity > -1: warnings.extend(mccabe.get_module_complexity(filename, complexity)) return warnings
def run(self, edit): """ Run flake8 lint. """ # current file name filename = self.view.file_name() # check if active view contains file if not filename: return # check only Python or cython files if not (self.view.match_selector(0, 'source.python') or self.view.match_selector(0, 'source.cython')): return # save file if dirty if self.view.is_dirty(): self.view.run_command('save') # place for warnings =) warnings = [] # lint with pyflakes if settings.get('pyflakes', True) and not self.view.match_selector( 0, 'source.cython'): warnings.extend(pyflakes.checkPath(filename)) # lint with pep8 if settings.get('pep8', True): settings_postfix = "_cython" if self.view.match_selector( 0, 'source.cython') else "" pep8style = pep8.StyleGuide( select=settings.get('select' + settings_postfix, []), ignore=settings.get('ignore' + settings_postfix, []), reporter=Pep8Report) pep8style.input_file(filename) warnings.extend(pep8style.options.report.errors) # check complexity complexity = settings.get('complexity', -1) if complexity > -1: warnings.extend(mccabe.get_module_complexity(filename, complexity)) # show errors if warnings: self.warnings = warnings self.show_errors()
def run(self, edit): """ Run flake8 lint. """ # current file name filename = self.view.file_name() # check if active view contains file if not filename: return # check only Python or cython files if not (self.view.match_selector(0, 'source.python') or self.view.match_selector(0, 'source.cython')): return # save file if dirty if self.view.is_dirty(): self.view.run_command('save') # place for warnings =) warnings = [] # lint with pyflakes if settings.get('pyflakes', True) and not self.view.match_selector(0, 'source.cython'): warnings.extend(pyflakes.checkPath(filename)) # lint with pep8 if settings.get('pep8', True): settings_postfix = "_cython" if self.view.match_selector(0, 'source.cython') else "" pep8style = pep8.StyleGuide( select=settings.get('select' + settings_postfix, []), ignore=settings.get('ignore' + settings_postfix, []), reporter=Pep8Report ) pep8style.input_file(filename) warnings.extend(pep8style.options.report.errors) # check complexity complexity = settings.get('complexity', -1) if complexity > -1: warnings.extend(mccabe.get_module_complexity(filename, complexity)) # show errors if warnings: self.warnings = warnings self.show_errors()