Search code examples
pylint

How to enforce using pylint human-readable messages?


Pylint allows using a string mnemonic when disabling a particular warning and I want to enforce that style in my team, because I deem it way more readable, consider:

while True:
# pylint: disable=W0632
# pylint: disable=unbalanced-tuple-unpacking

But I cannot find a way to really enforce it as a linter option. Is there any?


Solution

  • While I tried to write a custom pylint checker to catch and report exactly that style of comments, I stumbled upon a pylint`s own informational checker use-symbolic-message-instead, which implements this functionality!

    To show this in the output you should add it to enable list in the config, for example like this setup.cfg:

    [pylint]
    enable=use-symbolic-message-instead,
    

    After enabling, message report looks as

    ************* Module module.py:13:0: I0023: 'W0221' is cryptic: use '# pylint: disable=arguments-differ' instead (use-symbolic-message-instead)
    

    Note: However, this does not make pylint exit with non-zero code