serhii.net

In the middle of the desert you can say anything you want

24 Sep 2024

Setting up pylint as external tool in pycharm

My changes:

  • arguments: --msg-template="{abspath}:{line:5d},{column:2d}: {C}/{msg} ({symbol})" --output-format=colorized "$FilePath$"
    • note ", otherwise it failed for me, and {C} — for the message class see man page (or below) for list of format string options.
  • output filters for on-click: $FILE_PATH$:\s*$LINE$\,\s*$COLUMN$

I had two options as separate tools:

  • pylint for a single file
  • pylint for the module — same as above, but
    • with $FileParentDir$ at the end.
    • --recursive=y — fails on no __init__.py otherwise

Worked neatly with a .pylintrc file in repo root with e.g.

[tool.pylint.main]

[tool.pylint.basic]
# "too-few-public-methods", disable
min-public-methods=0

function-naming-style="camelCase"
argument-naming-style="camelCase"
method-naming-style="camelCase"
variable-naming-style="camelCase"
attr-naming-style="camelCase"

[tool.pylint."messages control"]
disable = [
    "fixme",  # TODOs
    "import-error",  # runner has them in its environment
    "import-outside-toplevel",  # explicit requirement of XXX to import where used
    "duplicate-code"  # entangling different extensions/modules is not the solution
]

Pylint format string options from man pylint:

path   relative path to the file

abspath
	  absolute path to the file

line   line number

column column number

end_line
	  line number of the end of the node

end_column
	  column number of the end of the node

module module name

obj    object within the module (if any)

msg    text of the message

msg_id the message code (eg. I0011)

symbol symbolic name of the message (eg. locally-disabled)

C      one letter indication of the message category

category
	  fullname of the message category

For example, the former (pre 1.0) default format can be obtained with:

  pylint --msg-template='{msg_id}:{line:3d},{column}: {obj}: {msg}'

Bonus

If I have this post open, I’ll need this one anyway: Messages control - Pylint 4.0.0-dev0 documentation

Nel mezzo del deserto posso dire tutto quello che voglio.
comments powered by Disqus