Skip to main content

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.

Metadata

Release files for flake8-no-else 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flake8-no-else 0.1.3
File Size Uploaded
flake8_no_else-0.1.3.tar.gz 3.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flake8-no-else 0.1.3
File Interpreter ABI Platform
flake8_no_else-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 6.7 kB

Release files / flake8_no_else-0.1.3.tar.gz

Download URL flake8_no_else-0.1.3.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
fece258f25613d42e14f3fd10b277b7c6863d12a792a4ee7e3cef208fc4e5444
BLAKE2b-256 checksum
How to use checksums
028733c5e055563d615615a1ce9562183ff3384af773f120f7bfddf5648afaa7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.8

Release files / flake8_no_else-0.1.3-py3-none-any.whl

Download URL flake8_no_else-0.1.3-py3-none-any.whl
Size 3.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
be1b577f05d1129f77bf5cb4828f0e907d9a41cbc4e4aeb494fd8a299a4203b0
BLAKE2b-256 checksum
How to use checksums
2582858250a54f5cb05e7c2ff78f9ade1ae4bed94b0640a2f4737833c7047c2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.8

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page