From 97c348c7021de3e4487dcd6b8d2019bb48fad356 Mon Sep 17 00:00:00 2001 From: Dedi Hirschfeld Date: Tue, 31 May 2022 14:48:26 +0300 Subject: [PATCH 1/3] Allow multiple per-file-ignores for the same pattern in flake8 plugin. --- pylsp/plugins/flake8_lint.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pylsp/plugins/flake8_lint.py b/pylsp/plugins/flake8_lint.py index 3707222f..74583c18 100644 --- a/pylsp/plugins/flake8_lint.py +++ b/pylsp/plugins/flake8_lint.py @@ -31,8 +31,19 @@ def pylsp_lint(workspace, document): per_file_ignores = settings.get("perFileIgnores") if per_file_ignores: + prev_file_pat = None for path in per_file_ignores: - file_pat, errors = path.split(":") + try: + file_pat, errors = path.split(":") + prev_file_pat = file_pat + except ValueError: + # It's legal to just specify another error type for the same + # file pattern: + if prev_file_pat is None: + log.warn("skipping a Per-file-ignore with no file pattern") + continue + file_pat = prev_file_pat + errors = path if PurePath(document.path).match(file_pat): ignores.extend(errors.split(",")) From ac32ebae3b22de1c5781c7f433f54b8f91c585c6 Mon Sep 17 00:00:00 2001 From: Dedi Hirschfeld Date: Tue, 31 May 2022 18:32:56 +0300 Subject: [PATCH 2/3] Added a regression for per_file_ignores using alternative syntax. --- test/plugins/test_flake8_lint.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/plugins/test_flake8_lint.py b/test/plugins/test_flake8_lint.py index 59a776a1..a72383ec 100644 --- a/test/plugins/test_flake8_lint.py +++ b/test/plugins/test_flake8_lint.py @@ -158,3 +158,25 @@ def test_flake8_per_file_ignores(workspace): assert not res os.unlink(os.path.join(workspace.root_path, "setup.cfg")) + + +def test_per_file_ignores_alternative_syntax(workspace): + config_str = r"""[flake8] +per-file-ignores = **/__init__.py:F401,E402 + """ + + doc_str = "print('hi')\nimport os\n" + + doc_uri = uris.from_fs_path(os.path.join(workspace.root_path, "blah/__init__.py")) + workspace.put_document(doc_uri, doc_str) + + flake8_settings = get_flake8_cfg_settings(workspace, config_str) + + assert "perFileIgnores" in flake8_settings + assert len(flake8_settings["perFileIgnores"]) == 2 + + doc = workspace.get_document(doc_uri) + res = flake8_lint.pylsp_lint(workspace, doc) + assert not res + + os.unlink(os.path.join(workspace.root_path, "setup.cfg")) From 99f72578edc360aec53cbb410487cc0dce0b221c Mon Sep 17 00:00:00 2001 From: Dedi Hirschfeld Date: Tue, 31 May 2022 18:50:39 +0300 Subject: [PATCH 3/3] Fixed a deprecation warning --- pylsp/plugins/flake8_lint.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pylsp/plugins/flake8_lint.py b/pylsp/plugins/flake8_lint.py index 74583c18..5c77e1d3 100644 --- a/pylsp/plugins/flake8_lint.py +++ b/pylsp/plugins/flake8_lint.py @@ -40,7 +40,8 @@ def pylsp_lint(workspace, document): # It's legal to just specify another error type for the same # file pattern: if prev_file_pat is None: - log.warn("skipping a Per-file-ignore with no file pattern") + log.warning( + "skipping a Per-file-ignore with no file pattern") continue file_pat = prev_file_pat errors = path