Python pylint

From wikinotes

Documentation

official docs https://pylint.readthedocs.io/en/latest/#
list of messages http://pylint-messages.wikidot.com/all-messages
list of error codes http://pylint-messages.wikidot.com/all-codes

Location

{cwd}/[.]pylintrc
{cwd}/pyproject.toml (containing a tool.pylint section)
{cwd}/setup.cfg (containing [pylint] section)
$PYLINTRC=
~/[.config/].pylintrc global pylint configuration
/etc/pylintrc

Install

sudo pacman -S python-pylint

Config

pylint --generate-rcfile > ~/.pylintrc  # create config

PyCharm Emulation


I built this so my linting was more consistent with Chris's. It is not 100%, but feels close enough.

# vim: ft=dosini
# generate full: `pylint --generate-rcfile > pylintrc`

[MASTER]
#load-plugins = chromite.cli.cros.lint  # chromium project's docstring typechecker
load-plugins = pylint.extensions.docparams
accept-no-param-doc = no
accept-no-raise-doc = no
accept-no-return-doc = no
accept-no-yields-doc = no
default-docstring-type = google

[FORMAT]
max-line-length = 120


[MESSAGES CONTROL]

# PyCharm Emulation

disable=
        # ============
        # bad-pracices
        # ============
        W0123,  # Use of eval
        W0221,  # Parameters differ from overridden X method
        R1710,  # Either all return statements return val, or none
        E1305,  # Too many arguments for format string
        W0201,  # Attribute X defined outside of __init__
        W0107,  # Unecessary pass statement
        C0123,  # Using type() instead of isinstance()
        W0125,  # Using a conditional statement with a constant value
        W1401,  # Anomalous backslash in string. String might be missing an r prefix
        R1705,  # Unecessary 'elif/else' after 'return'
        R1720,  # Unecessary 'elif/else' after 'raise'
        R1723,  # Unecessary 'elif/else' after 'break'
        W0613,  # Unused Argument
        W0706,  # The except handler raises immediately
        E1120,  # Missing argument 'X' in constructor call
        R1721,  # Unecessary use of list-comprehension
        C0302,  # Too many lines in module (max 1000)
        R0904,  # Too many public methods (max 20)
        R0912,  # Too many branches (conditionals) (max 12)
        R0913,  # Too many arguments (max 5)
        R0914,  # Too many local variables (max 15)
        R0915,  # Too many statements (lines per func) (max 50)
        C0303,  # Trailing Whitespace
        # ====
        # PEP8  
        # ====
        C0103,  # Argument doesn't conform to snake_case
        # =======
        # spacing
        # =======
        C0326,  # Exactly one space required after comma
        # =======
        # classes
        # =======
        R0902,  # Too many instance attributes
        W0235,  # Useless super delegation in method X
        # =============
        # documentation
        # =============
        C0115,  # Missing class docstring
        C0116,  # Missing function or method docstring
        W9011,  # X Missing return documentation
        W9012,  # X Missing return type documentation
        W9015,  # X Missing in parameter documentation
        W9016,  # X Missing in parameter type documentation
        W9006,  # X not documented as being raised
        W9017,  # 'X, ...' differing in parameter documentation
        W9018,  # 'X, ...' differing in parameter type documentation
        W9008,  # Redundant returns documentation (incorrect return docs)
        W0511,  # (simply prints TODO doc-comments)
        # =======
        # python3
        # =======
        R0205,  # useless-object-inheritance (py3)

Usage

pytlint2 file.py

IDE Integration

vim

" ~/.vimrc:
Plugin 'https://github.com/dense-analysis/ale'
let g:ale_linters = {'python': ['pylint']}
let g:ale_python_pylint_change_directory = 0

" open python file with CWD as tma/ dir

pycharm

File > Settings > Plugins> Pylint (Install/Restart)
File > Settings > Pylint (set executable, test, && apply)
File > Settings > Editor > Inspections > Pylint > Severity > [x] Pylint real-time scan

visualstudio

Plugin:
    (Ctrl+Shift+P) Install Extensions > ms-python.python
usage:
    * open tma/ directory in vscode.
    * popup prompts you to enable intellisense
    * popup will detect pylintrc, and prompt to enable pylint