This document describes the code quality enforcement tools used in the NestJS repository, including ESLint for linting, Prettier for code formatting, and their integration with the development workflow through git hooks. These tools ensure consistent code style and catch potential issues across all packages and sample applications in the monorepo.
For information about TypeScript compilation and build configuration, see TypeScript Configuration. For build pipeline and scripts, see Scripts and Automation.
Sources: package.json1-242
The NestJS repository uses a comprehensive code quality toolchain with specific versions managed at the root level:
| Tool | Version | Purpose |
|---|---|---|
| ESLint | 9.39.2 | Static code analysis and linting |
| Prettier | 3.7.4+ | Code formatting and style enforcement |
| TypeScript ESLint | 8.55.0 | TypeScript-specific linting rules |
| Husky | 9.1.7 | Git hooks automation |
| lint-staged | 16.2.7 | Pre-commit file staging and processing |
| concurrently | 9.2.1 | Parallel script execution |
Sources: package.json82-173
Sources: package.json82-115 package.json38-43
The repository separates linting into three distinct targets with dedicated npm scripts:
The --max-old-space-size=4096 flag allocates 4GB of memory to the Node.js process to handle the large codebase during linting operations.
Sources: package.json38-42
The main lint commands use concurrently to run multiple lint targets in parallel:
Sources: package.json38-43 package.json122
Sources: package.json29 package.json53-60 package.json159
The format script applies Prettier to all TypeScript and JSON files, respecting the .prettierignore file:
This command:
.ts files in the repository.json files within the packages/ directory--write)Sources: package.json29
Sources: package.json51-60 package.json144 package.json150
The lint-staged configuration in package.json53-60 defines which tools run on staged files:
When developers commit files, Husky triggers lint-staged, which:
**/*.tspackages/**/*.jsonSources: package.json53-60
Husky is initialized via the prepare script, which runs automatically after npm install:
This ensures git hooks are configured in every clone of the repository.
Sources: package.json51 package.json144
Sources: sample/06-mongoose/package.json1-72 sample/12-graphql-schema-first/package.json1-93 sample/14-mongoose-base/package.json1-71 sample/22-graphql-prisma/package.json1-68 sample/23-graphql-code-first/package.json1-60
Each sample application includes simplified code quality scripts targeting the sample's source code:
| Script | Command | Target |
|---|---|---|
format | prettier --write "src/**/*.ts" "test/**/*.ts" | Source and test TypeScript files |
lint | eslint '{src,apps,libs,test}/**/*.ts' --fix | Source, app, library, and test TypeScript files |
The sample applications use the same tool versions as the root repository, ensuring consistency across the monorepo:
Sources: sample/06-mongoose/package.json9-14 sample/12-graphql-schema-first/package.json9-14 sample/22-graphql-prisma/package.json9-15
Some samples include additional ESLint plugins for specialized linting:
The eslint-plugin-import provides import/export statement validation and ordering rules, used in GraphQL samples for managing complex module dependencies.
Sources: sample/22-graphql-prisma/package.json39-66 sample/23-graphql-code-first/package.json36-59
The code quality tools work in conjunction with TypeScript's type checking:
Sources: package.json16-43
The repository enforces code quality in the following order:
This ordering is reflected in the CI workflow where npm run lint:ci executes before npm run build (which performs type checking via tsc).
Sources: package.json17-21 package.json38-43
All ESLint scripts include memory optimization flags:
This configuration allocates 4GB of heap memory to the Node.js process, necessary for linting the entire monorepo which includes:
packages/integration/Without this memory allocation, ESLint would encounter out-of-memory errors when processing the complete codebase.
Sources: package.json40-42
The code quality tools integrate with the test coverage system through NYC (Istanbul):
This configuration ensures that:
Sources: package.json194-232
The repository includes commit message linting through commitlint:
This enforces Angular-style commit message conventions with types like:
type: feature :tada:type: bug :sob:type: enhancement :wolf:type: docs :page_facing_up:type: code styleSources: package.json85-86 package.json184-193
The NestJS repository maintains code quality through a multi-layered approach:
These tools run automatically during development and are enforced in CI/CD pipelines, maintaining consistent code quality across the entire monorepo.
Sources: package.json1-242
Refresh this wiki