|
28 | 28 | # fix for a very specific upstream issue.
|
29 | 29 | # Related: https://github.com/PyCQA/pylint/issues/3518
|
30 | 30 | os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = 'hide'
|
| 31 | +DEPRECATION_CODES = { |
| 32 | + 'W0402', # Uses of a deprecated module %r |
| 33 | + 'W1505', # Using deprecated method %s() |
| 34 | + 'W1511', # Using deprecated argument %s of method %s() |
| 35 | + 'W1512', # Using deprecated class %s of module %s |
| 36 | + 'W1513', # Using deprecated decorator %s() |
| 37 | +} |
| 38 | +UNNECESSITY_CODES = { |
| 39 | + 'W0611', # Unused import %s |
| 40 | + 'W0612', # Unused variable %r |
| 41 | + 'W0613', # Unused argument %r |
| 42 | + 'W0614', # Unused import %s from wildcard import |
| 43 | + 'W1304', # Unused-format-string-argument |
| 44 | +} |
31 | 45 |
|
32 | 46 |
|
33 | 47 | class PylintLinter:
|
@@ -146,13 +160,22 @@ def lint(cls, document, is_saved, flags=''):
|
146 | 160 | elif diag['type'] == 'warning':
|
147 | 161 | severity = lsp.DiagnosticSeverity.Warning
|
148 | 162 |
|
149 |
| - diagnostics.append({ |
| 163 | + code = diag['message-id'] |
| 164 | + |
| 165 | + diagnostic = { |
150 | 166 | 'source': 'pylint',
|
151 | 167 | 'range': err_range,
|
152 | 168 | 'message': '[{}] {}'.format(diag['symbol'], diag['message']),
|
153 | 169 | 'severity': severity,
|
154 |
| - 'code': diag['message-id'] |
155 |
| - }) |
| 170 | + 'code': code |
| 171 | + } |
| 172 | + |
| 173 | + if code in UNNECESSITY_CODES: |
| 174 | + diagnostic['tags'] = [lsp.DiagnosticTag.Unnecessary] |
| 175 | + if code in DEPRECATION_CODES: |
| 176 | + diagnostic['tags'] = [lsp.DiagnosticTag.Deprecated] |
| 177 | + |
| 178 | + diagnostics.append(diagnostic) |
156 | 179 | cls.last_diags[document.path] = diagnostics
|
157 | 180 | return diagnostics
|
158 | 181 |
|
@@ -295,24 +318,27 @@ def _parse_pylint_stdio_result(document, stdout):
|
295 | 318 | 'W': lsp.DiagnosticSeverity.Warning,
|
296 | 319 | }
|
297 | 320 | severity = severity_map[code[0]]
|
298 |
| - diagnostics.append( |
299 |
| - { |
300 |
| - 'source': 'pylint', |
301 |
| - 'code': code, |
302 |
| - 'range': { |
303 |
| - 'start': { |
304 |
| - 'line': line, |
305 |
| - 'character': character |
306 |
| - }, |
307 |
| - 'end': { |
308 |
| - 'line': line, |
309 |
| - # no way to determine the column |
310 |
| - 'character': len(document.lines[line]) - 1 |
311 |
| - } |
| 321 | + diagnostic = { |
| 322 | + 'source': 'pylint', |
| 323 | + 'code': code, |
| 324 | + 'range': { |
| 325 | + 'start': { |
| 326 | + 'line': line, |
| 327 | + 'character': character |
312 | 328 | },
|
313 |
| - 'message': msg, |
314 |
| - 'severity': severity, |
315 |
| - } |
316 |
| - ) |
| 329 | + 'end': { |
| 330 | + 'line': line, |
| 331 | + # no way to determine the column |
| 332 | + 'character': len(document.lines[line]) - 1 |
| 333 | + } |
| 334 | + }, |
| 335 | + 'message': msg, |
| 336 | + 'severity': severity, |
| 337 | + } |
| 338 | + if code in UNNECESSITY_CODES: |
| 339 | + diagnostic['tags'] = [lsp.DiagnosticTag.Unnecessary] |
| 340 | + if code in DEPRECATION_CODES: |
| 341 | + diagnostic['tags'] = [lsp.DiagnosticTag.Deprecated] |
| 342 | + diagnostics.append(diagnostic) |
317 | 343 |
|
318 | 344 | return diagnostics
|
0 commit comments