Skip to main content

Automatically fix pytlint warnings/errors.

Project description

Build Status PyPI version

pydelinter

Pydelinter automatically generates unified-diffs of python source code that violate certain class of Pylint warnings. You can run this tool on your source code, inspect the diffs and apply the diffs as patches.

Installation

pip install pydelinter

Usage

$ delint -h
usage: delint [-h] [--msg_id MSG_ID] [--version] [-v] [-vv]
              file_path_or_folder

Command line tool for delinting certain pylint messages

positional arguments:
  file_path_or_folder  Path to a .py file or folder contain *.py files. This
                       relative path will be used to generate the unified diff
                       files.

optional arguments:
  -h, --help           show this help message and exit
  --msg_id MSG_ID      The pylint message that will be delinterd. Eg W0611
  --version            show program's version number and exit
  -v, --verbose        set loglevel to INFO
  -vv, --very-verbose  set loglevel to DEBUG

Examples:

            Running the below examples will generate an unified-diff file that can be used as a patch to apply the changes to git or Mercurial.
            delinter/main.py --msg W0611 foo/core.py

            To process multiple python files, provide a folder
            delinter/main.py --msg W0611 foo/

            Running, this command on the test file available with this repository:
            delinter/main.py --msg W0611 delinter/test/input

            --- a/delinter/test/input/test_unused_imports.py
            +++ b/delinter/test/input/test_unused_imports.py
            @@ -1,12 +1,7 @@
            -import unitest.mock.patch, unittest.mock.patch as p1
             import unitest.mock.patch, unittest.mock.patch as p2
            -import unittest as t, unittest as t2
            +import unittest as t2
             import unitest.mock.patch as p
            -import os
            -import pandas as pd, numpy as np
            -from collections.abc import defaultdict, OrderedDict
            -from itertools import filterfalse as _filterfalse
            -from collections.abc import x, y
            +from collections.abc import y
             from collections import *

             p2.mock() # use p2

Status of pylint messages supported

Message Id Message Status
W0611 unused-imports :heavy_check_mark:
W0404 reimported :heavy_check_mark:
W0108 unnecessary-lambda
W0107 unnecessary-pass
E1111 assignment-from-no-return
E0701 bad-except-order
E0711 not-implemented-raised
C0411 wrong-import-order
C0412 ungrouped-imports
C0410 multiple-imports
W0611 unused-variable
W0613 unused-argument
W0612 unused-wildcard-import
W0602 global-variable-not-assigned
R0102 simplifiable-if-statement
C0326 bad-whitespace
C0304 missing-final-newline
C0327 multiple-statements
C0305 trailing-newline
C0303 trailing-whitespace
C0325 superfluous-parens

(more items will be added to this list after carefully reviewing all message groups supported by Pylint)

Objectives of this tool

  1. The tool will only support addressing one pytlint warning/error at a time. This is provided through the msg_id argument.
  2. Any warnings that might need complex formatting will not be supported. We leave that to more sophisticated tools like Black.

Caveats

  1. When dropping statements, preceeding newlines/comments attached to the statement will be removed.
  2. Given how pylint reports warnings, the tool might have to be run on the same code base more than once, after applying the previous patch. For example, an (reimported) error on a particular statement, precededs an (unused-import) error. Therefore, re-running the program will force this statement to be tagged by pylint as an unused-import.
  3. The diffs produces by this tool is only as good as how pylint reports warning/errors and howthe LibCST yields the CST. Therefore, manual review of the patches is always a good idea (along with a good test suite).

Acknowledgements

This project has been set up using PyScaffold 3.2.3. For details and usage information on PyScaffold see https://pyscaffold.org/.

This library primarily depends upon the LibCST [https://github.com/Instagram/LibCST] library.

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

pydelinter-0.0.3.tar.gz (22.9 kB view details)

Uploaded Source

Built Distribution

pydelinter-0.0.3-py2.py3-none-any.whl (11.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pydelinter-0.0.3.tar.gz.

File metadata

  • Download URL: pydelinter-0.0.3.tar.gz
  • Upload date:
  • Size: 22.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.3

File hashes

Hashes for pydelinter-0.0.3.tar.gz
Algorithm Hash digest
SHA256 893077edb42585d3ddbcc5c1061c7790aef8b752f2b41139d14da99bf600078d
MD5 cb28df3bac8255bd08e5c81026fe8df1
BLAKE2b-256 1171e9810e5cbaaa2e6fd9bfc3c18f923f6f3986d1f2cf6d1979e7aa5719099d

See more details on using hashes here.

File details

Details for the file pydelinter-0.0.3-py2.py3-none-any.whl.

File metadata

  • Download URL: pydelinter-0.0.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.3

File hashes

Hashes for pydelinter-0.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c7b5f5517e976a79b8060a8ee61c7e5df4f5bffedac4fae1b31a9db52fc4e950
MD5 e20f99375158fba8c639a8b776a1af5d
BLAKE2b-256 b2b85c6210c33580eb2ff61d3854faf9ec2a1df4f573f7f892c4cd7fc5671421

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