0
# Configuration Utilities
1
2
Utilities for analyzing and managing ESLint configurations, focusing on type-aware rule detection for TypeScript projects.
3
4
## Core Imports
5
6
```typescript
7
import { hasRulesRequiringTypeChecking } from '@nx/eslint';
8
import type { Linter } from 'eslint';
9
```
10
11
## Capabilities
12
13
### Type-Aware Rules Detection
14
15
The primary utility for determining if an ESLint configuration uses rules that require TypeScript type information.
16
17
```typescript { .api }
18
/**
19
* Determines if an ESLint configuration uses rules requiring type checking
20
* @param eslintConfig - ESLint configuration object to analyze
21
* @returns Boolean indicating if type-aware rules are present
22
*/
23
function hasRulesRequiringTypeChecking(eslintConfig: Linter.Config): boolean;
24
25
interface Linter.Config {
26
parser?: string;
27
parserOptions?: {
28
project?: string | string[];
29
[key: string]: any;
30
};
31
rules?: Record<string, any>;
32
overrides?: Array<{
33
files: string | string[];
34
rules?: Record<string, any>;
35
parserOptions?: any;
36
}>;
37
}
38
```
39
40
**Usage Examples:**
41
42
```typescript
43
import { hasRulesRequiringTypeChecking } from '@nx/eslint';
44
45
// Check if config uses type-aware rules
46
const config = {
47
rules: {
48
'@typescript-eslint/no-unused-vars': 'error',
49
'@typescript-eslint/prefer-nullish-coalescing': 'error'
50
}
51
};
52
53
const requiresTypeInfo = hasRulesRequiringTypeChecking(config);
54
// Returns: true (both rules require type information)
55
56
// Example with no type-aware rules
57
const simpleConfig = {
58
rules: {
59
'no-console': 'warn',
60
'prefer-const': 'error'
61
}
62
};
63
64
const noTypeInfo = hasRulesRequiringTypeChecking(simpleConfig);
65
// Returns: false (no type-aware rules)
66
```
67
68
### Common Type-Aware Rules
69
70
The following TypeScript ESLint rules require type information and will cause `hasRulesRequiringTypeChecking` to return `true`:
71
72
- `@typescript-eslint/await-thenable`
73
- `@typescript-eslint/dot-notation`
74
- `@typescript-eslint/no-floating-promises`
75
- `@typescript-eslint/no-for-in-array`
76
- `@typescript-eslint/no-implied-eval`
77
- `@typescript-eslint/no-misused-promises`
78
- `@typescript-eslint/no-throw-literal`
79
- `@typescript-eslint/no-unnecessary-type-assertion`
80
- `@typescript-eslint/no-unsafe-argument`
81
- `@typescript-eslint/no-unsafe-assignment`
82
- `@typescript-eslint/no-unsafe-call`
83
- `@typescript-eslint/no-unsafe-member-access`
84
- `@typescript-eslint/no-unsafe-return`
85
- `@typescript-eslint/prefer-includes`
86
- `@typescript-eslint/prefer-nullish-coalescing`
87
- `@typescript-eslint/prefer-readonly`
88
- `@typescript-eslint/prefer-readonly-parameter-types`
89
- `@typescript-eslint/prefer-reduce-type-parameter`
90
- `@typescript-eslint/prefer-regexp-exec`
91
- `@typescript-eslint/prefer-string-starts-ends-with`
92
- `@typescript-eslint/promise-function-async`
93
- `@typescript-eslint/require-array-sort-compare`
94
- `@typescript-eslint/restrict-plus-operands`
95
- `@typescript-eslint/restrict-template-expressions`
96
- `@typescript-eslint/strict-boolean-expressions`
97
- `@typescript-eslint/switch-exhaustiveness-check`
98
- `@typescript-eslint/unbound-method`
99
100
### Usage in Nx Context
101
102
This utility is primarily used by the `@nx/eslint:lint` executor to determine if the `hasTypeAwareRules` option should be set, which affects caching behavior:
103
104
```typescript
105
import { hasRulesRequiringTypeChecking } from '@nx/eslint';
106
107
// In a project configuration
108
const projectConfig = {
109
targets: {
110
lint: {
111
executor: '@nx/eslint:lint',
112
options: {
113
lintFilePatterns: ['src/**/*.ts'],
114
hasTypeAwareRules: hasRulesRequiringTypeChecking(eslintConfig)
115
}
116
}
117
}
118
};
119
```
120
121
When `hasTypeAwareRules` is `true`, the lint executor will invalidate its cache when any TypeScript files or `tsconfig.json` files change, ensuring accurate type-aware linting.