Skip to content

bana513/python-linting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Linting: flake8

  • Style Guide Enforcement
  • Check code syntax
  • Provide instructions on how to clean it
  • Prevent things like syntax errors, typos, bad formatting, incorrect styling, etc
  • If you working in the team, it saves time for people who are reviewing your code (no need to distrust for typos and formatting issues). Read more
  1. pip install flake8
  2. Install VSCode plugin: cornflakes-linter

  3. Settings.json:

    {
        "cornflakes.linter.executablePath": "path/to/venvs/myvenv/bin/flake8",
        "cornflakes.linter.run": "onType"
    }

Import formatting: isort

  • Sort imports alphabetically
  • Automatically separated into sections and by type.
  1. pip install isort
  2. isort mypythonfile.py mypythonfile2.py
    
    isort .
    
    isort **/*.py
    
    isort mypythonfile.py --diff
    
    #  only applying changes if they don't introduce syntax errors
    isort --atomic .

Code formatter: black

  • Can be forced to check with GitHub Actions on push or pull requests
  1. pip install black
    • VSCode: Right click + Format Document
    • black my_file.py
      black .
      Sometimes needs to refresh project in VSCode
  2. isort compatibility
    pyproject.toml:
        [tool.isort]
        profile = "black"
        multi_line_output = 3

Static type checker: mypy

  1. pip install mypy
  2. mypy .

About

Python linting, type checking, formatting

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages