Skip to main content

A Pylint plugin for enforcing Clean Architecture principles and Design Patterns.

Project description

pylint-clean-architecture

A powerful, highly-opinionated Pylint plugin for enforcing Clean Architecture (The Onion Architecture) principles in Python projects.

This linter acts as a "GPS" for your codebase, preventing technical debt by strictly enforcing architectural boundaries, dependency rules, and design patterns.

Features

  • Layer Boundary Enforcement: Prevents inner layers (Domain, UseCase) from importing outer layers (Infrastructure, Interface).
  • Dependency Injection Checks: Forbids direct instantiation of infrastructure classes in UseCases.
  • Design Pattern Enforcement: Detects "naked returns" from repositories, delegation anti-patterns, and more.
  • Law of Demeter: Enforces loose coupling by flagging deep method chains.
  • Contract Integrity: Ensures Infrastructure classes correctly implement Domain Protocols.
  • Anti-Bypass Guard: Prevents "lazy" disabling of linter rules without justification.

Installation

pip install pylint-clean-architecture

Usage

Add the plugin to your pyproject.toml or Pylint configuration:

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

Run Pylint as usual:

pylint src/

Configuration

The linter is configured via [tool.clean-arch] in pyproject.toml.

[tool.clean-arch]
# 1. Project Type Presets (generic, cli_app, fastapi_sqlalchemy)
project_type = "generic"

# 2. Strict Visibility Enforcement
visibility_enforcement = true

# 3. Custom Layer Mapping (Map directory regex patterns to layers)
[tool.clean-arch.layer_map]
"services" = "UseCase"
"infrastructure/clients" = "Infrastructure"
"domain/models" = "Domain"

Rules

See RULES.md for a complete catalog of enforced rules and "Clean Fix" examples.

Contributing

  1. Fork the repo.
  2. Install dependencies: make install.
  3. Run tests: make test.
  4. Submit a PR.

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

clean_architecture_linter_plugin-1.1.1.tar.gz (23.8 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file clean_architecture_linter_plugin-1.1.1.tar.gz.

File metadata

File hashes

Hashes for clean_architecture_linter_plugin-1.1.1.tar.gz
Algorithm Hash digest
SHA256 4e65b22d00e6e5fa0d69b5765ff2330f8578a7adfd66e975fac862da8fb3f27a
MD5 b4bc21420c95e96a7327ee850836cbc8
BLAKE2b-256 feafb1e471dcf3c18eb4301e1108ca33b7ef3eb103b69edaef1855970c07eb26

See more details on using hashes here.

Provenance

The following attestation bundles were made for clean_architecture_linter_plugin-1.1.1.tar.gz:

Publisher: publish.yml on noah-goodrich/pylint-clean-architecture

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

File details

Details for the file clean_architecture_linter_plugin-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for clean_architecture_linter_plugin-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 18ea86449e7d302e80a8552444a621cf4aa8cb4d9e94faaa249fef71b1d52744
MD5 6317f0ce34f453c96a101401f89586c3
BLAKE2b-256 2c1420728fd97c5ef904e2c0726b00d762dd142e64add6e5ca0efb8a3ed964a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for clean_architecture_linter_plugin-1.1.1-py3-none-any.whl:

Publisher: publish.yml on noah-goodrich/pylint-clean-architecture

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