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

Cannot configure severity for partial error code #7

Open
Avasam opened this issue Aug 30, 2022 · 2 comments
Open

Cannot configure severity for partial error code #7

Avasam opened this issue Aug 30, 2022 · 2 comments
Labels
feature-request Request for new features or functionality needs community feedback

Comments

@Avasam
Copy link

Avasam commented Aug 30, 2022

I am trying to configure flake8 as such:

class test:
    __init__(self): pass  # pylint: disable=syntax-error

    a = 0
    c = 2
    b = 1

    if True:
        if True:
            pass
  "flake8.severity": {
    "convention": "Warning",
    "error": "Error",
    "fatal": "Error",
    "refactor": "Warning",
    "warning": "Warning",
    "info": "Warning",
    // builtins
    "A": "Warning",
    // mccabe
    "C": "Warning",
    // class attributes order
    "CCE": "Warning",
    // pycodestyles
    "E": "Warning",
    "E9": "Error", // Runtime
    "W": "Warning",
    // Pyflakes
    "F": "Warning",
    // PEP8 Naming convention
    "N": "Warning",
    // Simplify
    "SIM": "Warning",
    "SIM9": "Information",
    // PYI
    "Y": "Warning",
  },

Only single characters or full error code work. The following do nothing: CCE, E9, SIM, SIM9.

@karthiknadig karthiknadig added feature-request Request for new features or functionality needs community feedback and removed triage-needed labels Sep 2, 2022
@karthiknadig
Copy link
Member

The check happens here, code_type is basically category. Pattern matching not supported:

def _get_severity(
code: str, code_type: str, severity: Dict[str, str]
) -> lsp.DiagnosticSeverity:
"""Converts severity provided by linter to LSP specific value."""
value = severity.get(code, None) or severity.get(code_type, "Error")
try:
return lsp.DiagnosticSeverity[value]
except KeyError:
pass
return lsp.DiagnosticSeverity.Error

One of the reasons we don't allow full pattern matching, but only category or error code is this: let say you have E, E1, E13 all set to different severity, you now have to build a hierarchy that ensures that you check for E13 first, then E1, and then E, and before that you have to check for all absolute error codes.

@gschwaer
Copy link

gschwaer commented Feb 15, 2023

It should be sufficient to iterate over the categories sorted by length from longest to shortest and pick the first that fits, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality needs community feedback
Projects
None yet
Development

No branches or pull requests

3 participants