Most of python programmers are familiar with pep8. The Pep8 isn’t a linter. I’ll explain what is the difference between pep8 and linters. Let’s see about what is linter first and pep8 later.
Concept of Linter:
- Lint refers to a general class of programming tools which analyze the source code and raise warning and errors about it.
- It simply means linter is a Static code analyzer.
- Examples:
- Syntax errors
- It also points out unused/undeclared variables.
- Reports calls to deprecated functions.
- Linters for Python Programming:
- Advantages:
- Detect and Prevent a large class of programming errors.
- Code review is done easily by addressing many mechanical and formatting problems automatically.
PEP8:
- It is style guidelines for python. We can call it as simple python style checker.
- It checks your python code against style guidelines which are defined in pep8.
- Examples:
- 4 space indents.
- line too long i.e greater than 79 characters.
- expected 1 blank line, found 0
- Advantages:
- Code style consistency.
- Improve code readability.
Difference between Linters and PEP8:
Let’s see sample program.
PEP8’s output:
PEP8 reports only style guide related errors. It doesn’t report errors like unused variable, unused import module etc.
Linter’s output:
Here,
Pylint reports various errors compared to pep8. This is the main difference between linter and pep8.
Pylint also checks code against pep8 style guide and reports pep8 errors. I’ll explain available linters for Python in next part.