More signal, less noise.
Project description
Pylint-Ignore
More signal, less noise.
Project/Repo:
Code Quality/CI:
Name | role | since | until |
---|---|---|---|
Manuel Barkhau (mbarkhau@gmail.com) | author/maintainer | 2020-06 | - |
Developer Ergonomics
The main issue with pylint
is developer ergonomics. The messages produced by pylint
can be valuable, but you have to put in some work before you can enable it in your CI setup. If you have an established codebase, you'll probably have to research its configuration options, disable many invalid messages and/or blindly litter your code with pylint:disable
comments.
The goal of pylint-ignore
is to let you benefit from pylint
right now, without having to first wade through endless message noise and without having to delay using it because you don't have time to configure every detail.
How it Works
The pylint-ignore
command is a thin wrapper around the pylint
command.
$ pip install pylint-ignore
Installing collected packages: astroid,isort,pylint,pylint-ignore
...
Successfully installed pylint-ignore-2020.1004
Assuming you have a minimal configuration such as this setup.cfg
.
You can invoke pylint-ignore
like this:
$ pylint-ignore --rcfile=setup.cfg src/
************* Module src/mymodule.py
src/mymodule.py:290:0: W0102: Dangerous default value sys.argv[1:] (builtins.list) as argument (dangerous-default-value)
...
-------------------------------------------------------------------
Your code has been rated at 9.92/10 (previous run: 10.00/10, -0.08)
The pylint-ignore
command reads its own configuration file called pylint-ignore.md
. This file contains messages that should be ignored and it is automatically updated with new entries if you specify the --update-ignorefile
parameter.
$ pylint-ignore --rcfile=setup.cfg src/ --update-ignorefile
-------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 9.92/10, +0.08)
The pylint-ignore.md
will now look something like this:
$ grep --after-context=15 --max-count=1 "## File" pylint-ignore.md
## File src/mymodule.py - Line 290 - W0102 (dangerous-default-value)
- message: Dangerous default value sys.argv[1:] (builtins.list) as argument
- author : Manuel Barkhau <mbarkhau@gmail.com>
- date : 2020-07-17T21:15:25
```
289:
> 290: def main(args: Sequence[str] = sys.argv[1:]) -> ExitCode:
291: try:
```
The recommended approach to using pylint-ignore
is:
- If a message refers to a valid issue, update your code rather than ignoring the message.
- If a message should always be ignored (globally), then to do so
via the usual
pylintrc
orsetup.cfg
files rather than thispylint-ignore.md
file. - If a message is a false positive, add a comment of this form to your code:
# pylint:disable=<symbol> ; explanation why this is a false positive
In principal these are the same options you have with pylint
by itself. For this particular case I would prefer option 3.:
def main(args: Sequence[str] = sys.argv[1:]) -> ExitCode:
# pylint:disable=dangerous-default-value; args is not mutated, mypy ensures this
try:
With this change, when you run pylint-ignore --update-ignorefile
again, the entry in pylint-ignore.md
is removed.
What does this solve?
Problem1: Setup Cost
If you have a large existing project, your codebase will inevitably trigger many linting messages the first time you use pylint
. You might take a first pass and try to reduce the noise. During this first pass, you will encounter two issues:
- You will be overwhelmed at all the configuration options that you will need before you can trust that the output of
pylint
is meaningful. - You will find messages that might be useful in general, but after looking at particular cases, you find that the message is only useful sometimes.
An example of case 1. is perhaps the missing-function-docstring
message. You know that is going to be way more work than is justified for your project. Even if you could justify the work in principle and agree that the message is valid, if you did enabled it, you may find a pattern like this emerge:
def get_author_name() -> str:
"""Gets the author name and returns it as a string."""
In case it isn't obvious, the above doc-string is redundant because it adds no information that isn't already in the function signature. In other words, your colleagues are likely to pacify the linter by changing the code in ways that are at best a useless waste of time and at worst they are counterproductive.
Problem2: Time Constraint
As you investigate messages, you will inevitably run across some that you disagree with, if not in general, then at least for the particular cases you're dealing with. Take for example this message:
R0902 Too many instance attributes (10/7) (too-many-instance-attributes)
Where you put the cutoff for "too-many" is a subjective matter. I would caution against code-golfing such cases, just to satisfy the linter. It's a good message to have in general, if for no other reason than to wag a finger when somebody introduces some smelly code. Such a message can be a nudge to investigate further if there are reasonable ways to refactor the code and improve it.
With pylint-ignore
you have a file in your repository that serves as a reminder of such cases, until you have time to look at them. In the meantime, because any new messages generated by pylint
are not ignored, if any new code is introduced that is similarly smelly, you can catch it in your CI build.
CLI Usage
The pylint-ignore
ignore command does not have its own help message. The --help
argument will simply behave exactly the same as pylint --help
. These are the parameters the pylint-ignore
supports:
Usage: pylint-ignore [options]
Options:
--ignorefile=<FILE> Path to ignore file [default: pylint-ignore.md]
--update-ignorefile Update the ignorefile, adds new messages,
removes any messages that are no longer
emmitted by pylint (were fixed or disabled)
Normally the pylint-ignore
command will not update the pylint-ignore.md
file. This is appropriate for
- CI/CD build systems, where you want to report any issues that were newly introduced.
- Normal development, when you don't want to introduce any new issues.
If you fix an issue or explicitly disable a message, you can cleanup obsolete entries by adding the --update-ignorefile
argument.
$ pylint-ignore --update-ignorefile --ignorefile=etc/pylint-ignore.md \
--rc-file=setup.cfg src/ test/
Usually changes in line numbers will be detected and not cause your build to fail, but occasionally a message that was previously tracked may no longer be recognized. This can happen for example after you move some code to a different file. For such cases you may also want to use --update-ignorefile
(or deal with the actual issue while you're refactoring...).
Changelog for https://gitlab.com/mbarkhau/pylint-ignore
2020.1003
- Initial release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pylint-ignore-2020.1004.tar.gz
.
File metadata
- Download URL: pylint-ignore-2020.1004.tar.gz
- Upload date:
- Size: 22.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1.post20200616 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1adbcd986f9f1f8e38a147164088709d5e41fcf3877b3e0fc3e29d48f22b107b |
|
MD5 | db109dd7b2505472746e4a10c176c7fd |
|
BLAKE2b-256 | 6a41544bf69d65612b2d0d28998575b84a32483c1bcf2dea52b10496cc6ab374 |
File details
Details for the file pylint_ignore-2020.1004-py2.py3-none-any.whl
.
File metadata
- Download URL: pylint_ignore-2020.1004-py2.py3-none-any.whl
- Upload date:
- Size: 16.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1.post20200616 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 039e4cecd068ea3d9ae3a7de8f775cc530650e28ab213cbc86179c56c0cf022d |
|
MD5 | 280b7126026786931eda17bfe2f699a3 |
|
BLAKE2b-256 | 28fb589ef22a187b64b65c5ce4856d225e8ca2b0e1843f8b9c1cb7b80e9bfe7b |