10000 Enable pylint (#202) · mrclary/python-lsp-server@c665291 · GitHub
[go: up one dir, main page]

Skip to content

Commit c665291

Browse files
authored
Enable pylint (python-lsp#202)
1 parent 7a66037 commit c665291

16 files changed

+62
-56
lines changed

pyls/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,14 @@ def _binary_stdio():
8080
PY3K = sys.version_info >= (3, 0)
8181

8282
if PY3K:
83+
# pylint: disable=no-member
8384
stdin, stdout = sys.stdin.buffer, sys.stdout.buffer
8485
else:
8586
# Python 2 on Windows opens sys.stdin in text mode, and
8687
# binary data that read from it becomes corrupted on \r\n
8788
if sys.platform == "win32":
8889
# set sys.stdin to binary mode
90+
# pylint: disable=no-member,import-error
8991
import os
9092
import msvcrt
9193
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)

pyls/_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def find_parents(root, path, names):
6565

6666

6767
def list_to_string(value):
68-
return ",".join(value) if type(value) == list else value
68+
return ",".join(value) if isinstance(value, list) else value
6969

7070

7171
def merge_dicts(dict_a, dict_b):
@@ -122,7 +122,7 @@ def format_docstring(contents):
122122
Until we can find a fast enough way of discovering and parsing each format,
123123
we can do a little better by at least preserving indentation.
124124
"""
125-
contents = contents.replace('\t', '\u00A0' * 4)
126-
contents = contents.replace(' ', '\u00A0' * 2)
125+
contents = contents.replace('\t', u'\u00A0' * 4)
126+
contents = contents.replace(' ', u'\u00A0' * 2)
127127
contents = contents.replace('*', '\\*')
128128
return contents

pyls/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
# pylint: skip-file
22
# This file helps to compute a version number in source trees obtained from
33
# git-archive tarball (such as those provided by githubs download-from-tag
44
# feature). Distribution tarballs (built by setup.py sdist) and build

pyls/config/flake8_conf.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Copyright 2017 Palantir Technologies, Inc.
22
import logging
33
import os
4-
from .source import ConfigSource
54
from pyls._utils import find_parents
5+
from .source import ConfigSource
66

77
log = logging.getLogger(__name__)
88

@@ -33,8 +33,7 @@ def user_config(self):
3333
def _user_config_file(self):
3434
if self.is_windows:
3535
return os.path.expanduser('~\\.flake8')
36-
else:
37-
return os.path.join(self.xdg_home, 'flake8')
36+
return os.path.join(self.xdg_home, 'flake8')
3837

3938
def project_config(self, document_path):
4039
files = find_parents(self.root_path, document_path, PROJECT_CONFIGS)

pyls/config/pycodestyle_conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2017 Palantir Technologies, Inc.
22
import pycodestyle
3-
from .source import ConfigSource
43
from pyls._utils import find_parents
4+
from .source import ConfigSource
55

66

77
CONFIG_KEY = 'pycodestyle'

pyls/language_server.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class _StreamHandlerWrapper(socketserver.StreamRequestHandler, object):
1515

1616
def setup(self):
1717
super(_StreamHandlerWrapper, self).setup()
18+
# pylint: disable=no-member
1819
self.delegate = self.DELEGATE_CLASS(self.rfile, self.wfile)
1920

2021
def handle(self):
@@ -62,7 +63,7 @@ def __getitem__(self, item):
6263
def wrapped(*args, **kwargs):
6364
try:
6465
return func(*args, **kwargs)
65-
except: # pylint: disable=bare-except
66+
except:
6667
log.exception("CAUGHT")
6768
raise
6869
return wrapped
@@ -77,7 +78,7 @@ class LanguageServer(MethodJSONRPCServer):
7778
root_uri = None
7879
init_opts = None
7980

80-
def capabilities(self):
81+
def capabilities(self): # pylint: disable=no-self-use
8182
return {}
8283

8384
def initialize(self, root_uri, init_opts, process_id):

pyls/plugins/format.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def pyls_format_document(document):
1414

1515

1616
@hookimpl
17-
def pyls_format_range(document, range):
17+
def pyls_format_range(document, range): # pylint: disable=redefined-builtin
1818
# First we 'round' the range up/down to full lines only
1919
range['start']['character'] = 0
2020
range['end']['line'] += 1
@@ -32,25 +32,25 @@ def pyls_format_range(document, range):
3232

3333

3434
def _format(document, lines=None):
35-
new_source, changed = FormatCode(
36-
document.source,
37-
lines=lines,
38-
filename=document.filename,
39-
style_config=file_resources.GetDefaultStyleForDir(
40-
os.path.dirname(document.filename)
41-
)
35+
new_source, changed = FormatCode(
36+
document.source,
37+
lines=lines,
38+
filename=document.filename,
39+
style_config=file_resources.GetDefaultStyleForDir(
40+
os.path.dirname(document.filename)
4241
)
43-
44-
if not changed:
45-
return []
46-
47-
# I'm too lazy at the moment to parse diffs into TextEdit items
48-
# So let's just return the entire file...
49-
return [{
50-
'range': {
51-
'start': {'line': 0, 'character': 0},
52-
# End char 0 of the line after our document
53-
'end': {'line': len(document.lines), 'character': 0}
54-
},
55-
'newText': new_source
56-
}]
42+
)
43+
44+
if not changed:
45+
return []
46+
47+
# I'm too lazy at the moment to parse diffs into TextEdit items
48+
# So let's just return the entire file...
49+
return [{
50+
'range': {
51+
'start': {'line': 0, 'character': 0},
52+
# End char 0 of the line after our document
53+
'end': {'line': len(document.lines), 'character': 0}
54+
},
55+
'newText': new_source
56+
}]

pyls/plugins/hover.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def pyls_hover(document, position):
1313
# Find an exact match for a completion
1414
definitions = [d for d in definitions if d.name == word]
1515

16-
if len(definitions) == 0:
16+
if not definitions:
1717
# :(
1818
return {'contents': ''}
1919

pyls/plugins/pycodestyle_lint.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,24 @@ def __init__(self, options=None):
3636
self.diagnostics = []
3737
super(PyCodeStyleDiagnosticReport, self).__init__(options=options)
3838

39-
def error(self, lineno, offset, text, check):
39+
def error(self, line_number, offset, text, check):
4040
# PyCodeStyle will sometimes give you an error the line after the end of the file
4141
# e.g. no newline at end of file
4242
# In that case, the end offset should just be some number ~100
4343
# (because why not? There's nothing to underline anyways)
44-
range = {
45-
'start': {'line': lineno - 1, 'character': offset},
44+
err_range = {
45+
'start': {'line': line_number - 1, 'character': offset},
4646
'end': {
4747
# FIXME: It's a little naiive to mark until the end of the line, can we not easily do better?
48-
'line': lineno - 1, 'character': 100 if lineno > len(self.lines) else len(self.lines[lineno - 1])
48+
'line': line_number - 1,
49+
'character': 100 if line_number > len(self.lines) else len(self.lines[line_number - 1])
4950
},
5051
}
5152
code, _message = text.split(" ", 1)
5253

5354
self.diagnostics.append({
5455
'source': 'pycodestyle',
55-
'range': range,
56+
'range': err_range,
5657
'message': text,
5758
'code': code,
5859
# Are style errors really ever errors?

pyls/plugins/pyflakes_lint.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,27 @@ def __init__(self, lines):
1919
def unexpectedError(self, filename, msg): # pragma: no cover
2020
pass
2121

22-
def syntaxError(self, filename, msg, lineno, offset, text):
23-
range = {
22+
def syntaxError(self, _filename, msg, lineno, offset, text):
23+
err_range = {
2424
'start': {'line': lineno - 1, 'character': offset},
2525
'end': {'line': lineno - 1, 'character': offset + len(text)},
2626
}
2727
self.diagnostics.append({
2828
'source': 'pyflakes',
29-
'range': range,
29+
'range': err_range,
3030
'message': msg,
3131
'severity': lsp.DiagnosticSeverity.Error,
3232
})
3333

3434
def flake(self, message):
3535
""" Get message like <filename>:<lineno>: <msg> """
36-
range = {
36+
err_range = {
3737
'start': {'line': message.lineno - 1, 'character': message.col},
3838
'end': {'line': message.lineno - 1, 'character': len(self.lines[message.lineno - 1])},
3939
}
4040
self.diagnostics.append({
4141
'source': 'pyflakes',
42-
'range': range,
42+
'range': err_range,
4343
'message': message.message % message.message_args,
4444
'severity': lsp.DiagnosticSeverity.Warning
4545
})

0 commit comments

Comments
 (0)
0