ESLint, Prettier and TypeScript Checks in CI
On this page
Learning Objective
Set up an automated quality pipeline: Prettier or a similar formatter for style, ESLint with TypeScript, React Hooks and accessibility rules for bugs and patterns, type checking with tsc, and enforcement through editor integration, pre-commit hooks and continuous integration, so code review can focus on design rather than style.
Concept Explanation
Code review time is expensive, and spending it on spacing, quotes or a forgotten dependency in a hook is a waste. The modern answer is to let tools enforce everything that can be checked mechanically and leave humans to judge design, naming and behavior. Three categories of tools cover most of it: a formatter, a linter and a type checker, each with a distinct job.
A formatter such as Prettier, or the faster Biome, rewrites code into one consistent style automatically: indentation, line length, quotes, trailing commas. It has few options by design, which ends style debates. Because it rewrites rather than reports, it should run on save in the editor and as a check in CI. Linters should not duplicate formatting rules, so the formatter owns style entirely.
A linter analyzes code for likely bugs and risky patterns. ESLint is the standard for JavaScript and TypeScript, configured with a flat config file and plugins. typescript-eslint adds rules that use type information, such as no-floating-promises, which catches promises that are neither awaited nor handled, and no-misused-promises. eslint-plugin-react-hooks enforces the rules of hooks and checks effect dependencies, catching the stale closures of Day 33. eslint-plugin-jsx-a11y catches accessibility problems such as missing alt text, click handlers on non-interactive elements and invalid ARIA. Rules should be chosen to catch real bugs; a rule that mostly produces noise trains developers to ignore warnings.
Type checking with tsc --noEmit verifies the whole program's types, which neither the bundler nor the linter does completely. In CI it is usually its own step. Large monorepos use project references or incremental builds to keep it fast, and tools such as Turborepo or Nx cache results so unchanged packages are not rechecked.
Enforcement happens at three points. The editor shows problems immediately and formats on save, which is where most issues should be fixed. Pre-commit hooks, set up with Husky or Lefthook and lint-staged, run fast checks on changed files only, catching problems before they reach the repository; they should stay fast, because slow hooks get skipped. CI is the gate that cannot be skipped: it runs the formatter check, the linter, the type checker and tests on every pull request, and branch protection prevents merging when they fail. When adopting stricter rules on an existing codebase, enable them as errors for new code and use baselines or gradual migration for old violations rather than a giant unreviewable change.
| Tool | Job | Runs |
|---|---|---|
| Prettier or Biome | Consistent formatting | On save, CI check |
| ESLint | Likely bugs and risky patterns | Editor, pre-commit, CI |
| typescript-eslint | Type-aware rules | no-floating-promises, strictness |
| react-hooks plugin | Rules of hooks, effect dependencies | Catches stale closures |
| jsx-a11y plugin | Accessibility mistakes in JSX | Missing alt, invalid ARIA |
| tsc --noEmit | Whole-program type checking | CI, editor |
| Husky and lint-staged | Fast checks on changed files | Pre-commit |
| Branch protection | Blocks merging on failures | Pull requests |
Worked Example: A Flat ESLint Config, Hooks and a CI Job
The configuration enables type-aware TypeScript rules, React Hooks and accessibility rules, leaves formatting to Prettier, and the pipeline enforces all of it.
// eslint.config.js
import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import reactHooks from 'eslint-plugin-react-hooks';
import jsxA11y from 'eslint-plugin-jsx-a11y';
import prettier from 'eslint-config-prettier';
export default tseslint.config(
{ ignores: ['dist', 'coverage'] },
js.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{
languageOptions: { parserOptions: { projectService: true } },
plugins: { 'react-hooks': reactHooks, 'jsx-a11y': jsxA11y },
rules: {
...reactHooks.configs.recommended.rules,
...jsxA11y.configs.recommended.rules,
'@typescript-eslint/no-floating-promises': 'error', // unhandled promises are bugs
'@typescript-eslint/no-explicit-any': 'warn',
'no-restricted-syntax': ['error', {
selector: "JSXAttribute[name.name='dangerouslySetInnerHTML']",
message: 'Use the sanitized <SafeHtml> component instead.',
}],
},
},
prettier, // turns off rules that conflict with formatting
);// package.json (excerpt)
{
"scripts": {
"lint": "eslint . --max-warnings 0",
"format:check": "prettier --check .",
"typecheck": "tsc --noEmit"
},
"lint-staged": {
"*.{ts,tsx}": ["eslint --fix", "prettier --write"],
"*.{css,md,json}": ["prettier --write"]
}
}# .github/workflows/quality.yml (excerpt)
- run: pnpm install --frozen-lockfile
- run: pnpm format:check
- run: pnpm lint
- run: pnpm typecheck
- run: pnpm test -- --runThe custom no-restricted-syntax rule shows how a team encodes its own decisions, here routing all raw HTML through one reviewed component, so the rule is enforced automatically rather than remembered in review.
Real-World Examples
- ESLint 9, released in 2024, made the flat configuration format the default, replacing the cascading .eslintrc files, and typescript-eslint's project service option made type-aware linting much simpler to configure in large repositories.
- Prettier's documentation explains its option philosophy: it deliberately offers few configuration options so that teams stop debating style, and it is used by a large share of popular open source JavaScript projects on GitHub.
Review Questions & Answers
A formatter rewrites code into a consistent style automatically, while a linter reports likely bugs and patterns. Mixing them leads to conflicting rules and noisy style warnings; letting the formatter own all style and disabling stylistic lint rules keeps each tool focused.
Promises that are created but neither awaited, returned nor given a rejection handler. Their errors become unhandled rejections and their completion is not waited for, which causes subtle bugs such as silently failed saves.
Slow hooks interrupt every commit, and developers start bypassing them. Running quick checks only on staged files keeps the feedback immediate, while the complete and slower checks run in CI, which cannot be skipped.
Editor integrations and local hooks depend on each developer's setup and can be skipped or misconfigured. CI runs the same checks for every pull request on a clean environment, and branch protection prevents merging code that fails them.