Skip to content

Commit 2f9d678

Browse files
MrGreenTeamaerteijn
authored andcommitted
add regex pattern matching to exclude documents from type checking
1 parent d72a3c6 commit 2f9d678

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pylsp_mypy/plugin.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,15 @@ def get_diagnostics(
218218
document.path,
219219
is_saved,
220220
)
221+
exclude = settings.get("exclude", [])
222+
for pattern in exclude:
223+
if re.match(pattern, document.path):
224+
log.debug(
225+
"Not running because %s matches exclude pattern %s",
226+
document.path,
227+
settings.get("exclude"),
228+
)
229+
return []
221230

222231
live_mode = settings.get("live_mode", True)
223232
dmypy = settings.get("dmypy", False)

test/test_plugin.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,14 @@ def foo():
328328
diag = diags[0]
329329
assert diag["message"] == DOC_ERR_MSG
330330
assert diag["code"] == "unreachable"
331+
332+
333+
def test_exclude_path_match_mypy_not_run(tmpdir, workspace):
334+
"""When exclude is set in config then mypy should not run for that file."""
335+
doc = Document(DOC_URI, workspace, DOC_TYPE_ERR)
336+
337+
plugin.pylsp_settings(workspace._config)
338+
workspace.update_config({"pylsp": {"plugins": {"pylsp_mypy": {"exclude": [doc.path]}}}})
339+
diags = plugin.pylsp_lint(workspace._config, workspace, doc, is_saved=False)
340+
341+
assert not diags

0 commit comments

Comments
 (0)