Skip to main content

A flake8 plugin to enforce object calisthenics rule "keep entities small"

Project description

Flake8 Small Entities Plugin

flake8-small-entities is a Flake8 plugin that encourages developers to write smaller, more manageable entities by enforcing the Object Calisthenics rule "Keep Entities Small." The plugin analyzes Python code to ensure functions, classes, and modules do not exceed predefined line limits.

Installation

To install flake8-small-entities, use pip:

pip install flake8-small-entities

Usage

Once installed, the plugin will be automatically activated alongside Flake8. To analyze your project, simply run:

flake8 your_project_directory

Violations of the line limits for functions, classes, and modules will be flagged accordingly.

Configuration

The plugin allows customization of the maximum number of lines allowed for each entity type. You can specify these settings in your Flake8 configuration file or directly via command-line options.

Command-Line Options

  • --max-fn-lines: Maximum number of lines in a function (default is 15)
  • --max-class-lines: Maximum number of lines in a class (default is 50)
  • --max-module-lines: Maximum number of lines in a module (default is 200)

Config File Example

You can also set these options in a .flake8 configuration file in your project root:

[flake8]
max-fn-lines = 20
max-class-lines = 60
max-module-lines = 300

Rules Enforced

  • FSE100: Function has too many lines
  • FSE101: Class has too many lines
  • FSE102: Module has too many lines

Each rule will indicate where the entity exceeds the specified line count, helping developers to refactor code into smaller, more focused components.

Motivation

Adhering to the "Keep Entities Small" rule improves code readability, maintainability, and facilitates easier debugging and testing. Large entities often perform too many functions, making them difficult to understand and change.

Contributing

Contributions are welcome! If you have suggestions for improvements or encounter any issues, please open an issue or submit a pull request on our GitHub repository.

License

This plugin is distributed under the MIT License. The full license text is available in the LICENSE file included with the source code.

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

flake8_small_entities-0.1.0.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

flake8_small_entities-0.1.0-py3-none-any.whl (3.9 kB view hashes)

Uploaded Python 3

Supported by

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