Skip to content

Lesson 8 of 9 · 27m

Typed Linting: ESLint Architecture Beyond Syntax Rules

Build an ESLint setup that uses TypeScript type information where it pays, avoids multi-project parser traps, and stays fast enough to run.

Typed linting is where teams discover that ESLint is not one tool. It is a parser pipeline, a rule engine, an editor integration, and — when configured correctly — a consumer of the same TypeScript program the compiler builds. Done well, it catches real bugs: floating promises, unsafe any leaks, misused async boundaries. Done badly, it turns pre-commit into a coffee break and CI into a random failure generator.

Syntax linting and type-aware linting are different products

Rules such as no-console need only the file's syntax tree. Rules such as these need type information:

@typescript-eslint/no-floating-promises      @typescript-eslint/no-misused-promises
@typescript-eslint/no-unsafe-member-access   @typescript-eslint/require-await

That means the parser must connect each linted file to a tsconfig project. In modern flat config, the shape is:

import tseslint from "typescript-eslint"

export default tseslint.config({
  files: ["src/**/*.ts"],
  languageOptions: {parserOptions: {projectService: true, tsconfigRootDir: import.meta.dirname}},
  rules: {"@typescript-eslint/no-floating-promises": "error"}
})

The exact version details evolve, but the architecture does not: no TypeScript program, no type-aware rules.

The classic failure: file not found in project

Every monorepo practitioner has seen this:

parserOptions.project was set but the file does not match any project

This is not a mystical ESLint bug. The file is outside the include graph of the tsconfig you gave the parser, or the config uses a different tsconfig than the compiler. Tests, scripts, generated files, and config files trigger this constantly. The correct fix is usually explicit project design: a tsconfig.eslint.json, separate test configs, or parser options that mirror real project boundaries.

Project service reduces config but does not repeal physics

projectService infers projects more intelligently and is a major quality-of-life improvement in monorepos. It does not make type-aware linting free: every file still participates in type construction.

Split rules by cost and intent

A mature setup separates fast syntax rules from expensive type-aware rules:

local pre-commit     fast syntax + format + targeted tests
CI pull request      full typecheck + typed lint
nightly              slow dependency and architecture audits

Do not use this as an excuse to make local feedback useless. Some typed rules catch bugs too important to defer. The design question is which feedback must be immediate and which can tolerate a few minutes.

Typed rules reveal design problems

If no-unsafe-* explodes after enabling typed linting, the answer is not blanket suppression. Often your API boundary accepts unknown and immediately casts it, or generated clients return any, or lint is inspecting untyped legacy files. Fix the trust boundary first. Use targeted disables with comments and expiry issues, not project-wide defeat.

Field notes

  • Type-aware lint performance is coupled to compiler performance; measure tsc before blaming ESLint.
  • .eslintignore-era assumptions do not always transfer cleanly to flat config. Verify which files are actually linted.
  • Keep parser project configuration close to the tsconfig used for real builds, or drift is guaranteed.
  • Rules that depend on types can produce different results in editor and CLI if they load different projects.
  • Disable a rule for a line because you understand the exception, not because the rule is noisy globally.

Was this lesson helpful?

Sign in to rate