Skip to content

Commit ad49a03

Browse files
committed
Type configs using literal types
By using `as const` on the string values for each of the rule configs, we ensure that the generated rules have string literal types matching their configured values. Fixes #181
1 parent 3e31c5b commit ad49a03

9 files changed

+16
-16
lines changed

lib/configs/addon-interactions.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ export = {
1515
'storybook/context-in-play-function': 'error',
1616
'storybook/use-storybook-expect': 'error',
1717
'storybook/use-storybook-testing-library': 'error',
18-
},
18+
} as const,
1919
},
2020
{
2121
files: ['.storybook/main.@(js|cjs|mjs|ts)'],
2222
rules: {
2323
'storybook/no-uninstalled-addons': 'error',
24-
},
24+
} as const,
2525
},
2626
],
2727
}

lib/configs/csf-strict.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ export = {
1010
'import/no-anonymous-default-export': 'off',
1111
'storybook/no-stories-of': 'error',
1212
'storybook/no-title-property-in-meta': 'error',
13-
},
13+
} as const,
1414
}

lib/configs/csf.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ export = {
1616
'storybook/hierarchy-separator': 'warn',
1717
'storybook/no-redundant-story-name': 'warn',
1818
'storybook/story-exports': 'error',
19-
},
19+
} as const,
2020
},
2121
{
2222
files: ['.storybook/main.@(js|cjs|mjs|ts)'],
2323
rules: {
2424
'storybook/no-uninstalled-addons': 'error',
25-
},
25+
} as const,
2626
},
2727
],
2828
}

lib/configs/flat/addon-interactions.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ export = [
2323
'storybook/context-in-play-function': 'error',
2424
'storybook/use-storybook-expect': 'error',
2525
'storybook/use-storybook-testing-library': 'error',
26-
},
26+
} as const,
2727
},
2828
{
2929
name: 'storybook:addon-interactions:main-rules',
3030
files: ['.storybook/main.@(js|cjs|mjs|ts)'],
3131
rules: {
3232
'storybook/no-uninstalled-addons': 'error',
33-
},
33+
} as const,
3434
},
3535
]

lib/configs/flat/csf-strict.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ export = [
1414
'import/no-anonymous-default-export': 'off',
1515
'storybook/no-stories-of': 'error',
1616
'storybook/no-title-property-in-meta': 'error',
17-
},
17+
} as const,
1818
},
1919
]

lib/configs/flat/csf.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ export = [
2424
'storybook/hierarchy-separator': 'warn',
2525
'storybook/no-redundant-story-name': 'warn',
2626
'storybook/story-exports': 'error',
27-
},
27+
} as const,
2828
},
2929
{
3030
name: 'storybook:csf:main-rules',
3131
files: ['.storybook/main.@(js|cjs|mjs|ts)'],
3232
rules: {
3333
'storybook/no-uninstalled-addons': 'error',
34-
},
34+
} as const,
3535
},
3636
]

lib/configs/flat/recommended.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ export = [
2828
'storybook/story-exports': 'error',
2929
'storybook/use-storybook-expect': 'error',
3030
'storybook/use-storybook-testing-library': 'error',
31-
},
31+
} as const,
3232
},
3333
{
3434
name: 'storybook:recommended:main-rules',
3535
files: ['.storybook/main.@(js|cjs|mjs|ts)'],
3636
rules: {
3737
'storybook/no-uninstalled-addons': 'error',
38-
},
38+
} as const,
3939
},
4040
]

lib/configs/recommended.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ export = {
2020
'storybook/story-exports': 'error',
2121
'storybook/use-storybook-expect': 'error',
2222
'storybook/use-storybook-testing-library': 'error',
23-
},
23+
} as const,
2424
},
2525
{
2626
files: ['.storybook/main.@(js|cjs|mjs|ts)'],
2727
rules: {
2828
'storybook/no-uninstalled-addons': 'error',
29-
},
29+
} as const,
3030
},
3131
],
3232
}

tools/utils/updates.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ export function formatRules(rules: TCategory['rules'], exclude?: string[]) {
2222
{ ...externalRuleOverrides }
2323
)
2424

25-
return JSON.stringify(obj, null, 2)
25+
return JSON.stringify(obj, null, 2) + ' as const'
2626
}
2727

2828
export function formatSingleRule(rules: TCategory['rules'], ruleId: string) {
2929
const ruleOpt = rules.find((rule) => rule.ruleId === ruleId)?.meta.severity || 'error'
3030

31-
return JSON.stringify({ [ruleId]: ruleOpt }, null, 2)
31+
return JSON.stringify({ [ruleId]: ruleOpt }, null, 2) + ' as const'
3232
}
3333

3434
export const SUPPORTED_EXTENSIONS = ['ts', 'tsx', 'js', 'jsx', 'mjs', 'cjs']

0 commit comments

Comments
 (0)