Skip to content

Flake8 plugin does not check content of unsaved buffer  #743

Closed
@will133

Description

@will133

It seems like the way the plugin is written it uses the document.path in the flake8 argument to check for errors:

args = build_args(opts, document.path)
output = run_flake8(args)
return parse_stdout(document, output)

Where pycodestyle would actually use the document.lines instead:

c = pycodestyle.Checker(
filename=document.uri, lines=document.lines, options=styleguide.options,
report=PyCodeStyleDiagnosticReport(styleguide.options)

This seems wrong as the flake8 check would ignore the update to the current buffer and always check what is written to disk. From the editor, you basically see all the signs/error lines to be incorrect.

For example, I'm using vim and use vim-lsp-settings, I have a configuration like:

    let g:lsp_settings['pyls'] = {
    \    'workspace_config': {'pyls': {'plugins': {
    \      'flake8': {'enabled': v:true,},
    \      'pycodestyle': {'enabled': v:false,},
    \      'pyflakes': {'enabled': v:false},
    \      'mccabe': {'enabled': v:false},
    \    }}}
    \  }

Say if you have a test.py file with this:

print(y)

Save the file and edit again, you'd see the line is flagged as error.

However, if you insert the line above it and add another print:

print(x)
print(y)

The result is that the error would still only appear on line 1 and NOT both lines since flake8 is run on the file saved on disk. It does not pipe the buffer to it instead.

Flake8 can read from stdin so it should be possible to pipe the lines to the checker. For instance:

cat test.py | flake8 -

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions