mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-30 18:56:53 +00:00
Make flake8 actually work
This commit is contained in:
parent
36fb688f97
commit
da21821517
4 changed files with 31 additions and 4 deletions
|
|
@ -137,6 +137,14 @@ class Manager(object):
|
|||
if utils.fnmatch(filename, filename_patterns)
|
||||
]
|
||||
|
||||
def run(self):
|
||||
"""Run checks.
|
||||
|
||||
TODO(sigmavirus24): Get rid of this
|
||||
"""
|
||||
for checker in self.checkers:
|
||||
checker.run_checks()
|
||||
|
||||
def is_path_excluded(self, path):
|
||||
# type: (str) -> bool
|
||||
"""Check if a path is excluded.
|
||||
|
|
@ -210,6 +218,7 @@ class FileChecker(object):
|
|||
|
||||
def run_check(self, plugin, **arguments):
|
||||
"""Run the check in a single plugin."""
|
||||
LOG.debug('Running %r with %r', plugin, arguments)
|
||||
self.processor.keyword_arguments_for(plugin.parameters, arguments)
|
||||
return plugin.execute(**arguments)
|
||||
|
||||
|
|
@ -263,7 +272,7 @@ class FileChecker(object):
|
|||
for token in file_processor.generate_tokens():
|
||||
self.check_physical_eol(token)
|
||||
token_type, text = token[0:2]
|
||||
processor.log_token(token)
|
||||
processor.log_token(LOG, token)
|
||||
if token_type == tokenize.OP:
|
||||
parens = processor.count_parentheses(parens, text)
|
||||
elif parens == 0:
|
||||
|
|
@ -298,7 +307,7 @@ class FileChecker(object):
|
|||
def handle_newline(self, token_type):
|
||||
"""Handle the logic when encountering a newline token."""
|
||||
if token_type == tokenize.NEWLINE:
|
||||
self.check_logical()
|
||||
self.run_logical_checks()
|
||||
self.processor.reset_blank_before()
|
||||
elif len(self.processor.tokens) == 1:
|
||||
# The physical line contains only this token.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
"""Command-line implementation of flake8."""
|
||||
import flake8
|
||||
from flake8 import checker
|
||||
from flake8 import defaults
|
||||
from flake8 import style_guide
|
||||
from flake8.options import aggregator
|
||||
|
|
@ -181,10 +182,11 @@ class Application(object):
|
|||
|
||||
self.check_plugins = None
|
||||
self.listening_plugins = None
|
||||
self.formatting_plugigns = None
|
||||
self.formatting_plugins = None
|
||||
self.formatter = None
|
||||
self.listener_trie = None
|
||||
self.guide = None
|
||||
self.file_checker_manager = None
|
||||
|
||||
self.options = None
|
||||
self.args = None
|
||||
|
|
@ -242,6 +244,17 @@ class Application(object):
|
|||
self.options, self.listener_trie, self.formatter
|
||||
)
|
||||
|
||||
def make_file_checker_manager(self):
|
||||
# type: () -> NoneType
|
||||
"""Initialize our FileChecker Manager."""
|
||||
if self.file_checker_manager is None:
|
||||
self.file_checker_manager = checker.Manager(
|
||||
style_guide=self.guide,
|
||||
arguments=self.args,
|
||||
checker_plugins=self.check_plugins,
|
||||
)
|
||||
self.file_checker_manager.make_checkers()
|
||||
|
||||
def run(self, argv=None):
|
||||
# type: (Union[NoneType, List[str]]) -> NoneType
|
||||
"""Run our application."""
|
||||
|
|
@ -251,6 +264,8 @@ class Application(object):
|
|||
self.make_formatter()
|
||||
self.make_notifier()
|
||||
self.make_guide()
|
||||
self.make_file_checker_manager()
|
||||
self.file_checker_manager.run()
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ class FileProcessor(object):
|
|||
#: Total number of lines in the file
|
||||
self.total_lines = len(self.lines)
|
||||
#: Verbosity level of Flake8
|
||||
self.verbosity = options.verbosity
|
||||
self.verbosity = options.verbose
|
||||
|
||||
@contextlib.contextmanager
|
||||
def inside_multiline(self, line_number):
|
||||
|
|
@ -302,10 +302,12 @@ def token_is_comment(token):
|
|||
|
||||
def count_parentheses(current_parentheses_count, token_text):
|
||||
"""Count the number of parentheses."""
|
||||
current_parentheses_count = current_parentheses_count or 0
|
||||
if token_text in '([{':
|
||||
return current_parentheses_count + 1
|
||||
elif token_text in '}])':
|
||||
return current_parentheses_count - 1
|
||||
return current_parentheses_count
|
||||
|
||||
|
||||
def log_token(log, token):
|
||||
|
|
|
|||
1
setup.py
1
setup.py
|
|
@ -71,6 +71,7 @@ setuptools.setup(
|
|||
'console_scripts': ['flake8 = flake8.main.cli:main'],
|
||||
'flake8.extension': [
|
||||
'F = flake8.plugins.pyflakes:FlakesChecker',
|
||||
'pep8.tabs_or_spaces = pep8:tabs_or_spaces',
|
||||
],
|
||||
'flake8.report': [
|
||||
'default = flake8.formatting.default:Default',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue