def METHOD_NAME(workspace, document):
    with workspace.report_progress("lint: flake8"):
        config = workspace._config
        settings = config.plugin_settings('flake8', document_path=document.path)
        log.debug("Got flake8 settings: %s", settings)
        ignores = settings.get("ignore", [])
        per_file_ignores = settings.get("perFileIgnores")
        if per_file_ignores:
            prev_file_pat = None
            for path in per_file_ignores:
                try:
                    file_pat, errors = path.split(":")
                    prev_file_pat = file_pat
                except ValueError:
                    # It's legal to just specify another error type for the same
                    # file pattern:
                    if prev_file_pat is None:
                        log.warning(
                            "skipping a Per-file-ignore with no file pattern")
                        continue
                    file_pat = prev_file_pat
                    errors = path
                if PurePath(document.path).match(file_pat):
                    ignores.extend(errors.split(","))
        opts = {
            'config': settings.get('config'),
            'exclude': settings.get('exclude'),
            'filename': settings.get('filename'),
            'hang-closing': settings.get('hangClosing'),
            'ignore': ignores or None,
            'max-complexity': settings.get('maxComplexity'),
            'max-line-length': settings.get('maxLineLength'),
            'indent-size': settings.get('indentSize'),
            'select': settings.get('select'),
        }
        # flake takes only absolute path to the config. So we should check and
        # convert if necessary
        if opts.get('config') and not os.path.isabs(opts.get('config')):
            opts['config'] = os.path.abspath(os.path.expanduser(os.path.expandvars(
                opts.get('config')
            )))
            log.debug("using flake8 with config: %s", opts['config'])
        # Call the flake8 utility then parse diagnostics from stdout
        flake8_executable = settings.get('executable', 'flake8')
        args = build_args(opts)
        output = run_flake8(flake8_executable, args, document)
        return parse_stdout(document, output)