Linting: Your Automated Code Style Guide
A linter is an automated style guide for your code, catching stylistic errors like inconsistent indentation or naming. It runs in your editor or CI pipeline to enforce team conventions, keeping style debates out of code reviews.
WHY IT EXISTS When multiple developers work on a project, their individual coding styles can create a messy, inconsistent codebase that's hard to read and maintain. Linting was created to solve this by automatically enforcing a single, shared set of style conventions, eliminating the need for manual correction and debate.
THE MENTAL MODEL A linter is a grammar and spell checker for your code's style. Instead of checking for correct English, it checks for correct formatting, naming, and patterns defined in a style guide. It frees up human code reviewers to focus on logic and architecture, not on whether a developer used tabs or spaces.
HOW IT WORKS A linter works by parsing your source code into a data structure called an Abstract Syntax Tree (AST). It then walks through this tree and applies a configured set of rules to its nodes. For example, a rule might check that all variable declarations use const instead of var, or that all function names are in camelCase. When a rule is violated, the linter reports an error, usually with the file and line number. Many modern linters can also automatically fix the errors they find.
WHEN TO USE IT Use a linter in any project with more than one developer to ensure consistency. It's also valuable for solo projects to maintain discipline. Integrate it early: first, in your code editor for instant feedback as you type, and second, in your CI/CD pipeline as a required check that must pass before code can be merged. This automates quality control.
WHEN NOT TO USE IT Avoid using a linter to enforce overly pedantic or subjective rules that create noise without adding real value. When introducing a linter to a large, existing codebase, don't enable hundreds of rules at once and demand a perfect score; this can halt development. Instead, apply it to new and changed files first, or use auto-fixing tools to establish a baseline.
ONE CANONICAL EXAMPLE ESLint is a popular linter for JavaScript. A team can configure it to use Google's JavaScript Style Guide. If a developer writes var name = "John";, ESLint will flag two issues: first, the use of var instead of let or const, and second, the use of double quotes instead of single quotes. This check can fail a CI build, forcing the developer to fix the style before their code is accepted.
Read the original → en.wikipedia.org
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.