Linting

2 Contributors
Last updated 25 Nov 08:07

TL;DR

Avoid stress with Linter! Let it analyze your code and find bugs and stylistic errors. Linter should be your best friend.

What Is a Linting

Lint, or a Linter, is a very useful tool for automated analyzing of your source code to look for bugs and stylistic errors. Linter helps to ensure that your code does not include any structural issues which can make your code harder to maintain. Linting became a verb and it is the process of flagging the functional and structural problems. The Lint tool is a basic static code analyzer. The term Linting comes from a Unix utility for C.

Linting
Source: Linting

Linters are available for most programming languages. Here are the most common ones:

Why You Might Want the Linting

  • Linting helps you reduce errors and improve the quality of your code.
  • It is an automated check and it saves the developers’ time.
  • It improves the code readability. It unifies the style within the team and therefore safes the time during the Code Review.
  • It can automatically correct some mistakes (auto fix).

Problems the Linting Solves

How to Implement the Linting

  • Linting should happen early in the development phase, before the Code Review and testing. It has to be integrated into the developer environment.
  • Implement the Linting to the Continuous Integration.
  • Ensure that your code follows standard rules. Otherwise, the Linter flags more than you need. You can override the default settings or disable rules for specific files but it can bring more trouble.
  • Turn on the auto fixer for as many errors as possible. After the implementation, fix all the issues from the auto fix.
  • Make a separate pull request so the other developers understand that you started using a Linter.

Common Pitfalls of the Linting

  • A high number of searched errors can lead to high false positive and false negative rates. Also, automatically corrected errors have to be rewritten by hand.
  • Too many rules and therefore too many notifications can get annoying. Turn on the auto fixer and get rid of as many marked errors as possible.
  • Implementing the Linting without informing your colleagues can lead to misunderstandings.
  • Do not Lint on demand. If you have it, use it.

Resources for the Linting