pylama_pydocstyle.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. """pydocstyle support."""
  2. from argparse import ArgumentParser
  3. from pydocstyle import ConventionChecker as PyDocChecker
  4. from pydocstyle.violations import conventions
  5. from pylama.context import RunContext
  6. from pylama.lint import LinterV2 as Abstract
  7. class Linter(Abstract):
  8. """Check pydocstyle errors."""
  9. name = "pydocstyle"
  10. @classmethod
  11. def add_args(cls, parser: ArgumentParser):
  12. """Add --max-complexity option."""
  13. parser.add_argument(
  14. "--pydocstyle-convention",
  15. choices=list(conventions.keys()),
  16. help="choose the basic list of checked errors by specifying an existing convention.",
  17. )
  18. def run_check(self, ctx: RunContext): # noqa
  19. """Check code with pydocstyle."""
  20. params = ctx.get_params("pydocstyle")
  21. options = ctx.options
  22. if options and options.pydocstyle_convention:
  23. params.setdefault("convention", options.pydocstyle_convention)
  24. convention_codes = conventions.get(params.get("convention"))
  25. for err in PyDocChecker().check_source(
  26. ctx.source,
  27. ctx.filename,
  28. params.get("ignore_decorators"),
  29. params.get("ignore_inline_noqa", False),
  30. ):
  31. if convention_codes is None or err.code in convention_codes:
  32. ctx.push(
  33. lnum=err.line,
  34. text=err.short_desc,
  35. type="D",
  36. number=err.code,
  37. source="pydocstyle",
  38. )