TXO TypeScript ESLint Configuration
eslint-config-txo-typescript provides a comprehensive, opinionated ESLint configuration specifically designed for TypeScript projects. It is maintained by Technology Studio and is currently at a stable version, `7.4.114`. The package maintains a frequent release cadence, often updating to reflect changes and improvements in its underlying dependencies, particularly `typescript-eslint`. A key differentiator of this configuration is its focus on "separation of concerns," allowing for incremental migration and tailored settings based on project patterns. This approach aims to reduce friction when integrating or updating linting rules across diverse TypeScript codebases, ensuring consistency and adherence to modern best practices in a modular fashion. It leverages established ESLint plugins to enforce robust code quality and style standards.
Common errors
-
ESLint: Configuration for rule "@typescript-eslint/no-floating-promises" is invalid:
cause This error typically occurs when type-aware rules are enabled, but ESLint cannot find or correctly parse your TypeScript project configuration (`tsconfig.json`).fixVerify that `parserOptions.project` in your `.eslintrc` correctly points to your `tsconfig.json` and that `parserOptions.tsconfigRootDir` is set to `__dirname`. -
Parsing error: Cannot find module '@typescript-eslint/parser' or its corresponding type declarations.
cause The `@typescript-eslint/parser` package is either not installed or ESLint cannot resolve its path.fixEnsure `@typescript-eslint/parser` is installed as a `devDependency`: `npm install --save-dev @typescript-eslint/parser` or `yarn add --dev @typescript-eslint/parser`. Check your ESLint configuration for correct parser path if it's explicitly set. -
ESLint: '...' is not defined. (no-undef)
cause This error often indicates that global variables or environments (like Node.js, browser, Jest) are not properly declared in your ESLint configuration, or the variable is not imported.fixAdd appropriate environments to your `.eslintrc` (e.g., `"env": { "node": true, "jest": true }`) or ensure the variable is imported from a module. If using custom globals, declare them in the `globals` section.
Warnings
- breaking This configuration frequently updates its dependency on `typescript-eslint`. New major versions of `typescript-eslint` often introduce breaking changes to rules or require updated configuration settings. Always review the `typescript-eslint` changelog when upgrading `eslint-config-txo-typescript` across minor or major versions.
- gotcha This package requires Node.js version 18 or higher. Using an older Node.js version will result in installation failures or runtime errors.
- gotcha For TypeScript-aware rules to function correctly, `parserOptions.project` and `parserOptions.tsconfigRootDir` must be correctly configured in your `.eslintrc` file. Incorrect paths can lead to rules not being applied or parsing errors.
Install
-
npm install eslint-config-txo-typescript -
yarn add eslint-config-txo-typescript -
pnpm add eslint-config-txo-typescript
Imports
- ESLint Configuration
import config from 'eslint-config-txo-typescript'
{ "extends": "eslint-config-txo-typescript" } - Specific Rules
import { ruleName } from 'eslint-config-txo-typescript/rules'{ "extends": ["eslint-config-txo-typescript", "./custom-rules.js"] } - TypeScript Project Settings
{ "parserOptions": { "project": true } }{ "extends": "eslint-config-txo-typescript", "parserOptions": { "project": "./tsconfig.json", "tsconfigRootDir": __dirname } }
Quickstart
{
"root": true,
"env": {
"node": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"tsconfigRootDir": __dirname,
"ecmaVersion": 2022,
"sourceType": "module"
},
"extends": "eslint-config-txo-typescript",
"rules": {
// Override or add custom rules here if needed
"no-console": "warn",
"@typescript-eslint/explicit-function-return-type": "off"
}
}