Skip to main content

Flake8 linting plugins to handle common AI code agent issues

Project description

pyla-linter

A collection of Python linting tools designed to be used with flake8.

Features

Length Checker Plugin

A flake8 plugin that enforces configurable statement limits for classes and functions using AST-based analysis, excluding docstrings and comments from the count.

Installation

Install using Poetry:

poetry add pyla-linter

Or using pip:

pip install pyla-linter

Usage

The length checker integrates with flake8 as a plugin. Run it using:

# Check all Python files in current directory with our plugin
flake8 --select=EL

# Check specific files or directories
flake8 --select=EL src/
flake8 --select=EL myfile.py

# Use with all flake8 checks
flake8

# Use only our length checker plugin
flake8 --select=EL001,EL002

Configuration

Configure the length checker in your pyproject.toml file:

[tool.pyla-linters]
# Maximum statements for functions (default: 40)
max_function_length = 40

# Maximum statements for classes (default: 200)
max_class_length = 200

You can also configure via command line arguments using flake8's standard option system:

# Use with flake8 ignore/select options
flake8 --select=EL001  # Only check function length
flake8 --select=EL002  # Only check class length
flake8 --ignore=EL001  # Ignore function length violations

Error Codes

The length checker uses the following error codes:

  • EL001: Function exceeds maximum statement limit (error at 2x threshold)
  • EL002: Class exceeds maximum statement limit (error at 2x threshold)
  • WL001: Function exceeds warning statement threshold
  • WL002: Class exceeds warning statement threshold

Statement Counting Logic

The plugin uses AST-based analysis to count logical statements rather than physical lines, providing a more accurate measure of code complexity. It counts executable statements while excluding:

  • Docstrings
  • Comments
  • Empty lines
  • Pure whitespace

For nested structures:

  • Nested functions/classes are excluded from their parent's statement count
  • Each code element is evaluated independently
  • Decorators are included in the decorated element's line span but don't count as statements

The plugin implements a two-tier threshold system:

  • Warning: Issued when statement count exceeds the configured threshold
  • Error: Issued when statement count exceeds 2x the configured threshold

Examples

Function that would trigger EL001:

def long_function():  # Function definition
    """This is a docstring (not counted as a statement)."""
    
    # This is a comment (not counted)
    
    x = 1  # Statement 1
    y = 2  # Statement 2
    # ... more code statements
    return x + y  # Statement 41 (exceeds default limit of 40)

Class that would trigger EL002:

class LargeClass:  # Class definition
    """Class docstring (not counted as a statement)."""
    
    def method1(self):  # Method definitions don't count toward class statements
        self.value = 1  # Statement 1 (counts toward method, not class)
        return self.value  # Statement 2 (counts toward method, not class)
    
    def __init__(self):  # Init method
        self.data = []  # Statement 1 of class body
        # ... many more statements in class body
    
    # Class with 201 statements in its direct body (exceeds default limit of 200)

Integration with Existing Workflow

The length checker works seamlessly with other flake8 plugins:

# Run with multiple checks (flake8 automatically includes all installed plugins)
flake8

# Run only our length checker with other specific checks
flake8 --select=E,F,EL

# Include in existing CI/CD pipelines
poetry run flake8 src/

Development

Setup

# Clone the repository
git clone <repository-url>
cd pyla-linter

# Install dependencies
poetry install

# Run tests
poetry run pytest

# Run linting and formatting
poetry run poe autolint

Quality Checks

Before submitting changes, ensure all quality checks pass:

# Format code
poetry run poe format

# Run linting
poetry run poe lint

# Type checking
poetry run pyright

# Run tests
poetry run pytest

License

[License information would go here]

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

pyla_linter-1.3.1.tar.gz (83.6 kB view details)

Uploaded Source

Built Distribution

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

pyla_linter-1.3.1-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file pyla_linter-1.3.1.tar.gz.

File metadata

  • Download URL: pyla_linter-1.3.1.tar.gz
  • Upload date:
  • Size: 83.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyla_linter-1.3.1.tar.gz
Algorithm Hash digest
SHA256 3e8fd5bc486bca8865caa56c1ed8a5ce8cfa3fb1f1a2a179f2ca7317f24f23d0
MD5 721f1345196412c3ae33e99331244686
BLAKE2b-256 76b52189a4135e6a682b8d32ed1bc01f0c643ac198fb1beae81a8b2e1eab3cc1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyla_linter-1.3.1.tar.gz:

Publisher: pypi.yml on langadventurellc/pyla-linter

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

File details

Details for the file pyla_linter-1.3.1-py3-none-any.whl.

File metadata

  • Download URL: pyla_linter-1.3.1-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyla_linter-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 949ce00c0ddd7b7e6aa6cddc187fd5148f6aed9fcc8dc8f4ef1fcb5527237c15
MD5 0dae979fb61d87e001bb2dfc7134ef00
BLAKE2b-256 64a73441e67f7c853da3df24e764f988399922c339864f105fd94c906c17db11

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyla_linter-1.3.1-py3-none-any.whl:

Publisher: pypi.yml on langadventurellc/pyla-linter

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