44import { md } from 'build-md' ;
55import { getEnabledRuleIds } from './rules.js' ;
66
7+ /** @type {Record<import('./types.js').ConfigName, import('build-md').FormattedText> } */
78const configDescriptions = {
89 javascript : md `Default config, suitable for any ${ md . bold ( 'JavaScript/TypeScript' ) } project.` ,
910 typescript : md `Config for strict ${ md . bold ( 'TypeScript' ) } projects.` ,
@@ -20,11 +21,11 @@ const configDescriptions = {
2021 'react-testing-library' : md `Config for projects using ${ md . bold ( 'React Testing Library' ) } for testing.` ,
2122} ;
2223
23- /** @type {(keyof typeof configDescriptions )[] } */
24+ /** @type {(import('./types.js').ConfigName )[] } */
2425// @ts -expect-error keys won't be any string
2526export const configNames = Object . keys ( configDescriptions ) ;
2627
27- /** @type {Record<keyof typeof configDescriptions , import('./types.js').Icon> } */
28+ /** @type {Record<import('./types.js').ConfigName , import('./types.js').Icon> } */
2829const configIcons = {
2930 javascript : 'material/javascript' ,
3031 typescript : 'material/typescript' ,
@@ -41,7 +42,7 @@ const configIcons = {
4142 'react-testing-library' : 'other/testing-library' ,
4243} ;
4344
44- /** @type {Partial<Record<keyof typeof configDescriptions , string>> } */
45+ /** @type {Partial<Record<import('./types.js').ConfigName , string>> } */
4546const configPatterns = {
4647 graphql : '*.graphql' ,
4748 jest : '*.test.ts' ,
@@ -52,13 +53,13 @@ const configPatterns = {
5253 'react-testing-library' : '*.spec.tsx' ,
5354} ;
5455
55- /** @type {Partial<Record<keyof typeof configDescriptions , string>> } */
56+ /** @type {Partial<Record<import('./types.js').ConfigName , string>> } */
5657const configExtraPatterns = {
5758 angular : '*.html' ,
5859 storybook : '.storybook/main.ts' ,
5960} ;
6061
61- /** @type {Set<(keyof typeof configDescriptions )> } */
62+ /** @type {Set<(import('./types.js').ConfigName )> } */
6263const testConfigs = new Set ( [
6364 'jest' ,
6465 'vitest' ,
@@ -71,7 +72,7 @@ const eslintConfig = 'eslint.config.js';
7172
7273const tsConfigDocsReference = md `Refer to ${ md . link ( './typescript.md#🏗️-setup' , "step 3 in TypeScript config's setup docs" ) } for how to set up tsconfig properly.` ;
7374
74- /** @type {Partial<Record<keyof typeof configDescriptions , import('build-md').FormattedText>> } */
75+ /** @type {Partial<Record<import('./types.js').ConfigName , import('build-md').FormattedText>> } */
7576export const configsExtraSetupDocs = {
7677 typescript : md `${ md . paragraph (
7778 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 = `,
207208 }
208209 }` ;
209210
210- /** @type {Partial<Record<keyof typeof configDescriptions , string>> } */
211+ /** @type {Partial<Record<import('./types.js').ConfigName , string>> } */
211212export const configsExtraEslintrc = {
212213 angular : angularExtraEslintrc ,
213214 ngrx : angularExtraEslintrc ,
@@ -236,30 +237,24 @@ export const configsExtraEslintrc = {
236237
237238/**
238239 * 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
240241 */
241242export function configDescription ( name ) {
242- if ( ! ( name in configDescriptions ) ) {
243- throw new Error ( `No description found for config ${ name } ` ) ;
244- }
245243 return configDescriptions [ name ] ;
246244}
247245
248246/**
249247 * 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
251249 * @returns {import('./types.js').Icon }
252250 */
253251export function configIcon ( name ) {
254- if ( ! ( name in configIcons ) ) {
255- throw new Error ( `No icon found for config ${ name } ` ) ;
256- }
257252 return configIcons [ name ] ;
258253}
259254
260255/**
261256 * 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
263258 */
264259export function configPattern ( name ) {
265260 if ( ! ( name in configPatterns ) ) {
@@ -270,7 +265,7 @@ export function configPattern(name) {
270265
271266/**
272267 * 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
274269 * @returns {string | undefined }
275270 */
276271export function configExtraPattern ( name ) {
@@ -279,16 +274,15 @@ export function configExtraPattern(name) {
279274
280275/**
281276 * 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
283278 */
284279export function isConfigForTests ( name ) {
285- // @ts -expect-error the point is to check if string is a union
286280 return testConfigs . has ( name ) ;
287281}
288282
289283/**
290284 * 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
292286 * @returns {Promise<import('@typescript-eslint/utils').TSESLint.FlatConfig.ConfigArray> }
293287 */
294288export async function importConfig ( name ) {
0 commit comments