flake2lint

Tool and pre-commit hook to augment Flake8 noqa comments with PyLint comments.

Docs

Documentation Build Status Docs Check Status

Tests

Linux Test Status Windows Test Status macOS Test Status Coverage

PyPI

PyPI - Package Version PyPI - Supported Python Versions PyPI - Supported Implementations PyPI - Wheel

Activity

GitHub last commit GitHub commits since tagged version Maintenance PyPI - Downloads

QA

CodeFactor Grade Flake8 Status mypy status

Other

License GitHub top language Requirements Status

Installation

python3 -m pip install flake2lint --user

Contents

Usage

flake2lint

Augment Flake8 noqa comments with PyLint comments.

flake2lint [OPTIONS] [FILENAMES]...

Options

-v, --verbose

Show verbose output.

-r, --recursive

Permits the use of the pattern ‘**’ to match any files, directories and subdirectories.

Arguments

FILENAMES

Optional argument(s). Default None

Changed in version 0.3.0: Added the -v / --verbose option.

pre-commit hook

Sample .pre-commit-config.yaml:

- repo: https://github.com/domdfcoding/flake2lint
  rev: v0.4.0
  hooks:
  - id: flake2lint

See pre-commit for further information.

Supported Flake8 Codes

flake2lint currently augments the following flake8 codes:

  • A001redefined-builtin

    New in version 0.4.0.

  • A002redefined-builtin

  • A003redefined-builtin

Contributions to add support for more codes are more than welcome. The relevant code is here.

Example

Before:

class FancyDialog(wx.Dialog):

    def __init__(
            self,
            parent,
            id=wx.ID_ANY,  # noqa: A002
            title="My Fancy Dialog",
            pos=wx.DefaultPosition,
            size=wx.DefaultSize,
            style=wx.DEFAULT_DIALOG_STYLE,
            name=wx.DialogNameStr,
            data=None
            ): ...

After:

class FancyDialog(wx.Dialog):

    def __init__(
            self,
            parent,
            id=wx.ID_ANY,  # noqa: A002  # pylint: disable=redefined-builtin
            title="My Fancy Dialog",
            pos=wx.DefaultPosition,
            size=wx.DefaultSize,
            style=wx.DEFAULT_DIALOG_STYLE,
            name=wx.DialogNameStr,
            data=None
            ): ...

Public API

pre-commit hook to augment Flake8 noqa comments with PyLint comments.

Functions:

find_noqa(physical_line)

Search a string for # noqa: ... comments.

find_pylint_disable(physical_line)

Search a string for # pylint: disable=... comments.

process_file(filename)

Augment Flake8 noqa comments with PyLint comments in the given file.

find_noqa(physical_line)[source]

Search a string for # noqa: ... comments.

Parameters

physical_line (str)

Return type

Optional[Match[str]]

find_pylint_disable(physical_line)[source]

Search a string for # pylint: disable=... comments.

Parameters

physical_line (str)

Return type

Optional[Match[str]]

process_file(filename)[source]

Augment Flake8 noqa comments with PyLint comments in the given file.

Parameters

filename (Union[str, Path, PathLike])

Return type

bool

Returns

True if the file contents were changed. False otherwise.

Contributing

flake2lint uses tox to automate testing and packaging, and pre-commit to maintain code quality.

Install pre-commit with pip and install the git hook:

python -m pip install pre-commit
pre-commit install

Coding style

formate is used for code formatting.

It can be run manually via pre-commit:

pre-commit run formate -a

Or, to run the complete autoformatting suite:

pre-commit run -a

Automated tests

Tests are run with tox and pytest. To run tests for a specific Python version, such as Python 3.6:

tox -e py36

To run tests for all Python versions, simply run:

tox

Type Annotations

Type annotations are checked using mypy. Run mypy using tox:

tox -e mypy

Build documentation locally

The documentation is powered by Sphinx. A local copy of the documentation can be built with tox:

tox -e docs

Downloading source code

The flake2lint source code is available on GitHub, and can be accessed from the following URL: https://github.com/domdfcoding/flake2lint

If you have git installed, you can clone the repository with the following command:

git clone https://github.com/domdfcoding/flake2lint
Cloning into 'flake2lint'...
remote: Enumerating objects: 47, done.
remote: Counting objects: 100% (47/47), done.
remote: Compressing objects: 100% (41/41), done.
remote: Total 173 (delta 16), reused 17 (delta 6), pack-reused 126
Receiving objects: 100% (173/173), 126.56 KiB | 678.00 KiB/s, done.
Resolving deltas: 100% (66/66), done.
Alternatively, the code can be downloaded in a ‘zip’ file by clicking:
Clone or download –> Download Zip
Downloading a 'zip' file of the source code.

Downloading a ‘zip’ file of the source code

Building from source

The recommended way to build flake2lint is to use tox:

tox -e build

The source and wheel distributions will be in the directory dist.

If you wish, you may also use pep517.build or another PEP 517-compatible build tool.

License

flake2lint is licensed under the MIT License

A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.

Permissions Conditions Limitations
  • Commercial use
  • Modification
  • Distribution
  • Private use
  • Liability
  • Warranty

Copyright (c) 2021 Dominic Davis-Foster

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.

View the Function Index or browse the Source Code.

Browse the GitHub Repository