Course contentsShow
← JavaScript
Lesson 2593 of 2,72352. Linting and FormattingFree lesson

What is Lint-Staged?

Understand how lint-staged runs linters only on Git-staged files to speed up pre-commit checks.

What is Lint-Staged?

You'll learn what lint-staged is and why it makes pre-commit checks faster by targeting only staged files.

The Performance Problem

Imagine you've modified just 2 files in a project with 500 JavaScript files. Running ESLint or Prettier on everything before each commit wastes time checking 498 unchanged files. That's like inspecting every room in a hotel when only two guests checked in today.

What Lint-Staged Does

Lint-staged is a tool that runs linters (like ESLint) and formatters (like Prettier) only on Git-staged files—the ones you're about to commit. It hooks into your Git workflow (typically via a pre-commit hook) and passes just the staged files to your configured tools.

Instead of:

eslint src/**/*.js  // checks ALL files

Lint-staged effectively runs:

eslint src/changed-file1.js src/changed-file2.js  // only staged files

Why This Matters

Speed is the main win. A full-project lint might take 30 seconds; checking 2 files takes under a second. This keeps your commit workflow snappy while still enforcing code quality rules exactly where they matter—on code that's actually changing.

It also prevents "linting the world" problems where touching one file triggers hundreds of unrelated lint errors from legacy code you didn't touch.

The Big Picture

Lint-staged doesn't replace ESLint or Prettier—it's a smart filter that decides which files get passed to them. Combined with Git hooks, it creates a checkpoint that ensures only clean, formatted, linted code enters your repository history.

Key Takeaway: Lint-staged speeds up pre-commit checks by running linters and formatters only on Git-staged files, not your entire codebase.