Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pydoctyle plugin: The 'match' option in a config file isn't ignored #524

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 24 additions & 19 deletions pylsp/plugins/pydocstyle_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

import contextlib
import logging
import os
import re
import sys
from pathlib import Path

import pydocstyle

Expand All @@ -17,7 +17,6 @@
pydocstyle_logger = logging.getLogger(pydocstyle.utils.__name__)
pydocstyle_logger.setLevel(logging.INFO)

DEFAULT_MATCH_RE = pydocstyle.config.ConfigurationParser.DEFAULT_MATCH_RE
DEFAULT_MATCH_DIR_RE = pydocstyle.config.ConfigurationParser.DEFAULT_MATCH_DIR_RE


Expand All @@ -33,30 +32,36 @@ def pylsp_lint(config, workspace, document):
settings = config.plugin_settings("pydocstyle", document_path=document.path)
log.debug("Got pydocstyle settings: %s", settings)

# Explicitly passing a path to pydocstyle means it doesn't respect the --match flag, so do it ourselves
filename_match_re = re.compile(settings.get("match", DEFAULT_MATCH_RE) + "$")
if not filename_match_re.match(os.path.basename(document.path)):
return []

# Likewise with --match-dir
# We explicitly pass the path to `pydocstyle`, so it ignores `--match-dir`. But
# we can match the directory ourselves.
dir_match_re = re.compile(settings.get("matchDir", DEFAULT_MATCH_DIR_RE) + "$")
if not dir_match_re.match(os.path.basename(os.path.dirname(document.path))):
if not dir_match_re.match(Path(document.path).parent.name):
return []

args = [document.path]

if settings.get("convention"):
args.append("--convention=" + settings["convention"])
def append_if_exists(setting_name, arg_name=None):
"""Append an argument if it exists in `settings`."""
if setting_name not in settings:
return False

if isinstance(settings[setting_name], str):
value = settings[setting_name]
else:
value = ",".join(settings[setting_name])

args.append(f"--{arg_name or setting_name}={value}")
return True

if settings.get("addSelect"):
args.append("--add-select=" + ",".join(settings["addSelect"]))
if settings.get("addIgnore"):
args.append("--add-ignore=" + ",".join(settings["addIgnore"]))
if append_if_exists("convention"):
append_if_exists("addSelect", "add-select")
append_if_exists("addIgnore", "add-ignore")
elif append_if_exists("select"):
pass
else:
append_if_exists("ignore")

elif settings.get("select"):
args.append("--select=" + ",".join(settings["select"]))
elif settings.get("ignore"):
args.append("--ignore=" + ",".join(settings["ignore"]))
append_if_exists("match")

log.info("Using pydocstyle args: %s", args)

Expand Down
Loading