Previously we looked at how to -- Style your Python Code like a Pro -- using the tool, Black.
However, what about if there is a typo in your code? For example, a missing colon or closing bracket. This is where linting comes into play.
Linting is the process of running a program that will analyze code for potential errors.
A popular Python linter that I like to use is Flake8. Below shows an example:
# Install
$ pip install flake8
# Sample file
$ cat print_devices.py
def print_devices(devices) # missing :
for d in devices:
print(d)
# Perform lint
$ flake8 print_devices.py
print_devices.py:1:26: E999 SyntaxError: invalid syntax
print_devices.py:2:5: E113 unexpected indentation
Linting isn't only limited to Python. For example, there is Ansible Lint, which validates your Ansible playbooks (see here https://github.com/ansible-community/ansible-lint).