Linting, Formatting, and Type Checking in React Projects

Learn how ESLint, a formatter, and TypeScript checks catch different React code issues, with simple scripts for fast local feedback and CI.

published: reading time: 8 min read author: Geek Workbench updated: November 22, 2026
Quick Summary

ESLint, a formatter, and TypeScript checks catch different classes of issues in a React project. This guide shows simple package scripts and a strict TypeScript configuration, then explains how local runs and CI can share the same checks. Treat passing types as static feedback, not proof that runtime API data is valid or that the interface behaves as intended.

Linting, Formatting, and Type Checking in React Projects

Introduction

ESLint flags code patterns that may be wrong or hard to maintain. A formatter makes layout consistent. TypeScript checks whether values and functions match their declared types. They catch different problems, so a React project may use all three.

This article maps each tool to its job and shows simple scripts for local feedback and continuous integration.

Three checks, three jobs

ESLint applies rules such as unused-variable or suspicious-pattern checks. Prettier changes whitespace and wrapping. tsc --noEmit checks static types across the project. A clean result does not prove the interface behaves correctly or that runtime API values match their declared type.

Add simple project scripts

This example pins a small TypeScript toolchain. The versions were checked on 2026-11-22. TypeScript 7 is newer, but typescript-eslint 8.73 officially supports TypeScript versions below 6.1, so this example uses TypeScript 6.0.3. ESLint 10 also needs Node 20.19+, 22.13+, or 24+.

{
  "devDependencies": {
    "@eslint/js": "10.0.1",
    "eslint": "10.15.0",
    "prettier": "3.10.1",
    "typescript": "6.0.3",
    "typescript-eslint": "8.73.0"
  },
  "scripts": {
    "lint": "eslint \"src/**/*.{ts,tsx}\"",
    "format": "prettier . --write",
    "format:check": "prettier . --check",
    "typecheck": "tsc --noEmit"
  }
}

Add a flat ESLint config at the project root. The recommended rules provide a small starting point for JavaScript and TypeScript files, including TSX:

import js from "@eslint/js";
import { defineConfig } from "eslint/config";
import tseslint from "typescript-eslint";

export default defineConfig({
  files: ["**/*.{ts,tsx}"],
  extends: [js.configs.recommended, tseslint.configs.recommended],
});

A tsconfig.json can enable strict checks and prevent TypeScript from writing output:

{
  "compilerOptions": {
    "strict": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": ["src"]
}

tsc --noEmit checks the project without producing compiled files. Commit the lockfile as well; exact top-level pins and npm ci make local and CI installs repeatable. For CI, run the same scripts after npm ci:

- run: npm ci
- run: npm run lint && npm run typecheck && npm run format:check

The chained command exits on the first failed check, so lint errors, type errors, and formatting drift all fail the job.

These checks respond to different problems. With the recommended TypeScript ESLint rules enabled, the same small examples get different feedback:

Before: code or issue Tool After: feedback
const unused = true; ESLint Fails because unused is never read.
const count={ total:3 } Prettier Reprints it as const count = { total: 3 };.
const count: number = "3"; tsc Fails because a string cannot be assigned to a number.
flowchart LR
    A[Edit React code] --> B[ESLint: code patterns]
    A --> C[Formatter: consistent layout]
    A --> D[TypeScript: value types]
    B --> E[Fix locally]
    C --> E
    D --> E
    E --> F[CI runs the same checks]

When to Use / When NOT to Use

Run ESLint and type checking during active development to find code and contract errors close to the edit. Format on save or before review. Do not treat these tools as runtime validation or as proof that behavior is correct.

Trade-Off Table

Tool Use it for It does not prove
ESLint Suspicious patterns and configured code rules That the app’s behavior matches the feature request
Prettier Consistent formatting That the code is correct or accessible
tsc --noEmit Type consistency across the project That external data matches its declared type at runtime

Run the relevant script while you work; CI can repeat the same checks before merging. Keep tool versions in the lockfile so local runs and CI use the same tools.

Production Failure Scenarios

If a prop changes from string to string | undefined, a page may fail only when the missing state appears. A local type check points to the unsafe use. Add a fallback, then keep the same script in CI.

If developers use different formatter or linter versions, files can churn between local and CI runs. Pin versions in the lockfile and run the repository scripts in both places.

Security and Compliance Notes

These tools do not make user input safe. Type declarations disappear at runtime, and neither linting nor type checking validates a value from an API. For example, annotating response.json() as User does not inspect the response body. Parse and validate untrusted data at the boundary; never treat a successful type check as authorization or input sanitization.

Observability Checklist

  • Keep command output and exit status visible in local and CI logs.
  • Label failures by check: lint, format, or typecheck.
  • Record the tool version and commit identifier when CI fails.
  • Do not print secrets or environment values in diagnostic output.

Common Pitfalls and Anti-Patterns

Do not use Prettier as a linter, assume TypeScript checks runtime input, or disable rules without a reason. Run repository scripts instead of ad hoc commands for consistent feedback.

Quick Recap Checklist

  • ESLint checks configured code patterns.
  • A formatter changes layout, not behavior.
  • tsc --noEmit checks types without writing JavaScript.
  • Run quick checks locally and repeat them in CI.
  • Validate external values at runtime.

Interview Questions

1. How is linting different from formatting?
Linting reports configured code problems, such as suspicious or unused code. Formatting applies consistent layout rules such as indentation and wrapping.
2. What does tsc --noEmit do?
It runs TypeScript's compiler checks without writing JavaScript output files. This is useful when another tool handles the project's build.
3. Does a successful type check validate API data?
No. Types help during development, but incoming values need runtime validation before the application trusts or uses them.
4. What kinds of issues can ESLint find?
It reports patterns covered by the project's configured rules.
  • Rules can catch unused variables or suspicious code.
  • Linting does not prove the feature behaves as intended.
5. What does Prettier check?
It checks or applies consistent code formatting.
  • It can change indentation and line wrapping.
  • It does not replace linting or type checking.
6. Why run type checks before sharing a change?
They can catch incompatible values and unsafe accesses during development.
  • A focused error is easier to fix near the edit.
  • CI can repeat the same check before a merge.
7. Why use package scripts for checks?
Named scripts give contributors one consistent command.
  • They can encode the project's intended flags and paths.
  • CI can invoke the same scripts used locally.
8. Why pin checking tool versions in the lockfile?
Different tool versions can format or report code differently.
  • Use a repeatable install in local development and CI.
  • Review tool updates deliberately instead of changing them incidentally.
9. What does strict TypeScript configuration help with?
It enables stronger checks for code relationships and missing values.
  • TypeScript can catch some unsafe nullable access.
  • Runtime data still needs validation.
10. What information should CI diagnostics avoid printing?
Diagnostic output should not expose secrets or environment values.
  • Keep the command, tool version, and failure useful for debugging.
  • Validate external data separately from static checks.

Further Reading

Conclusion

When a check fails, fix the source or change the rule deliberately rather than silencing the output just to pass CI. Keep type checks in the build workflow, but validate API values at runtime because TypeScript cannot inspect what the server actually returned.

Category

Related Posts

Accessible React UI: Semantics, Labels, and Keyboard Use

Build React interfaces with semantic controls, connected labels, visible keyboard focus, and status announcements through practical TypeScript examples.

#react #typescript #accessibility

Advanced React State: When Local State Stops Fitting

Learn when React state needs a reducer and context, when Redux Toolkit helps, and why server data often belongs in a query cache instead.

#react #typescript #state-management

Testing React Components and User Interactions

Write behavior-first React tests with accessible roles, realistic user events, and async assertions while avoiding brittle checks of implementation details.

#react #typescript #testing