Code linters and formatters
- Published
TL;DR Linters flag bugs and bad practices Formatters fix your code to match style guides
Linting
Code linters perform static analysis on code to identify programming errors, detect bugs, point out stylistic issues, and highlight suspicious constructs using the abstract syntax tree (AST). By ensuring your code adheres to a style guide, code linting promotes and enforces best practices.
A linter typically alerts you to functions that are overly complex, suggests syntax improvements, and flags coding practices that deviate from established conventions or configurations.
For example, ESLint is a popular linter for JavaScript, while SonarLint is an IDE extension that provides linting support for code in VSCode. Popular configs such as Airbnb make it easy to start adopting strict practices in your projects
Formatters
Code formatters manage style elements like spacing, line breaks, and comments, helping to enforce programming and formatting rules that can be easily automated. This reduces future code diffs by allowing an automatic tool to handle formatting instead of relying on individual developers.
For example, Prettier is a popular code formatter that automatically formats code to ensure a consistent style across various languages.