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.
Interview question
What is a key distinction between the primary roles of a linter and a human code reviewer?
- a.A linter identifies performance; reviewers validate security.
- b.A linter corrects syntax; reviewers optimize database queries.
- c.A linter enforces style; reviewers focus on logic and architecture.Correct
- d.A linter checks for logical flaws; reviewers ensure code readability.
Why? this is the answer
The card states a linter acts as a 'grammar and spell checker for your code's style,' enforcing formatting and naming. This 'frees up human code reviewers to focus on logic and architecture,' making option C correct. Option D is incorrect because it swaps these primary responsibilities; linters handle style, while human reviewers tackle logic.
Just read this? Test yourself on what you have been reading.
Read the original → en.wikipedia.org
- #code quality
- #automation
- #ci/cd
- #static analysis
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.
See open roles