Skip to main content

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

Project description

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.

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-custom-error-messages-0.1.1.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file flake8-custom-error-messages-0.1.1.tar.gz.

File metadata

File hashes

Hashes for flake8-custom-error-messages-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ff5f2cbc6da2fa6659a1f431e559b239382d2fb365a650b4b360107a76606de2
MD5 6304b229d3196746d340eeeea70f9b7a
BLAKE2b-256 c764c0fe933c89063ba7785cf7ac6a23dd001e9b176da1c44fc09ab089b0ce41

See more details on using hashes here.

File details

Details for the file flake8_custom_error_messages-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for flake8_custom_error_messages-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2fda5ad00391d34b2b014e5b9dcb0d4976f53f2548be78b4b9ab3a6071cf3c4b
MD5 0817e1d47f05aa515a2e92d09fd631db
BLAKE2b-256 03d90d2cafb312cc93fcc967aead87c923979107451fa8df2f0a2b6de1c9d1af

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