8000
We read every piece of feedback, and take your input very seriously.
1 parent 73b945b commit c428381Copy full SHA for c428381
pylsp/plugins/flake8_lint.py
@@ -9,9 +9,13 @@
9
from pathlib import PurePath
10
from subprocess import PIPE, Popen
11
12
+from flake8.plugins.pyflakes import FLAKE8_PYFLAKES_CODES
13
+
14
from pylsp import hookimpl, lsp
15
+from pylsp.plugins.pyflakes_lint import PYFLAKES_ERROR_MESSAGES
16
17
log = logging.getLogger(__name__)
18
19
FIX_IGNORES_RE = re.compile(r"([^a-zA-Z0-9_,]*;.*(\W+||$))")
20
UNNECESSITY_CODES = {
21
"F401", # `module` imported but unused
@@ -20,6 +24,14 @@
24
"F523", # .format(...) unused positional arguments
25
"F841", # local variable `name` is assigned to but never used
22
26
}
27
+# NOTE: If the user sets the flake8 executable with workspace configuration, the
28
+# error codes in this set may be inaccurate.
29
+ERROR_CODES = (
30
+ # Errors from the pyflakes plugin of flake8
31
+ {FLAKE8_PYFLAKES_CODES.get(m.__name__, "E999") for m in PYFLAKES_ERROR_MESSAGES}
32
+ # Syntax error from flake8 itself
33
+ | {"E999"}
34
+)
23
35
36
37
@hookimpl
@@ -208,7 +220,7 @@ def parse_stdout(source, stdout):
208
220
# show also the code in message
209
221
msg = code + " " + msg
210
222
severity = lsp.DiagnosticSeverity.Warning
211
- if code == "E999" or code[0] == "F":
223
+ if code in ERROR_CODES:
212
224
severity = lsp.DiagnosticSeverity.Error
213
225
diagnostic = {
214
226
"source": "flake8",
test/plugins/test_flake8_lint.py
@@ -40,7 +40,7 @@ def test_flake8_unsaved(workspace):
40
assert unused_var["code"] == "F841"
41
assert unused_var["range"]["start"] == {"line": 5, "character": 1}
42
assert unused_var["range"]["end"] == {"line": 5, "character": 11}
43
- assert unused_var["severity"] == lsp.DiagnosticSeverity.Error
+ assert unused_var["severity"] == lsp.DiagnosticSeverity.Warning
44
assert unused_var["tags"] == [lsp.DiagnosticTag.Unnecessary]
45
46
@@ -55,7 +55,7 @@ def test_flake8_lint(workspace):
55
56
57
58
59
finally:
60
os.remove(name)
61
@@ -101,7 +101,7 @@ def test_flake8_respecting_configuration(workspace):
101
"end": {"line": 5, "character": 11},
102
},
103
"message": "F841 local variable 'a' is assigned to but never used",
104
- "severity": 1,
+ "severity": 2,
105
"tags": [1],
106
107
]
@@ -116,7 +116,7 @@ def test_flake8_respecting_configuration(workspace):
116
"end": {"line": 0, "character": 9},
117
118
"message": "F401 'os' imported but unused",
119
120
121
122