Skip to main content

flake8-custom-error-messages

A flake8 plugin to customize the error messages emitted by other flake8 plugins

Installation

Install with pip

pip install flake8-custom-error-messages

Configuration Options

The package has one configuration option --custom-error-messages "<code> [<new_msg>" "<code> <new_msg>", ] that can have multiple values. Each one of them should start with the error code followed by a space and after that comes the new message to be displayed. You can also interpolate the original message as well.

flake8 some_file.py --format=custom_error_messages --custom-error-messages "TST000 {original_message} For more info,\
    check the styleguide at https://some-domain.com" "DTZ005 Use django.utils.timezone.now() instead of datetime.now()"

Given that you might be overriding multiple error messages, adding that to a configuration file is better than specifying them as part of the flake8 command. Each message should be in its own line (messages cannot span multiple lines).

# setup.cfg or tox.ini or .flake8
[flake8]
format = custom_error_messages
custom-error-messages =
    TST000 {original_message} For more info, check the styleguide at https://some-domain.com
    DTZ005 Use django.utils.timezone.now() instead of datetime.now()

Motivation

As a project grows and based on the libraries or framework it uses, it makes sense to change the default error messages emitted by flake8 plugins to recommend best practices followed by the project in question rather than a generic message. For example, adding a link to a style guide or best practices document adopted by the project. Another example is when a framework provides helpers to better deal with the issue in question: instead of the default messages emitted by flake8-datetimez and when the project already relies on Django, it's better to recommend using helpers from the django.utils.timezone module.

Usage with pre-commit

repos:
  - repo: https://github.com/pycqa/flake8
    rev: '6.0.0'
    hooks:
      - id: flake8
        args: [
          --format,
          'custom_error_messages',
          --custom-error-messages,
          'DTZ005 Use django.utils.timezone.now() instead of datetime.now()',
          'TST000 {original_message} For more info, check the styleguide at https://some-domain.com'
        ]
        additional_dependencies: [ "flake8-custom-error-messages==0.1.1" ]

License

This project is MIT licensed.

Metadata

Release files for flake8-custom-error-messages 0.1.1

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-custom-error-messages 0.1.1
File Size Uploaded
flake8-custom-error-messages-0.1.1.tar.gz 6.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flake8-custom-error-messages 0.1.1
File Interpreter ABI Platform
flake8_custom_error_messages-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 11.3 kB

Release files / flake8-custom-error-messages-0.1.1.tar.gz

Download URL flake8-custom-error-messages-0.1.1.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ff5f2cbc6da2fa6659a1f431e559b239382d2fb365a650b4b360107a76606de2
BLAKE2b-256 checksum
How to use checksums
c764c0fe933c89063ba7785cf7ac6a23dd001e9b176da1c44fc09ab089b0ce41
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.28.2

Release files / flake8_custom_error_messages-0.1.1-py3-none-any.whl

Download URL flake8_custom_error_messages-0.1.1-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2fda5ad00391d34b2b014e5b9dcb0d4976f53f2548be78b4b9ab3a6071cf3c4b
BLAKE2b-256 checksum
How to use checksums
03d90d2cafb312cc93fcc967aead87c923979107451fa8df2f0a2b6de1c9d1af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.28.2

Release history Release notifications | RSS feed

This release

0.1.1 This release

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