Skip to main content

A Flake8 plugin to checking module level docstrings, future-imports, and dunders as specified in PEP 8

Project description

Module Level Lint

A Flake8 plugin to enforce code quality by checking module level docstrings, future-imports, and module level dunders as specified in PEP 8

Installation

You can install this plugin via pip:

pip install module-level-lint

Usage

After installation, you can use this plugin with the flake8 command. Here's how to run it:

flake8 [path]

To show only module level lint errors, run:

flake8 --select MLL [path]

To show only specific errors

flake8 --select MLL001,MLL002 [path]

To apply formatting

flake8 --select MLL [path] --fix

Features

Lint

Module Docstring Check: Ensure that your docstrings are always at the top of the file

  • Linting Error: MLL001

Example:

import random

# Bad: Module docstring is not at the top of the file
"""This is a docstring"""

def foo():
    pass
# Good: Docstring present at the top of the file
""" This is a docstring. """

def foo():
    pass

Future-Imports Check: Ensure that future-imports are always at the top after module docstrings

  • Linting Error: MLL002

Example:

import random

# Bad: Future-imports is not at the top of the file
from __future__ import print_function
# Good: Future-imports is at the top of the file
from __future__ import division

import random
  • Linting Error: MLL003

Example:

from __future__ import print_function

# Bad: Docstring is not at the top of the file
"""This is a docstring."""
"""This is a docstring."""

# Good: Future-imports is at the top of the file after docstring
from __future__ import division

Module-Level Dunders: Ensure that module level dunders are always at the top after future-imports or docstrings

  • Linting Error: MLL004

Example:

import random

# Bad: Module level dunder after imports
__all__ = ["foo"]

def foo():
    pass
# Bad: Module level dunder before docstring
__all__ = ["foo"]

"""This is a docstring"""

def foo():
    pass
def foo():
    pass

# Bad: Module level dunder after code
__all__ = ["foo"]
# Good: Module level dunder at the top of the file
__all__ = ["foo"]

def foo():
    pass

Format

With the --fix flag, this plugin will try to format the files that have no rule violations. It will fix the newlines in the following format:

"""Docstring goes here"""   # An empty line after docstrings

from __future__ import annotations  # An empty line after future imports

__all__ = ["foo"]  # An empty line after module dunders

import random   # Rest of the code


def foo():
    return random.randint(1, 10)

Configuration

This plugin doesn't require any specific configuration, but you can include its error codes in your Flake8 configuration file to disable or enable specific checks:

[flake8]
extend-ignore = MLL001, MLL002, MLL003, MLL004

Contributing

Contributions, issues, and feature requests are welcome! Please feel free to submit a pull request or open an issue.

License

This plugin is licensed under the MIT License.

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

module_level_lint-0.2.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

module_level_lint-0.2.1-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file module_level_lint-0.2.1.tar.gz.

File metadata

  • Download URL: module_level_lint-0.2.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for module_level_lint-0.2.1.tar.gz
Algorithm Hash digest
SHA256 e7cf0adddf38a6154e426fe9f69cf7647a5b443766250791ca580a2950066708
MD5 7a04f94fcedfc1e37cc4cee02578d201
BLAKE2b-256 b92df8f81f025ff228cb0f98ea7a52ffa75b95b825718519b81ca0b615ff1068

See more details on using hashes here.

File details

Details for the file module_level_lint-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for module_level_lint-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 db1e1568ab19c088e3fb4acd69089c0c69adf573ecfa2cf0f763420795e10e3b
MD5 a8836d2fd50ccbe0aebf01dc768d373b
BLAKE2b-256 da37689161c098616823a559c7ee0cc01f1582424db48042475fca172d07e451

See more details on using hashes here.

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