|
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 | | - |
| 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 | +} |
32 | 45 |
|
33 | 46 | class PylintLinter: |
34 | 47 | last_diags = collections.defaultdict(list) |
@@ -146,13 +159,22 @@ def lint(cls, document, is_saved, flags=''): |
146 | 159 | elif diag['type'] == 'warning': |
147 | 160 | severity = lsp.DiagnosticSeverity.Warning |
148 | 161 |
|
149 | | - diagnostics.append({ |
| 162 | + code = diag['message-id'] |
| 163 | + |
| 164 | + diagnostic = { |
150 | 165 | 'source': 'pylint', |
151 | 166 | 'range': err_range, |
152 | 167 | 'message': '[{}] {}'.format(diag['symbol'], diag['message']), |
153 | 168 | 'severity': severity, |
154 | | - 'code': diag['message-id'] |
155 | | - }) |
| 169 | + 'code': code |
| 170 | + } |
| 171 | + |
| 172 | + if code in UNNECESSITY_CODES: |
| 173 | + diagnostic['tags'] = [lsp.DiagnosticTag.Unnecessary] |
| 174 | + if code in DEPRECATION_CODES: |
| 175 | + diagnostic['tags'] = [lsp.DiagnosticTag.Deprecated] |
| 176 | + |
| 177 | + diagnostics.append(diagnostic) |
156 | 178 | cls.last_diags[document.path] = diagnostics |
157 | 179 | return diagnostics |
158 | 180 |
|
@@ -295,24 +317,27 @@ def _parse_pylint_stdio_result(document, stdout): |
295 | 317 | 'W': lsp.DiagnosticSeverity.Warning, |
296 | 318 | } |
297 | 319 | 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 | | - } |
| 320 | + diagnostic = { |
| 321 | + 'source': 'pylint', |
| 322 | + 'code': code, |
| 323 | + 'range': { |
| 324 | + 'start': { |
| 325 | + 'line': line, |
| 326 | + 'character': character |
312 | 327 | }, |
313 | | - 'message': msg, |
314 | | - 'severity': severity, |
315 | | - } |
316 | | - ) |
| 328 | + 'end': { |
| 329 | + 'line': line, |
| 330 | + # no way to determine the column |
| 331 | + 'character': len(document.lines[line]) - 1 |
| 332 | + } |
| 333 | + }, |
| 334 | + 'message': msg, |
| 335 | + 'severity': severity, |
| 336 | + } |
| 337 | + if code in UNNECESSITY_CODES: |
| 338 | + diagnostic['tags'] = [lsp.DiagnosticTag.Unnecessary] |
| 339 | + if code in DEPRECATION_CODES: |
| 340 | + diagnostic['tags'] = [lsp.DiagnosticTag.Deprecated] |
| 341 | + diagnostics.append(diagnostic) |
317 | 342 |
|
318 | 343 | return diagnostics |
0 commit comments