Skip to main content

Pylint plugin with documentation and architecture rules.

Project description

pylint-tyrant

Pylint plugin with documentation and architecture rules inspired by eslint-plugin-tyrant.

The plugin currently ships these rules:

  • tyrant-enforce-doc-tag-order
  • tyrant-enforce-project-layer-dependencies
  • tyrant-enforce-package-layer-dependencies
  • tyrant-no-direct-error-instantiation
  • tyrant-require-docstring-for-public-api
  • tyrant-require-module-docstring
  • tyrant-require-empty-line-after-module-docstring
  • tyrant-prefer-single-line-docstring
  • tyrant-restrict-relative-imports-to-base-module

tyrant-enforce-project-layer-dependencies

Requires configured project directories to depend only on themselves or lower layers.

This rule uses --tyrant-layers:

pylint \
  --load-plugins=pylint_tyrant \
  --enable=tyrant-enforce-project-layer-dependencies \
  --tyrant-layers=lib,services,app \
  path/to/your_package

tyrant-enforce-package-layer-dependencies

Requires same-package module layers to be declared in the entry-module docstring and to depend only on themselves or lower layers.

This rule uses --tyrant-shared-modules. __init__.py is treated as the entry module automatically, configured same-directory module names such as base or types.py are treated as shared low-level modules, and every other module in the directory is treated as a feature module.

Prefix inheritance is disabled by default. Set --tyrant-inherit-layers-from-module-prefixes=y to let underscore-qualified modules inherit the layer of their longest declared module-name prefix. For example, bbb_unit_test.py and bbb_integration_test.py then inherit the layer declared by @module bbb, so they do not need to be listed separately and cannot import higher layers. Qualified entry modules such as __init___unit_test.py inherit the entry layer, and qualified configured shared modules such as types_unit_test.py inherit the shared layer.

Use @module for one ordered module layer and @module-group for one ordered flat peer layer:

"""Package docs.

@module materials - Core data.
@module-group paragraphs, lexicons - Peer modules derived from the same inputs.
@module metrics - Aggregates.
"""

Every feature module must be listed exactly once. Missing modules, extra listed modules, repeated modules, and upward imports are violations. Every @module and @module-group tag must also include a non-empty relationship description.

pylint \
  --load-plugins=pylint_tyrant \
  --enable=tyrant-enforce-package-layer-dependencies \
  --tyrant-shared-modules=base,types.py \
  path/to/your_package

Add --tyrant-inherit-layers-from-module-prefixes=y to that command only when prefix inheritance is wanted.

tyrant-require-docstring-for-public-api

Requires public classes, functions, and methods to have docstrings.

This rule currently treats names that do not start with _ as public. It checks:

  • top-level public classes
  • top-level public functions
  • public methods on public classes

Valid:

class UserService:
    """Load users."""

    def load_user(self) -> None:
        """Load one user."""

Also valid:

def load_user() -> None:
    """Load one user."""

Invalid:

def load_user() -> None:
    pass

tyrant-enforce-doc-tag-order

Requires recognized docstring tags to follow one configured order.

This rule reads tags written as @tag - value from module, class, and function docstrings. It only checks tags listed in tyrant-doc-tag-order.

Configure it in pyproject.toml like this:

[tool.pylint.main]
load-plugins = ["pylint_tyrant"]

[tool.pylint."messages control"]
enable = ["tyrant-enforce-doc-tag-order"]

[tool.pylint.tyrant-doc-tag-order]
tyrant-doc-tag-order = ["@remarks", "@param", "@returns"]

Command-line equivalent:

pylint \
  --load-plugins=pylint_tyrant \
  --enable=tyrant-enforce-doc-tag-order \
  --tyrant-doc-tag-order=@remarks,@param,@returns \
  path/to/your_package

Valid:

def load_user() -> User:
    """Load one user.

    @remarks - Used by the public API.
    @param - User id.
    @returns - Loaded user.
    """

Invalid:

def load_user() -> User:
    """Load one user.

    @returns - Loaded user.
    @param - User id.
    """

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pylint_tyrant-0.5.1.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pylint_tyrant-0.5.1-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file pylint_tyrant-0.5.1.tar.gz.

File metadata

  • Download URL: pylint_tyrant-0.5.1.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pylint_tyrant-0.5.1.tar.gz
Algorithm Hash digest
SHA256 a0e322c9407740c56886cfcab70ab85fb1433576944c94f78cfea62ec3ed3581
MD5 1f705a41549e15d6927df68b7918a8ee
BLAKE2b-256 718f6fdedc97d748525c3ce4c47f2bff287c7eb36fbe0eb35cf2001048bfd21c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylint_tyrant-0.5.1.tar.gz:

Publisher: publish.yml on otakutyrant/tyrant-rules

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pylint_tyrant-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: pylint_tyrant-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pylint_tyrant-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f6ea9dc18f0fc11904a890220ad6c55d39e8e9ce26b55d608cbc845d07781464
MD5 893fd7b31a209bd26ae83fc63bbf41d9
BLAKE2b-256 fa4c3d0f0bc0828e273f2946d87f05f6c5bf89f42fe2d55369e03561a9f0309f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylint_tyrant-0.5.1-py3-none-any.whl:

Publisher: publish.yml on otakutyrant/tyrant-rules

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page