Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flake8 more native support #18261

Closed
1 task done
Niccolum opened this issue Jan 7, 2022 · 11 comments
Closed
1 task done

Flake8 more native support #18261

Niccolum opened this issue Jan 7, 2022 · 11 comments
Assignees
Labels
area-linting community ask Feature request that the community expressed interest in feature-request Request for new features or functionality needs proposal Need to make some design decisions

Comments

@Niccolum
Copy link

Niccolum commented Jan 7, 2022

Good day. Thank you for your work with that beautiful plugin and vscode at all.

I newbie with vscode, but I found, that your plugin match only F, W and E error codes. I use a lot of flake8 plugins, which have another letter (or letters) for codes. Have you any plans to support absolutely custom codes, as user want? For example, dict with code: level match:

flake8CategorySeverity: {
    "F": "error",
    "FF": "warning",
    "FOO": "info",
    "BAR": "none",
}

Logs

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Niccolum Niccolum added triage-needed Needs assignment to the proper sub-team feature-request Request for new features or functionality labels Jan 7, 2022
@karthiknadig karthiknadig added area-linting needs community feedback Awaiting community feedback and removed triage-needed Needs assignment to the proper sub-team labels Jan 10, 2022
@karthiknadig karthiknadig self-assigned this Jan 10, 2022
@karthiknadig
Copy link
Member

Thanks for the feature request! We are going to give the community 60 days from when this issue was created to provide 7 👍 upvotes on the opening comment to gauge general interest in this idea. If there's enough upvotes then we will consider this feature request in our future planning. If there's unfortunately not enough upvotes then we will close this issue.

@Niccolum
Copy link
Author

Niccolum commented Jan 10, 2022

@karthiknadig I've asked rude russian python community (yes, it exists :) ) about this feature, and, as I see, community supports this :)

@karthiknadig
Copy link
Member

Related #17235

@karthiknadig
Copy link
Member

We have a prototype for flake8 behind LSP that adds ability to control severity by error code. Instructions to get it and use it are here: PyCQA/flake8#1467 (comment)

Please leave your feedback on this here: #17235

@Niccolum
Copy link
Author

Niccolum commented Feb 11, 2022

@karthiknadig I'll check in a few days. Is it works together with python extension? Can I add flake8 plugin to LSP flake8?

@karthiknadig
Copy link
Member

the flake8 extension can work with the python extension. By default, it uses flake8 that you have installed in your environment, if that flake8 has plugins it should work. If you don't have flake8 installed, it will use the bundled flake8. You can also use a path to a flake8 binary if you prefer to use a global flake8.

You may want to disable linting with python extension, or you will see two items for each linting issue.

@Niccolum
Copy link
Author

Niccolum commented Feb 12, 2022

@karthiknadig

1 case:

  • Install flake8 extension.
  • Create file with with suggested content

Expected:

F401, E302, E305 error, W292 warning

Actual:

same

Status:

OK

case 2:

  • Create file with with suggested content
  • add next settings:
    "python.flake8Severity":{
        "W": "Error",
    }

Expected:

W292 error

Actual:

F401, E302, E305 W292 error

Status:

Default settings override custom, if it not set. Not expected.

case 3:

  • Create file with with suggested content
  • add next settings:
    "python.flake8Severity":{
        "W": "Error",
        "E": "Hint",
        "F": "Hint",
    }

Expected:

W292 error

Actual:

same

Status:

OK

case 4

  • Create file with with suggested content
  • add next settings:
    "python.flake8Severity":{
        "W": "Hint",
        "E302": "Error",
        "E": "Hint",
        "F": "Hint",
    }

Expected:

E302 error

Actual:

same

Status:

OK

case 5

  • Create file with with suggested content
  • added line
    from os import * # for F403
  • add .flake8 config:
[flake8]
select=
    F401,
  • add next settings:
    "python.flake8Severity":{
        "W": "Hint",
        "E": "Hint",
        "F": "Error",
    }

Expected:

F403 error

Actual:

same

Status:

OK

case 6

  • Create file with with suggested content
  • added linefrom os import *
  • add .flake8 config:
[flake8]
ignore=
    F403,
  • add next settings:
    "python.flake8Severity":{
        "W": "Hint",
        "E": "Hint",
        "F": "Error",
    }

Expected:

F401 F401 error

Actual:

same

Status:

OK

case 7

  • Create file with with suggested content
  • added linefrom os import *
  • add .flake8 config:
[flake8]
select=
    F,

ignore=
    F403,
  • add next settings:
    "python.flake8Severity":{
        "W": "Hint",
        "E": "Hint",
        "F": "Error",
    }

Expected:

F401 F401 error

Actual:

same

Status:

OK

case 8

  • Create file with with suggested content
  • install flake8

Expected:

F401, E302, E305 error, W292 warning

Actual:

F401, F401, E302, E302, E305, E305 error, W292, W292 warning

Status:

Duplicate codes, if flake8 installed locally

case 9

  • Create file with with suggested content
  • install flake8
  • add next settings:
    {
        "python.flake8Path": ["${workspaceFolder}/venv/bin/flake8"]
    }

Expected:

F401, E302, E305 error, W292 warning

Actual:

same

Status:

OK, if flake8Path set manually

case 10:

  • Create file with with suggested content
  • install flake8
  • add next settings:
{
    "python.flake8Path": ["${workspaceFolder}/venv/bin/flake8"],
    "python.flake8Severity":{
        "W": "Hint",
        "E": "Hint",
        "F": "Hint",
    }
}

Expected:

none

Actual:

F401, E302, E305 error, W292 warning

Status:

flake8Severity not worked with installed flake8

case 11

  • Create file with with suggested content
  • install flake8
  • install flake8-print
  • add line somethere print() # for T001
  • add next settings:
{
    "python.flake8Path": ["${workspaceFolder}/venv/bin/flake8"],
    "python.flake8Severity":{
        "W": "Hint",
        "E": "Hint",
        "F": "Hint",
        "T": "Error",
    }
}

Expected:

T001 Error

Actual:

F401, E302, E305 error, W292 warning, T001 info

Status:

flake8Severity not worked with installed flake8. Default codes from flake are info (I think, needed "error" as default level)

Thanks for you work, really! Almost perfect! Just 4/11 are broken

@karthiknadig
Copy link
Member

@Niccolum You can see the logic for severity in the linter_server.py, (in the extensions folder). The way it works now is that if you set:

"python.flake8Severity":{
        "W": "Error",
    }

Then it does not know about F, E, or other types of codes. The severity setting literally replaces the look up. If it cannot find anything it uses Error.

def _get_severity(code, codeType, severity):
    value = severity.get(code, None) or severity.get(codeType, "Error")
    try:
        return types.DiagnosticSeverity[value]
    except Exception:
        pass

    return types.DiagnosticSeverity.Error

Here code can take values like (F401, E302, E305), codeType can take values like (F, E, I, T, W), severity is literally what you set in the severity setting. In the above case { "W": "Error", }

@Niccolum
Copy link
Author

Niccolum commented Feb 12, 2022

Main logic with default "error" - is great. Why this doesn't work with T001?

And what about, if I ignore main letter, but use some of them in config. For example

[flake8]
select=E001,E002,E123
ignore=E

If we use next logic with default letters - we must duplicate flake8 config in vscode flake8Severity. I think it's a problem. Or I am wrong?

UPD:
@karthiknadig Re-read you message. If I understand you correctly - second part of message are not valid. Thanks!

@brettcannon
Copy link
Member

Thank you to everyone who upvoted this issue! Since the community showed interest in this feature request we will leave this issue open as something to consider implementing at some point in the future.

We do encourage people to continue 👍 the first/opening comment as it helps us prioritize our work based on what the community seems to want the most.

@brettcannon brettcannon added community ask Feature request that the community expressed interest in needs proposal Need to make some design decisions and removed needs community feedback Awaiting community feedback labels Mar 8, 2022
@karthiknadig
Copy link
Member

We have a preview extension available now from marketplace: https://marketplace.visualstudio.com/items?itemName=ms-python.flake8

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-linting community ask Feature request that the community expressed interest in feature-request Request for new features or functionality needs proposal Need to make some design decisions
Projects
None yet
Development

No branches or pull requests

3 participants