4
4
import { md } from 'build-md' ;
5
5
import { getEnabledRuleIds } from './rules.js' ;
6
6
7
+ /** @type {Record<import('./types.js').ConfigName, import('build-md').FormattedText> } */
7
8
const configDescriptions = {
8
9
javascript : md `Default config, suitable for any ${ md . bold ( 'JavaScript/TypeScript' ) } project.` ,
9
10
typescript : md `Config for strict ${ md . bold ( 'TypeScript' ) } projects.` ,
@@ -20,11 +21,11 @@ const configDescriptions = {
20
21
'react-testing-library' : md `Config for projects using ${ md . bold ( 'React Testing Library' ) } for testing.` ,
21
22
} ;
22
23
23
- /** @type {(keyof typeof configDescriptions )[] } */
24
+ /** @type {(import('./types.js').ConfigName )[] } */
24
25
// @ts -expect-error keys won't be any string
25
26
export const configNames = Object . keys ( configDescriptions ) ;
26
27
27
- /** @type {Record<keyof typeof configDescriptions , import('./types.js').Icon> } */
28
+ /** @type {Record<import('./types.js').ConfigName , import('./types.js').Icon> } */
28
29
const configIcons = {
29
30
javascript : 'material/javascript' ,
30
31
typescript : 'material/typescript' ,
@@ -41,7 +42,7 @@ const configIcons = {
41
42
'react-testing-library' : 'other/testing-library' ,
42
43
} ;
43
44
44
- /** @type {Partial<Record<keyof typeof configDescriptions , string>> } */
45
+ /** @type {Partial<Record<import('./types.js').ConfigName , string>> } */
45
46
const configPatterns = {
46
47
graphql : '*.graphql' ,
47
48
jest : '*.test.ts' ,
@@ -52,13 +53,13 @@ const configPatterns = {
52
53
'react-testing-library' : '*.spec.tsx' ,
53
54
} ;
54
55
55
- /** @type {Partial<Record<keyof typeof configDescriptions , string>> } */
56
+ /** @type {Partial<Record<import('./types.js').ConfigName , string>> } */
56
57
const configExtraPatterns = {
57
58
angular : '*.html' ,
58
59
storybook : '.storybook/main.ts' ,
59
60
} ;
60
61
61
- /** @type {Set<(keyof typeof configDescriptions )> } */
62
+ /** @type {Set<(import('./types.js').ConfigName )> } */
62
63
const testConfigs = new Set ( [
63
64
'jest' ,
64
65
'vitest' ,
@@ -71,7 +72,7 @@ const eslintConfig = 'eslint.config.js';
71
72
72
73
const tsConfigDocsReference = md `Refer to ${ md . link ( './typescript.md#🏗️-setup' , "step 3 in TypeScript config's setup docs" ) } for how to set up tsconfig properly.` ;
73
74
74
- /** @type {Partial<Record<keyof typeof configDescriptions , import('build-md').FormattedText>> } */
75
+ /** @type {Partial<Record<import('./types.js').ConfigName , import('build-md').FormattedText>> } */
75
76
export const configsExtraSetupDocs = {
76
77
typescript : md `${ md . paragraph (
77
78
md `Because this config includes rules which require type information, make sure to configure ${ md . code ( 'parserOptions.project' ) } in your ${ md . code ( 'eslint.config.js' ) } points to your project's tsconfig.
@@ -207,7 +208,7 @@ const angularExtraEslintrc = `,
207
208
}
208
209
}` ;
209
210
210
- /** @type {Partial<Record<keyof typeof configDescriptions , string>> } */
211
+ /** @type {Partial<Record<import('./types.js').ConfigName , string>> } */
211
212
export const configsExtraEslintrc = {
212
213
angular : angularExtraEslintrc ,
213
214
ngrx : angularExtraEslintrc ,
@@ -236,30 +237,24 @@ export const configsExtraEslintrc = {
236
237
237
238
/**
238
239
* Get description for given config.
239
- * @param {string } name Config file name without extension
240
+ * @param {import('./types.js').ConfigName } name Config file name without extension
240
241
*/
241
242
export function configDescription ( name ) {
242
- if ( ! ( name in configDescriptions ) ) {
243
- throw new Error ( `No description found for config ${ name } ` ) ;
244
- }
245
243
return configDescriptions [ name ] ;
246
244
}
247
245
248
246
/**
249
247
* Get icon name for given config.
250
- * @param {string } name Config file name without extension
248
+ * @param {import('./types.js').ConfigName } name Config file name without extension
251
249
* @returns {import('./types.js').Icon }
252
250
*/
253
251
export function configIcon ( name ) {
254
- if ( ! ( name in configIcons ) ) {
255
- throw new Error ( `No icon found for config ${ name } ` ) ;
256
- }
257
252
return configIcons [ name ] ;
258
253
}
259
254
260
255
/**
261
256
* Get file pattern for given config.
262
- * @param {string } name Config file name without extension
257
+ * @param {import('./types.js').ConfigName } name Config file name without extension
263
258
*/
264
259
export function configPattern ( name ) {
265
260
if ( ! ( name in configPatterns ) ) {
@@ -270,7 +265,7 @@ export function configPattern(name) {
270
265
271
266
/**
272
267
* Get additional file pattern for given config.
273
- * @param {string } name Config file name without extension
268
+ * @param {import('./types.js').ConfigName } name Config file name without extension
274
269
* @returns {string | undefined }
275
270
*/
276
271
export function configExtraPattern ( name ) {
@@ -279,16 +274,15 @@ export function configExtraPattern(name) {
279
274
280
275
/**
281
276
* Is config targetting some testing framework?
282
- * @param {string } name Config file name without extension
277
+ * @param {import('./types.js').ConfigName } name Config file name without extension
283
278
*/
284
279
export function isConfigForTests ( name ) {
285
- // @ts -expect-error the point is to check if string is a union
286
280
return testConfigs . has ( name ) ;
287
281
}
288
282
289
283
/**
290
284
* Imports flat config array by name.
291
- * @param {string } name Config file name without extension
285
+ * @param {import('./types.js').ConfigName } name Config file name without extension
292
286
* @returns {Promise<import('@typescript-eslint/utils').TSESLint.FlatConfig.ConfigArray> }
293
287
*/
294
288
export async function importConfig ( name ) {
0 commit comments