Skip to content

Commit fc2851a

Browse files
authored
Use ruff as linter and code formatter (#502)
1 parent cb213e0 commit fc2851a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+241
-213
lines changed

.github/workflows/static.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,12 @@ jobs:
3838
# If we don't install pycodestyle, pylint will throw an unused-argument error in pylsp/plugins/pycodestyle_lint.py:72
3939
# This error cannot be resolved by adding a pylint: disable=unused-argument comment ...
4040
- run: |
41-
pip install -e .[pylint,pycodestyle,pyflakes]
42-
pip install black
43-
- name: Pylint checks
44-
run: pylint pylsp test
45-
- name: Code style checks with black
46-
run: black --check pylsp test
47-
- name: Pyflakes checks
48-
run: pyflakes pylsp test
41+
pip install -e .[pylint,pycodestyle]
42+
pip install ruff
43+
- name: ruff linter and code style checks
44+
run: ruff check pylsp test
45+
- name: ruff code formatter check
46+
run: ruff format --check pylsp test
4947
- name: Validate JSON schema
5048
run: echo {} | jsonschema pylsp/config/schema.json
5149
- name: Ensure JSON schema and Markdown docs are in sync

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ reports = no
2828

2929
generated-members =
3030
pylsp_*
31-
cache_clear
31+
cache_clear

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ include README.md
22
include versioneer.py
33
include pylsp/_version.py
44
include LICENSE
5+
include ruff.toml
56
include .pylintrc
67
recursive-include test *.py

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,13 @@ To run the test suite:
185185
pytest
186186
```
187187

188+
Running ruff as a linter and code formatter on the repo:
189+
```sh
190+
ruff check . # linter
191+
ruff check --fix . # fix all auto-fixable lint issues
192+
ruff format . # format the document
193+
```
194+
188195
After adding configuration options to `schema.json`, refresh the `CONFIGURATION.md` file with
189196

190197
```

pylsp/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
# Copyright 2021- Python Language Server Contributors.
33

44
import os
5+
56
import pluggy
7+
68
from . import _version
79
from ._version import __version__
810

pylsp/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99

1010
try:
1111
import ujson as json
12-
except Exception: # pylint: disable=broad-except
12+
except Exception:
1313
import json
1414

15+
from ._version import __version__
1516
from .python_lsp import (
1617
PythonLSPServer,
1718
start_io_lang_server,
1819
start_tcp_lang_server,
1920
start_ws_lang_server,
2021
)
21-
from ._version import __version__
2222

2323
LOG_FORMAT = "%(asctime)s {0} - %(levelname)s - %(name)s - %(message)s".format(
2424
time.localtime().tm_zone

pylsp/_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def throttle(seconds=1):
6161

6262
def decorator(func):
6363
@functools.wraps(func)
64-
def wrapper(*args, **kwargs): # pylint: disable=inconsistent-return-statements
64+
def wrapper(*args, **kwargs):
6565
if not hasattr(wrapper, "last_call"):
6666
wrapper.last_call = 0
6767
if time.time() - wrapper.last_call >= seconds:

pylsp/config/config.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Copyright 2017-2020 Palantir Technologies, Inc.
22
# Copyright 2021- Python Language Server Contributors.
3-
# pylint: disable=import-outside-toplevel
43

54
import logging
65
import sys
@@ -10,7 +9,7 @@
109
import pluggy
1110
from pluggy._hooks import HookImpl
1211

13-
from pylsp import _utils, hookspecs, uris, PYLSP
12+
from pylsp import PYLSP, _utils, hookspecs, uris
1413

1514
# See compatibility note on `group` keyword:
1615
# https://docs.python.org/3/library/importlib.metadata.html#entry-points
@@ -38,7 +37,7 @@ def _hookexec(
3837
# enable_tracing will set its own wrapping function at self._inner_hookexec
3938
try:
4039
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
41-
except Exception as e: # pylint: disable=broad-except
40+
except Exception as e:
4241
log.warning(f"Failed to load hook {hook_name}: {e}", exc_info=True)
4342
return []
4443

@@ -79,7 +78,7 @@ def __init__(self, root_uri, init_opts, process_id, capabilities):
7978
for entry_point in entry_points(group=PYLSP):
8079
try:
8180
entry_point.load()
82-
except Exception as e: # pylint: disable=broad-except
81+
except Exception as e:
8382
log.info(
8483
"Failed to load %s entry point '%s': %s", PYLSP, entry_point.name, e
8584
)

pylsp/config/flake8_conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
import logging
55
import os
6+
67
from pylsp._utils import find_parents
8+
79
from .source import ConfigSource
810

911
log = logging.getLogger(__name__)

pylsp/config/pycodestyle_conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
# Copyright 2021- Python Language Server Contributors.
33

44
import pycodestyle
5+
56
from pylsp._utils import find_parents
6-
from .source import ConfigSource
77

8+
from .source import ConfigSource
89

910
CONFIG_KEY = "pycodestyle"
1011
USER_CONFIGS = [pycodestyle.USER_CONFIG] if pycodestyle.USER_CONFIG else []

0 commit comments

Comments
 (0)