Skip to main content

A flake8 plugin to enforce object calisthenics rule "do not use ELSE"

Project description

flake8-no-else

flake8-no-else is a plugin for Flake8 that promotes cleaner and more maintainable code by enforcing the Object Calisthenics rule: "Do Not Use ELSE." This plugin discourages the use of else, elif, and ternary operators in Python code, encouraging developers to use guard clauses and other techniques to keep code flat and prevent deep nesting.

Installation

You can install flake8-no-else using pip:

pip install flake8-no-else

Usage

Once installed, flake8-no-else will automatically integrate with Flake8. Run Flake8 as you normally would:

flake8 your_project_directory

flake8-no-else will check for the presence of else, elif, and ternary expressions and flag them as violations.

Rules Enforced

  • NOE100: Use of else
  • NOE101: Use of elif
  • NOE102: Use of ternary operator (condition ? true_value : false_value)

Configuration

There are no specific configurations required for flake8-no-else. It works out-of-the-box once installed. However, you can exclude specific files or directories through your standard .flake8 configuration file.

Example .flake8 configuration:

[flake8]
exclude = tests/*
max-line-length = 120

Motivation

The motivation behind this plugin is to encourage developers to follow the "Do Not Use ELSE" rule of Object Calisthenics. This rule aims to reduce the complexity of code by avoiding multiple conditional branches, which often lead to deeply nested structures and can make code harder to read and maintain.

Contributing

Contributions to flake8-no-else are welcome! If you have suggestions for improvements or have found a bug, please open an issue or submit a pull request.

License

Distributed under the MIT License. See LICENSE file for more information.

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

Uploaded Source

Built Distribution

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

flake8_no_else-0.1.2-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: flake8_no_else-0.1.2.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.8

File hashes

Hashes for flake8_no_else-0.1.2.tar.gz
Algorithm Hash digest
SHA256 539f3ca1fe2079252a06abb1430a3be24c871602b07da5f8024a83faf0b5afa7
MD5 44dc8d9b0e7aaff0049cb9a1e342cc8c
BLAKE2b-256 0e5a788ee4dbc000de01d041efc047f4adb6204124076075e3eb1cd30b0c8a00

See more details on using hashes here.

File details

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

File metadata

  • Download URL: flake8_no_else-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.8

File hashes

Hashes for flake8_no_else-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 27aacfef7cf251185461098743d2a457c14980968654245027c29269e61611c3
MD5 99a5ae64b37dfae5d0e22c4834681dfb
BLAKE2b-256 eca933fc975814d4c28e2415451a702c4a160577bd154b40ed6d1feb4180306e

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