Skip to content

Commit 91a9881

Browse files
committed
(#19) Add extendIgnore option
Also allow use of server options over project settings
1 parent 500b626 commit 91a9881

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ When enabled, all linting diagnostics will be provided by `ruff`.
2525

2626
Configuration options can be passed to the python-language-server. If a `pyproject.toml`
2727
file is present in the project, `python-lsp-ruff` will use these configuration options.
28-
Note that any configuration options passed to ruff via `pylsp` are ignored if the project has
29-
a `pyproject.toml`.
28+
Note that any configuration options (except for `extendIgnore` and `extendSelect`, see
29+
[this issue](https://github.com/python-lsp/python-lsp-ruff/issues/19)) passed to ruff via
30+
`pylsp` are ignored if the project has a `pyproject.toml`.
3031

3132
The plugin follows [python-lsp-server's
3233
configuration](https://github.com/python-lsp/python-lsp-server/#configuration). These are
@@ -37,6 +38,7 @@ the valid configuration keys:
3738
- `pylsp.plugins.ruff.exclude`: Exclude files from being checked by `ruff`.
3839
- `pylsp.plugins.ruff.executable`: Path to the `ruff` executable. Assumed to be in PATH by default.
3940
- `pylsp.plugins.ruff.ignore`: Error codes to ignore.
41+
- `pylsp.plugins.ruff.extendIgnore`: Same as ignore, but append to existing ignores.
4042
- `pylsp.plugins.ruff.lineLength`: Set the line-length for length checks.
4143
- `pylsp.plugins.ruff.perFileIgnores`: File-specific error codes to be ignored.
4244
- `pylsp.plugins.ruff.select`: List of error codes to enable.

pylsp_ruff/ruff_lint.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def pylsp_settings():
3030
"exclude": None,
3131
"executable": "ruff",
3232
"ignore": None,
33+
"extendIgnore": None,
3334
"lineLength": None,
3435
"perFileIgnores": None,
3536
"select": None,
@@ -251,10 +252,11 @@ def load_config(workspace: Workspace, document: Document) -> dict:
251252
"exclude": None,
252253
"executable": _settings.get("executable", "ruff"),
253254
"ignore": None,
255+
"extend-ignore": _settings.get("extendIgnore", None),
254256
"line-length": None,
255257
"per-file-ignores": None,
256258
"select": None,
257-
"extend-select": None,
259+
"extend-select": _settings.get("extendSelect", None),
258260
}
259261

260262
else:
@@ -264,6 +266,7 @@ def load_config(workspace: Workspace, document: Document) -> dict:
264266
"exclude": _settings.get("exclude", None),
265267
"executable": _settings.get("executable", "ruff"),
266268
"ignore": _settings.get("ignore", None),
269+
"extend-ignore": _settings.get("extendIgnore", None),
267270
"line-length": _settings.get("lineLength", None),
268271
"per-file-ignores": _settings.get("perFileIgnores", None),
269272
"select": _settings.get("select", None),

tests/test_ruff_lint.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,23 @@ def test_ruff_config_param(workspace):
7878
mock_instance.communicate.return_value = [bytes(), bytes()]
7979
ruff_conf = "/tmp/pyproject.toml"
8080
workspace._config.update(
81-
{"plugins": {"ruff": {"config": ruff_conf, "extendSelect": ["D", "F"]}}}
81+
{
82+
"plugins": {
83+
"ruff": {
84+
"config": ruff_conf,
85+
"extendSelect": ["D", "F"],
86+
"extendIgnore": ["E"],
87+
}
88+
}
89+
}
8290
)
8391
_name, doc = temp_document(DOC, workspace)
8492
ruff_lint.pylsp_lint(workspace, doc)
8593
(call_args,) = popen_mock.call_args[0]
8694
assert "ruff" in call_args
8795
assert f"--config={ruff_conf}" in call_args
8896
assert "--extend-select=D,F" in call_args
97+
assert "--extend-ignore=E" in call_args
8998

9099

91100
def test_ruff_executable_param(workspace):
@@ -171,15 +180,25 @@ def f():
171180
"-",
172181
]
173182

183+
workspace._config.update(
184+
{
185+
"plugins": {
186+
"ruff": {
187+
"extendIgnore": ["D104"],
188+
}
189+
}
190+
}
191+
)
192+
174193
diags = ruff_lint.pylsp_lint(workspace, doc)
175194

176195
_list = []
177196
for diag in diags:
178197
_list.append(diag["code"])
179-
# Assert that ignore and extend-select is working as intended
198+
# Assert that ignore, extend-ignore and extend-select is working as intended
180199
assert "E402" in _list
181200
assert "D103" in _list
182-
assert "D104" in _list
201+
assert "D104" not in _list
183202
assert "F841" not in _list
184203

185204
# Excludes

0 commit comments

Comments
 (0)