Linter Formatter - makersacademy/simpleassettracker GitHub Wiki

Pylint

This project uses Pylint as a tool to check for errors in Python code. In particular:

  • Version 2.4.4
  • pylint==2.4.4 is already included in the <requirements.txt> file.

Introduction

The default coding style used by Pylint is close to PEP 8.

Specifying all the options suitable for your setup and coding standards can be tedious, so it is possible to use a configuration file to specify the default values. You can specify a configuration file on the command line using the --rcfile option

Usage and commands

Create a custom configuration file

# Using an *nix shell or cmd on Windows
pylint --generate-rcfile > .pylintrc
  • It creates a .pylintrc file under your current working directory

Remember the path at which it’s installed

which pylint

Editor and IDE integration

Invoking pylint

pylint AssetTracker/<file-name>.py
pylint AssetTracker/<folder-name>/<file-name>.py

Example usage

pylint AssetTracker/apps/assets/serializers.py

************* Module simpleassettracker.AssetTracker.apps.assets.serializers
AssetTracker/apps/assets/serializers.py:7:0: C0301: Line too long (182/100) (line-too-long)
AssetTracker/apps/assets/serializers.py:5:1: R0903: Too few public methods (0/2) (too-few-public-methods)

-----------------------------------
Your code has been rated at 6.67/10

Added current configurations

Ignores the following directories and files:

# line 10 - .pylintrc
ignore= migrations, admin.py

Does not show warnings:

disable=...
        ...
        missing-module-docstring,
	missing-class-docstring

Indentation unit is #tab:

# line 326
indent-string='\t'

Important: Please note that when you write code, you might need to do further configuration in your editor/IDE to specify indentation using tabs.

To decide

  • How to add pylint-django plug-in

  • urlpatterns

    It shows a wrong hanging indentation error (C0330). While in most cases pylint is right, urlpatterns comes with Django and we want to keep it as it is.

    • One solution is to add # pylint: disable=bad-continuation to every urls.py file like in the following example:
      # AssetTracker/apps/dashboard/urls.py
      
      # pylint: disable=bad-continuation
      # pylint: disable=invalid-name
      urlpatterns = [
          path('dashboard', dashboardPageView, name='home')
      ]
    • Another solution is to change indent-after-paren=4 to indent-after-paren=1 in the configuration file. The latter might affect blocks of code that have already been checked with pylint.

    It shows a naming convention error (C0103 - Constant name "urlpatterns" doesn't conform to UPPER_CASE naming style (invalid-name)). One solution is to add #pylint: disable=invalid-name to every urls.py

Documentation

Pylint User Manual

⚠️ **GitHub.com Fallback** ⚠️