Skip to content

Cannot configure severity for partial error code #7

Open

Description

@Avasam

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.

Activity

  1. karthiknadig commented on Sep 2, 2022

    @karthiknadig
    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.

  2. added a commit that references this issue on Sep 12, 2022
  3. gschwaer commented on Feb 15, 2023

    @gschwaer

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions