0
# Configuration
1
2
Comprehensive configuration system supporting all ESLint CLI options with automatic detection of ESLint configuration type (legacy vs flat config).
3
4
## Capabilities
5
6
### Configuration Loading
7
8
Configuration loading system using cosmiconfig to find and parse jest-runner-eslint configuration.
9
10
```javascript { .api }
11
/**
12
* Loads ESLint options from configuration files
13
* Supports package.json, .jest-runner-eslintrc, and jest-runner-eslint.config.js
14
* @param configType - ESLint configuration type ('flat' or 'legacy')
15
* @param config - Jest configuration object containing rootDir
16
* @returns Normalized ESLint options object
17
*/
18
function getESLintOptions(
19
configType: 'flat' | 'legacy',
20
config: { rootDir: string }
21
): { cliOptions: ESLintCliOptions };
22
```
23
24
**Usage Examples:**
25
26
```javascript
27
// package.json configuration
28
{
29
"jest-runner-eslint": {
30
"cliOptions": {
31
"fix": true,
32
"cache": true,
33
"format": "codeframe"
34
}
35
}
36
}
37
38
// jest-runner-eslint.config.js
39
module.exports = {
40
cliOptions: {
41
fix: true,
42
cache: true,
43
cacheLocation: './eslint-cache',
44
maxWarnings: 0,
45
format: 'stylish'
46
}
47
};
48
49
// .jest-runner-eslintrc (JSON)
50
{
51
"cliOptions": {
52
"quiet": true,
53
"fix": false,
54
"ext": [".js", ".jsx", ".ts", ".tsx"]
55
}
56
}
57
```
58
59
### Configuration Normalization
60
61
System for normalizing configuration options based on ESLint configuration type.
62
63
```javascript { .api }
64
/**
65
* Normalizes configuration object with proper CLI options
66
* @param configType - ESLint configuration type
67
* @param config - Raw configuration object
68
* @returns Normalized configuration with cliOptions
69
*/
70
function normalizeConfig(
71
configType: 'flat' | 'legacy',
72
config: Partial<JestRunnerESLintConfig>
73
): JestRunnerESLintConfig;
74
75
/**
76
* Normalizes CLI options based on configuration type
77
* @param configType - ESLint configuration type
78
* @param rawConfig - Raw CLI options object
79
* @returns Normalized CLI options object
80
*/
81
function normalizeCliOptions(
82
configType: 'flat' | 'legacy',
83
rawConfig: Partial<ESLintCliOptions>
84
): ESLintCliOptions;
85
```
86
87
### Configuration Schemas
88
89
Configuration schemas for different ESLint configuration types.
90
91
```javascript { .api }
92
/** Base configuration schema shared by both config types */
93
const BASE_CONFIG: ConfigSchema;
94
95
/** Legacy ESLint configuration schema (ESLint <8.57.0) */
96
const LEGACY_CONFIG: ConfigSchema;
97
98
/** Flat ESLint configuration schema (ESLint >=8.57.0) */
99
const FLAT_CONFIG: ConfigSchema;
100
101
interface ConfigSchema {
102
[key: string]: {
103
name?: string;
104
default: any;
105
transform?: (value: any) => any;
106
};
107
}
108
```
109
110
### ESLint CLI Options
111
112
Complete interface for ESLint CLI options supported by jest-runner-eslint.
113
114
```javascript { .api }
115
interface ESLintCliOptions {
116
// Basic options (supported in both legacy and flat config)
117
/** Enable ESLint caching */
118
cache?: boolean;
119
/** Location of cache file */
120
cacheLocation?: string;
121
/** Path to ESLint configuration file */
122
config?: string;
123
/** Automatically fix problems */
124
fix?: boolean;
125
/** Fix problems without saving files */
126
fixDryRun?: boolean;
127
/** Output format for ESLint results */
128
format?: string;
129
/** Maximum number of warnings allowed */
130
maxWarnings?: number;
131
/** Disable warning output, only show errors */
132
quiet?: boolean;
133
/** Disable ignore files and patterns */
134
noIgnore?: boolean;
135
/** Disable inline configuration comments */
136
noInlineConfig?: boolean;
137
138
// Legacy config options (ESLint <8.57.0)
139
/** File extensions to lint */
140
ext?: string | string[];
141
/** Environment presets to enable */
142
env?: string | string[];
143
/** Global variables to define */
144
global?: string | string[];
145
/** Path to ignore file */
146
ignorePath?: string;
147
/** Ignore patterns to apply */
148
ignorePattern?: string[];
149
/** Disable .eslintrc files */
150
noEslintrc?: boolean;
151
/** Parser to use for code analysis */
152
parser?: string;
153
/** Parser options object */
154
parserOptions?: Record<string, any>;
155
/** ESLint plugins to load */
156
plugin?: string | string[];
157
/** Report unused disable directives */
158
reportUnusedDisableDirectives?: boolean;
159
/** Base path for resolving plugins */
160
resolvePluginsRelativeTo?: string;
161
/** Rules configuration object */
162
rules?: Record<string, any>;
163
/** Additional rules directories */
164
rulesdir?: string | string[];
165
}
166
167
interface JestRunnerESLintConfig {
168
/** CLI options for ESLint */
169
cliOptions?: ESLintCliOptions;
170
}
171
```
172
173
**Usage Examples:**
174
175
```javascript
176
// Comprehensive configuration example
177
module.exports = {
178
cliOptions: {
179
// Basic options
180
cache: true,
181
cacheLocation: './node_modules/.cache/eslint',
182
format: 'codeframe',
183
fix: false,
184
maxWarnings: 10,
185
quiet: false,
186
187
// Legacy config options (if using ESLint <8.57.0)
188
ext: ['.js', '.jsx', '.ts', '.tsx'],
189
env: ['browser', 'node'],
190
global: ['window', 'document'],
191
plugin: ['react', 'import'],
192
rules: {
193
'no-console': 'warn',
194
'prefer-const': 'error'
195
},
196
197
// File patterns
198
ignorePattern: ['dist/*', 'build/*'],
199
noIgnore: false,
200
noInlineConfig: false
201
}
202
};
203
```
204
205
### Transformation Functions
206
207
Utility functions for transforming configuration values.
208
209
```javascript { .api }
210
/** Identity function - returns value unchanged */
211
const identity: <T>(value: T) => T;
212
213
/** Negation function - returns boolean opposite */
214
const negate: (value: boolean) => boolean;
215
216
/** Array conversion function - converts string to single-item array */
217
const asArray: (value: string | string[]) => string[];
218
219
/** Integer conversion function - converts string to number */
220
const asInt: (value: string | number) => number;
221
```
222
223
**Usage Examples:**
224
225
```javascript
226
// Configuration with type transformations
227
const config = {
228
cliOptions: {
229
ext: '.js', // Transformed to ['.js'] by asArray
230
maxWarnings: '5', // Transformed to 5 by asInt
231
noEslintrc: true, // Transformed to useEslintrc: false by negate
232
}
233
};
234
235
// Dot-prop path transformation for nested properties
236
const legacyConfig = {
237
env: ['browser'], // Becomes overrideConfig.env
238
global: ['window'], // Becomes overrideConfig.globals
239
rules: { 'no-console': 'warn' } // Becomes overrideConfig.rules
240
};
241
```
242
243
### Configuration Discovery
244
245
Configuration files are discovered using cosmiconfig in the following order:
246
247
1. `jest-runner-eslint` property in `package.json`
248
2. `.jest-runner-eslintrc` file (JSON)
249
3. `.jest-runner-eslintrc.json` file
250
4. `.jest-runner-eslintrc.js` file
251
5. `jest-runner-eslint.config.js` file
252
253
The search starts from the Jest `rootDir` and traverses up the directory tree until a configuration is found or the file system root is reached.