FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Allow multiple per-file-ignores for the same pattern in flake8 plugin by dedi · Pull Request #217 · python-lsp/python-lsp-server · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
14 changes: 13 additions & 1 deletion pylsp/plugins/flake8_lint.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,20 @@ 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.warning(
"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(","))

Expand Down
22 changes: 22 additions & 0 deletions test/plugins/test_flake8_lint.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Back | FazBrowse Home | New Git URL