{"id":2221,"library":"pylint-plugin-utils","title":"Pylint Plugin Utilities","description":"Pylint Plugin Utilities (version 0.9.0) provides a collection of helper functions and classes designed to simplify the development of custom Pylint checkers and transformers. It abstracts away common boilerplate and provides tools for AST manipulation and message suppression. The library maintains a steady release cadence, typically aligning with Pylint's own major versions to ensure compatibility.","status":"active","version":"0.9.0","language":"en","source_language":"en","source_url":"https://github.com/PyCQA/pylint-plugin-utils","tags":["pylint","plugin","linter","static analysis","code quality"],"install":[{"cmd":"pip install pylint-plugin-utils","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for Pylint plugin development and execution. Ensure compatibility with Pylint >= 2.16 for version 0.9.0 of this library.","package":"pylint","optional":false}],"imports":[{"note":"Decorator to suppress specific Pylint messages on functions or methods.","symbol":"suppress_message","correct":"from pylint_plugin_utils.utils import suppress_message"},{"note":"Helper to add a Pylint message from within a checker instance.","symbol":"add_message","correct":"from pylint_plugin_utils.messages import add_message"},{"note":"Utility for programmatically building Abstract Syntax Trees (ASTs).","symbol":"AstBuilder","correct":"from pylint_plugin_utils.ast_builder import AstBuilder"}],"quickstart":{"code":"# my_plugin.py\nfrom pylint.checkers import BaseChecker\nfrom pylint_plugin_utils.messages import add_message\nfrom pylint_plugin_utils.utils import suppress_message\n\n# Define a custom message ID and details\nMY_MSG = 'W9999'\nMY_MSG_ID = 'no-direct-print'\nMY_MSG_STR = 'Avoid calling \"print\" directly in production code.'\n\nclass NoPrintChecker(BaseChecker):\n    \"\"\"\n    Checks for direct calls to the 'print' function.\n    \"\"\"\n    name = 'no-print-checker'\n    priority = -1\n    msgs = {\n        MY_MSG: (\n            MY_MSG_STR,\n            MY_MSG_ID,\n            'Avoid using print for logging in production; use a proper logger instead.',\n        )\n    }\n\n    def visit_call(self, node):\n        \"\"\"Called for every function call.\"\"\"\n        if node.func.as_string() == 'print':\n            add_message(self, MY_MSG_ID, node=node)\n\n# Example of using suppress_message decorator\n@suppress_message('invalid-name')\ndef ThisFunctionIsAllowedToHaveAnInvalidName():\n    pass\n\ndef register(linter):\n    \"\"\"Register the checker with Pylint.\"\"\"\n    linter.register_checker(NoPrintChecker(linter))\n\n# To run this plugin:\n# 1. Save the above code as `my_plugin.py`.\n# 2. Create a test file, e.g., `test_code.py`:\n#    print(\"Hello, World!\")\n#    ThisFunctionIsAllowedToHaveAnInvalidName()\n# 3. Run Pylint with the plugin: `pylint --load-plugins=my_plugin test_code.py`\n#    This will report 'no-direct-print' for `print` and suppress 'invalid-name' for the function.","lang":"python","description":"This quickstart demonstrates how to create a basic Pylint checker using `pylint-plugin-utils` to detect direct calls to `print`. It also shows the use of the `suppress_message` decorator to exempt specific code from Pylint's default checks. The `register` function is the standard entry point for Pylint plugins."},"warnings":[{"fix":"Ensure your `Pylint` installation is version 2.16 or newer. Upgrade `Pylint` using `pip install --upgrade pylint`.","message":"Pylint version compatibility changed; `pylint-plugin-utils` 0.9.0 now requires `Pylint >= 2.16`.","severity":"breaking","affected_versions":"0.9.0 onwards"},{"fix":"This function was deprecated in 0.8.0. Plugins should use the standard `register(linter)` function in their module, and within it, call `linter.register_checker()` or similar methods directly.","message":"The `register_linter_extension` function has been removed.","severity":"breaking","affected_versions":"0.9.0 onwards"},{"fix":"This function was primarily used for older Pylint setups to manipulate `sys.path`. Ensure your plugin's dependencies are correctly available on `PYTHONPATH` or use Pylint's `--init-hook` option for path manipulation if necessary.","message":"The `fix_pythonpath` function has been removed.","severity":"breaking","affected_versions":"0.8.0 onwards"},{"fix":"To enable a plugin, Pylint must be invoked with `--load-plugins=your_plugin_module`. For more persistent configuration, define plugins in your `pyproject.toml` or `.pylintrc` file under the `[MASTER]` section using the `load-plugins` option.","message":"Pylint plugins are not automatically discovered by default; they must be explicitly loaded.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}