Linting Basics
8 examples to get you started with Linting & Formatting - 6 basic and 2 intermediate.
Search across all documentation pages
8 examples to get you started with Linting & Formatting - 6 basic and 2 intermediate.
npm install -D eslint@9 typescript-eslint @eslint/jsESLint 9 uses eslint.config.js (or .mjs) instead of legacy .eslintrc.
// eslint.config.js
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
{
ignores: ["dist/**", "node_modules/**"],
}
);ignores replaces .eslintignore.typescript-eslint bundles parser and plugin for TS.Wire lint into daily workflow and CI.
{
"scripts": {
"lint": "eslint .",
"lint:fix": "eslint . --fix"
}
}npm run lint before push; fail CI on errors.--fix handles import order and simple style rules automatically.Related: Linting Best Practices - zero-warning policy
Enable type-checked linting for stricter correctness.
export default tseslint.config(
...tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
}
);projectService (TS 5.6+) simplifies parserOptions.project setup.any usage.src/** if needed.Tell ESLint you run on Node with ES modules.
{
files: ["**/*.ts"],
languageOptions: {
ecmaVersion: 2022,
sourceType: "module",
globals: {
...globals.node,
},
},
}npm install -D globalssourceType: "module" matches "type": "module" in package.json.no-undef on process and Buffer.Keep logs structured via your logger, not raw console in src/.
{
files: ["src/**/*.ts"],
rules: {
"no-console": ["error", { allow: ["warn", "error"] }],
},
}no-console: off.Related: Prettier Integration - formatting separate from lint
Relax rules where mocks and any are common.
{
files: ["test/**/*.ts", "**/*.test.ts"],
rules: {
"@typescript-eslint/no-explicit-any": "off",
"no-console": "off",
},
}src/ stays strict.Share one ESLint config across workspaces.
// eslint.config.js (root)
import base from "./packages/eslint-config/index.js";
export default [
...base,
{
files: ["apps/api/**/*.ts"],
rules: { "no-console": "error" },
},
];packages/eslint-config for reuse.Related: Import Boundaries - architectural rules
Fail PRs on lint errors and warnings if you adopt zero-warning policy.
- run: npm ci
- run: npm run lint -- --max-warnings 0--max-warnings 0 turns warnings into failures.Related: Typecheck in CI - complementary gate
Stack versions: This page was written for Node.js 24.18.0 (Active LTS), npm 10+, TypeScript 5.6+, Express 5, Fastify 5, and NestJS 11.
Reviewed by Chris St. John·Last updated Jul 18, 2026