Sub topic 12
Performance and Monorepo Considerations
Assume that you know TypeScript, tsconfig.json, npm, and ESLint flat configuration. This chapter focuses on keeping type-aware linting fast as a repository grows.
Why type-aware linting costs more
Basic lint rules inspect the syntax tree of one file. Type-aware rules also ask the TypeScript program for information about types, imports, and project membership. ESLint may need to load tsconfig.json, parse related files, and build compiler information before it can report a problem.
This extra work catches bugs that syntax-only linting cannot see, but it increases startup time and memory use. The cost becomes noticeable when a repository contains many packages, generated files, tests, or several TypeScript projects.
Use type-aware rules where they provide value. Do not enable them for files that do not need them.
Keep the lint scope narrow
Ignore files that are not maintained source code. Build output, coverage reports, generated clients, and vendored dependencies usually do not need linting.
// eslint.config.mjs
import eslint from '@eslint/js';
import { defineConfig, globalIgnores } from 'eslint/config';
import tseslint from 'typescript-eslint';
export default defineConfig(
globalIgnores([
'**/dist/**',
'**/coverage/**',
'**/generated/**',
]),
eslint.configs.recommended,
tseslint.configs.recommendedTypeChecked,
{
files: ['**/*.ts', '**/*.tsx'],
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
);The files pattern prevents this type-aware configuration from applying to unrelated file types. The projectService finds the relevant TypeScript project for each source file.
Use the ESLint cache for repeated local runs:
npx eslint . --cacheThe cache lets ESLint skip files that have not changed. CI can run a complete lint on trusted branches, while pre-commit checks can focus on changed files.
Organize a monorepo around projects
A monorepo contains multiple packages in one repository. A common layout looks like this:
| Path | Purpose |
|---|---|
| `packages/api/tsconfig.json` | TypeScript project for the API |
| `packages/web/tsconfig.json` | TypeScript project for the web application |
| `packages/shared/tsconfig.json` | TypeScript project for shared code |
| `eslint.config.mjs` | Repository-wide ESLint configuration |
With project service enabled, a file such as packages/api/src/server.ts is associated with the nearest suitable tsconfig.json. This avoids manually listing every project in the ESLint configuration and works well when packages have different compiler settings.
Keep each package's tsconfig.json focused. A configuration that includes tests, build output, and generated files causes TypeScript to load more files than necessary. Use separate configurations when appropriate, such as a build configuration and a test configuration.
Avoid expensive exceptions
Files outside a TypeScript project, such as a root configuration file or a script, may need a special configuration. The project service can allow selected files through a default project, but each such file adds work. Keep that list small.
Do not use a broad default-project pattern such as **/*. Instead, either exclude the file from typed linting or add only the few files that genuinely need type information.
When to split or disable typed linting
For very large repositories, consider separate ESLint commands:
- Run syntax-only rules quickly on every package.
- Run type-aware rules on source packages and changed projects.
- Run the complete type-aware check in CI or before release.
- Disable typed linting for JavaScript files that are not part of a TypeScript project.
Custom rules can also reduce repeated checks when a repository has a specific convention. Add them only when a normal rule or TypeScript compiler check cannot express the requirement.
Exercise
Why should a monorepo ignore generated files and keep each tsconfig.json focused?
Show answer
Type-aware linting loads project information and related files. Narrow inputs reduce parsing time, memory use, and unnecessary reports.