# Few choices of linter and formatter
## Formatter
[Black](https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html) with argument `--skip-string-normalization` so `'` and `"` can be mixed.
## Linter
### MyPy
[MyPy](https://mypy.readthedocs.io/en/stable/getting_started.html) is a must to verify type harmony. It's a type checking tool other than a linting tool. It should be used with pylint or flake8 or ruff.
### Pylint
[Pylint](https://pylint.readthedocs.io/en/latest/) is slower than flake8 but covers more rules. It's advised [to pair with ruff/flake8 and mypy](https://pylint.readthedocs.io/en/latest/#advised-linters-alongside-pylint).
An example of `.pylintrc` file
```ini
[FORMAT]
max-line-length=120
```
### Flake8
[Flake8](https://flake8.pycqa.org/en/latest/) is fast and pure python but not fast as ruff.
An example of `.flake8` file
```ini
[flake8]
max-line-length = 120
```
### Ruff
[Ruff](https://github.com/charliermarsh/ruff) is the fastest linter written in Rust. It's recommended [to use it with pylint](https://beta.ruff.rs/docs/faq/#how-does-ruff-compare-to-pylint) and [to replace with flake8](https://beta.ruff.rs/docs/faq/#how-does-ruff-compare-to-flake8).
An example of `ruff.toml` file that configures ruff to cover as many rules as possible of flake8 and pylint.
```toml
line-length = 120
# Select the rules
# Read more here https://beta.ruff.rs/docs/rules/
# By default, Ruff enables Flake8's E and F rules
# Pyflakes - F, pycodestyle - E, W
# flake8-builtins - A
# Pylint - PLC, PLE, PLR, PLW
select = ['E', 'F', 'W', 'A', 'PLC', 'PLE', 'PLR', 'PLW']
```
### Vscode configuration
An example of `.vscode/settings.json` that uses pylint, mypy, and ruff together
```json
{
"python.linting.pylintEnabled": true,
"python.linting.flake8Enabled": false,
"python.linting.enabled": true,
"python.linting.mypyEnabled": true,
"python.formatting.blackArgs": [
"--skip-string-normalization"
],
}
```
Note: ruff is enabled by [vscode ruff extension](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff)
# Resources
- [Python Linter Comparison 2022: Pylint vs Pyflakes vs Flake8 vs autopep8 vs Bandit vs Prospector vs Pylama vs Pyroma vs Black vs Mypy vs Radon vs mccabe](https://inventwithpython.com/blog/2022/11/19/python-linter-comparison-2022-pylint-vs-pyflakes-vs-flake8-vs-autopep8-vs-bandit-vs-prospector-vs-pylama-vs-pyroma-vs-black-vs-mypy-vs-radon-vs-mccabe/) (2022)
- [Python Code Quality: Tools & Best Practices](https://realpython.com/python-code-quality/) (2018)
- [The Big Ol' List of flake8 Rules](https://www.flake8rules.com/)
- [Vscode Python Linting](https://code.visualstudio.com/docs/python/linting)
- [Vscode Python Formatting](https://code.visualstudio.com/docs/python/editing#_formatting)
- [Vscode Ruff](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff)