What is Linting?

Linting is the process of using automated tools to analyze source code for potential errors, bugs, stylistic issues, and suspicious constructs without actually executing the code.

Quick Facts

Full NameCode Linting / Static Analysis
Created1978 (original lint for C by Stephen Johnson)
SpecificationOfficial Specification

How It Works

Linting (named after the original 'lint' tool for C language) is a form of static code analysis that examines source code to flag programming errors, bugs, stylistic errors, and suspicious constructs. Unlike testing which runs code, linters analyze code statically—without execution. Modern linters check for syntax errors, undefined variables, unused imports, inconsistent formatting, potential security issues, and violations of coding standards. Popular linters include ESLint for JavaScript, Pylint for Python, RuboCop for Ruby, and Prettier for code formatting. Linting is typically integrated into development workflows through IDE plugins (real-time feedback), pre-commit hooks (catch issues before commits), and CI/CD pipelines (enforce standards across teams). Linting improves code quality, maintains consistency, catches bugs early, and reduces technical debt.

Key Characteristics

  • Static analysis (no code execution required)
  • Catches errors before runtime
  • Enforces coding standards and style
  • Configurable rules and plugins
  • Integrates with IDEs and CI/CD
  • Can auto-fix many issues

Common Use Cases

  1. Enforcing team coding standards
  2. Catching common programming mistakes
  3. Maintaining consistent code style
  4. Security vulnerability detection
  5. Code review automation

Example

loading...
Loading code...

Frequently Asked Questions

What is the difference between linting and testing?

Linting performs static analysis on code without executing it, checking for syntax errors, style violations, and potential bugs. Testing runs the code to verify it behaves correctly. Linting catches issues like unused variables and formatting problems, while testing verifies functionality and logic. Both are complementary practices.

What is the difference between a linter and a formatter?

A linter analyzes code for errors and potential issues (like unused variables, possible bugs), while a formatter only handles code style (indentation, spacing, line breaks). ESLint is primarily a linter but has formatting rules. Prettier is purely a formatter. Many teams use both together - Prettier for formatting and ESLint for catching errors.

How do I set up ESLint in my JavaScript project?

Run 'npm init @eslint/config' to initialize ESLint with an interactive setup. This creates an eslintrc configuration file. Then run 'npx eslint .' to lint your code or 'npx eslint --fix .' to auto-fix issues. For VS Code, install the ESLint extension for real-time feedback while coding.

Should I use ESLint or Prettier, or both?

Use both for the best results. ESLint catches errors and enforces coding standards, while Prettier handles code formatting. Configure them together using eslint-config-prettier to disable ESLint's formatting rules that conflict with Prettier. This gives you error detection from ESLint and consistent formatting from Prettier.

How do I disable a linting rule for a specific line or file?

For a single line, add '// eslint-disable-next-line rule-name' above it. For a code block, wrap it with '/* eslint-disable rule-name */' and '/* eslint-enable rule-name */'. For entire files, add '/* eslint-disable rule-name */' at the top. You can also configure ignorePatterns in your ESLint config to exclude files.

Related Tools

Related Terms

Related Articles