Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def next_line(self): # type: () -> str
"""Get the next line from the list."""
if self.line_number >= self.total_lines:
return ""
line = self.lines[self.line_number]
self.line_number += 1
if self.indent_char is None and line[:1] in defaults.WHITESPACE:
self.indent_char = line[0]
return line
parse_from_config=True,
help="Print total number of errors and warnings to standard error and"
" set the exit code to 1 if total is not empty.",
)
add_option(
"--diff",
action="store_true",
help="Report changes only within line number ranges in the unified "
"diff provided on standard in by the user.",
)
add_option(
"--exclude",
metavar="patterns",
default=",".join(defaults.EXCLUDE),
comma_separated_list=True,
parse_from_config=True,
normalize_paths=True,
help="Comma-separated list of files or directories to exclude."
" (Default: %(default)s)",
)
add_option(
"--extend-exclude",
metavar="patterns",
default="",
parse_from_config=True,
comma_separated_list=True,
help="Comma-separated list of files or directories to add to the list"
" of excluded ones.",
)
self.selected = tuple(options.select)
self.extended_selected = tuple(
sorted(options.extended_default_select, reverse=True)
)
self.enabled_extensions = tuple(options.enable_extensions)
self.all_selected = tuple(
sorted(self.selected + self.enabled_extensions, reverse=True)
)
self.ignored = tuple(
sorted(
itertools.chain(options.ignore, options.extend_ignore),
reverse=True,
)
)
self.using_default_ignore = set(self.ignored) == set(defaults.IGNORE)
self.using_default_select = set(self.selected) == set(defaults.SELECT)
def build_logical_line(self):
"""Build a logical line from the current tokens list."""
comments, logical, mapping_list = self.build_logical_line_tokens()
joined_comments = ''.join(comments)
self.logical_line = ''.join(logical)
if defaults.NOQA_INLINE_REGEXP.search(joined_comments):
self.noqa = True
self.statistics['logical lines'] += 1
return joined_comments, self.logical_line, mapping_list
def report_benchmarks(self):
"""Aggregate, calculate, and report benchmarks for this run."""
if not self.options.benchmark:
return
time_elapsed = self.end_time - self.start_time
statistics = [("seconds elapsed", time_elapsed)]
add_statistic = statistics.append
for statistic in defaults.STATISTIC_NAMES + ("files",):
value = self.file_checker_manager.statistics[statistic]
total_description = "total " + statistic + " processed"
add_statistic((total_description, value))
per_second_description = statistic + " processed per second"
add_statistic((per_second_description, int(value / time_elapsed)))
self.formatter.show_benchmarks(statistics)
self.cache = {} # type: Dict[str, Decision]
self.selected = tuple(options.select)
self.extended_selected = tuple(
sorted(options.extended_default_select, reverse=True)
)
self.enabled_extensions = tuple(options.enable_extensions)
self.all_selected = tuple(
sorted(self.selected + self.enabled_extensions, reverse=True)
)
self.ignored = tuple(
sorted(
itertools.chain(options.ignore, options.extend_ignore),
reverse=True,
)
)
self.using_default_ignore = set(self.ignored) == set(defaults.IGNORE)
self.using_default_select = set(self.selected) == set(defaults.SELECT)
)
add_option(
'--count', action='store_true', parse_from_config=True,
help='Print total number of errors and warnings to standard error and'
' set the exit code to 1 if total is not empty.',
)
add_option(
'--diff', action='store_true',
help='Report changes only within line number ranges in the unified '
'diff provided on standard in by the user.',
)
add_option(
'--exclude', metavar='patterns', default=defaults.EXCLUDE,
comma_separated_list=True, parse_from_config=True,
normalize_paths=True,
help='Comma-separated list of files or directories to exclude.'
' (Default: %default)',
)
add_option(
'--filename', metavar='patterns', default='*.py',
parse_from_config=True, comma_separated_list=True,
help='Only check for filenames matching the patterns in this comma-'
'separated list. (Default: %default)',
)
add_option(
'--stdin-display-name',
help='The name used when reporting errors from code passed via stdin.'
def report_benchmarks(self):
"""Aggregate, calculate, and report benchmarks for this run."""
if not self.options.benchmark:
return
time_elapsed = self.end_time - self.start_time
statistics = [("seconds elapsed", time_elapsed)]
add_statistic = statistics.append
for statistic in defaults.STATISTIC_NAMES + ("files",):
value = self.file_checker_manager.statistics[statistic]
total_description = "total " + statistic + " processed"
add_statistic((total_description, value))
per_second_description = statistic + " processed per second"
add_statistic((per_second_description, int(value / time_elapsed)))
self.formatter.show_benchmarks(statistics)
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:`defaults.NOQA_FILE`,
otherwise False
:rtype:
bool
"""
if not self.options.disable_noqa and any(
defaults.NOQA_FILE.match(line) for line in self.lines
):
return True
elif any(defaults.NOQA_FILE.search(line) for line in self.lines):
LOG.warning(
"Detected `flake8: noqa` on line with code. To ignore an "
"error on a line use `noqa` instead."
)
return False
else:
return False
def config_for(parameter):
environment_variable = "flake8_{0}".format(parameter).upper()
git_variable = "flake8.{0}".format(parameter)
value = os.environ.get(environment_variable, git_config_for(git_variable))
return value.lower() in defaults.TRUTHY_VALUES