How to use the flake8.defaults function in flake8

To help you get started, we’ve selected a few flake8 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PyCQA / flake8 / src / flake8 / processor.py View on Github external
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
github PyCQA / flake8 / src / flake8 / main / options.py View on Github external
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.",
    )
github PyCQA / flake8 / src / flake8 / style_guide.py View on Github external
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)
github PyCQA / flake8 / src / flake8 / processor.py View on Github external
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
github PyCQA / flake8 / src / flake8 / main / application.py View on Github external
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)
github PyCQA / flake8 / src / flake8 / style_guide.py View on Github external
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)
github PyCQA / flake8 / src / flake8 / main / options.py View on Github external
)

    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.'
github PyCQA / flake8 / src / flake8 / main / application.py View on Github external
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)
github PyCQA / flake8 / src / flake8 / processor.py View on Github external
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
github PyCQA / flake8 / src / flake8 / main / git.py View on Github external
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