Skip to main content

Pylint plugin to sort functions in Python code

Project description

pylint-sort-functions

A PyLint plugin that enforces alphabetical sorting of functions and methods within Python classes and modules.

Features

  • Function Organization: Enforces alphabetical sorting of functions within modules
  • Method Organization: Enforces alphabetical sorting of methods within classes
  • Public/Private Separation: Ensures public functions/methods come before private ones (underscore prefix)
  • Configurable Rules: Customizable message codes (W9001-W9003) for different violations
  • Clear Error Messages: Helpful messages indicating exactly what needs to be reordered

Installation

pip install pylint-sort-functions

Usage

Enable the Plugin

Add the plugin to your pylint configuration:

pylint --load-plugins=pylint_sort_functions your_module.py

Or add to your .pylintrc file:

[MASTER]
load-plugins = pylint_sort_functions

Or in pyproject.toml:

[tool.pylint.MASTER]
load-plugins = ["pylint_sort_functions"]

Example

❌ Bad (will trigger warnings):

class MyClass:
    def public_method_b(self):
        pass

    def _private_method_a(self):
        pass

    def public_method_a(self):  # Out of order!
        pass

✅ Good (follows sorting rules):

class MyClass:
    # Public methods
    def public_method_a(self):
        pass

    def public_method_b(self):
        pass

    # Private methods
    def _private_method_a(self):
        pass

Message Codes

  • W9001: unsorted-functions - Functions not sorted alphabetically within their scope
  • W9002: unsorted-methods - Class methods not sorted alphabetically within their scope
  • W9003: mixed-function-visibility - Public and private functions not properly separated

Warning

⚠️ This project is currently under active development and not ready for production use.

Key limitations:

  • Many core features are still being implemented
  • More unit tests need to be added
  • Documentation is incomplete
  • APIs and functionality may change significantly

Please check back later for a stable release.

Documentation

See hakonhagland.github.io/pylint-sort-functions

PyPI

See pylint-sort-functions

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_sort_functions-0.1.2.tar.gz (76.1 kB view details)

Uploaded Source

Built Distribution

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

pylint_sort_functions-0.1.2-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file pylint_sort_functions-0.1.2.tar.gz.

File metadata

  • Download URL: pylint_sort_functions-0.1.2.tar.gz
  • Upload date:
  • Size: 76.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for pylint_sort_functions-0.1.2.tar.gz
Algorithm Hash digest
SHA256 dda73f7f867448b3a51822197525d9101d5fc591e99afd2a2e8c6ef786e81f25
MD5 3b52b2204ca1cbeab1484f16f687c82f
BLAKE2b-256 d4b12e79020f4e5a42180e76a686a0aff470328e7f96f4a4d9fa3ccf791c7512

See more details on using hashes here.

File details

Details for the file pylint_sort_functions-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pylint_sort_functions-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 be1d06da0b7bd367f86565651d1c8aa2942b70bc17ee0bee15f17b210726d097
MD5 dda93fc655b7f563633cd15e7078aa52
BLAKE2b-256 a52be19f6a2b3677b187046d7b26b03ae26025e8a7c43d11e0c5fe7c388e3f60

See more details on using hashes here.

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