Linting
- Linting ⇒ automated check of your code for programmatic and stylistic errors.
- This is done by using a tool known as a linter.
- A linter is a basic static code analyzer ⇒ it analyzes the code without running it.
- The term linting originally comes from a Unix utility for C.
- VS Code is prepared for linting and comes with a few linters.
- Linters are often used by companies to ensure a certain code standard.
Linters available in VS Code
- Pylint - Enforces a soft coding standard.
- pycodestyle - Enforces pep8, a much harder coding standard.
- PyFlakes - Analyzes programs and detects various errors (Errors that might show up at runtime).
- Bandit - Analyzes code to find common security issues.
- ... a few more.
- Flake8 - a combination of PyFlakes and pycodestyle
Example using Flake8
Flake8 found several code style errors in a small program that
Turn on Flake8 in VS Code
- You will be using the Command Palette (CP).
- You find CP in menu View → Command Palette.
- Enable linting: In CP, search for Enable/Disable Linting and switch to Enable.
- Enable Flake8: In CP, search for Select Linter and select flake8.
Flake8 is applied when you save a file and the result shows up in the Problem terminal.
Interested in code style? Look up the pep8 code guide by the inventor of Python.