Aaron's Blog

https://aaronchenwei.github.io/

View on GitHub
1 August 2023

Few choices of Python linter and formatter with VSCode

by aaronchenwei

Formatter

black is the uncompromising Python code formatter.

In Visual Studio Code, Black Formatter extension can be installed.

A basic usage in Visual Studio Code could be as follow:

  "[python]": {
    "editor.defaultFormatter": "ms-python.black-formatter",
    "editor.formatOnSave": true
  }

Linter

MyPy

Mypy is a static type checker for Python. Type checkers help ensure that you’re using variables and functions in your code correctly. With mypy, add type hints (PEP 484) to your Python programs, and mypy will warn you when you use those types incorrectly.

In Visual Studio Code, Mypy Type Checker extension can be installed.

Ruff

Ruff is an extremely fast Python linter, written in Rust. Ruff can be used to replace Flake8 (plus dozens of plugins), isort, pydocstyle, yesqa, eradicate, pyupgrade, and autoflake, all while executing tens or hundreds of times faster than any individual tool.

In Visual Studio Code, Ruff extension can be installed.