Skip to content

Commit e17a2fe

Browse files
authored
Merge pull request #197 from storybookjs/norbert/vitest
Modernize codebase (tsup, vitest, etc.)
2 parents d2fe5dc + 03da210 commit e17a2fe

35 files changed

+1476
-1581
lines changed

.github/workflows/test.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,11 @@ jobs:
2121
- name: Build
2222
run: pnpm run build
2323

24-
- name: Run tests
25-
run: pnpm run test:ci
24+
- name: Run Check
25+
run: pnpm run check
26+
27+
- name: Run tests:unit
28+
run: pnpm run test:unit
29+
30+
- name: Run tests:integration
31+
run: pnpm run test:integration

.prettierrc.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { Options } from 'prettier'
2+
3+
declare const config: Options
4+
export default config

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ This plugin does not support MDX files.
181181
| [`storybook/hierarchy-separator`](./docs/rules/hierarchy-separator.md) | Deprecated hierarchy separator in title property | 🔧 | <ul><li>csf</li><li>flat/csf</li><li>recommended</li><li>flat/recommended</li><li>csf-strict</li><li>flat/csf-strict</li></ul> |
182182
| [`storybook/meta-inline-properties`](./docs/rules/meta-inline-properties.md) | Meta should only have inline properties | | N/A |
183183
| [`storybook/no-redundant-story-name`](./docs/rules/no-redundant-story-name.md) | A story should not have a redundant name property | 🔧 | <ul><li>csf</li><li>flat/csf</li><li>recommended</li><li>flat/recommended</li><li>csf-strict</li><li>flat/csf-strict</li></ul> |
184+
| [`storybook/no-renderer-packages`](./docs/rules/no-renderer-packages.md) | Do not import renderer packages directly in stories | | <ul><li>recommended</li><li>flat/recommended</li></ul> |
184185
| [`storybook/no-stories-of`](./docs/rules/no-stories-of.md) | storiesOf is deprecated and should not be used | | <ul><li>csf-strict</li><li>flat/csf-strict</li></ul> |
185186
| [`storybook/no-title-property-in-meta`](./docs/rules/no-title-property-in-meta.md) | Do not define a title in meta | 🔧 | <ul><li>csf-strict</li><li>flat/csf-strict</li></ul> |
186187
| [`storybook/no-uninstalled-addons`](./docs/rules/no-uninstalled-addons.md) | This rule identifies storybook addons that are invalid because they are either not installed or contain a typo in their name. | | <ul><li>recommended</li><li>flat/recommended</li></ul> |

docs/rules/no-renderer-packages.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Do not import renderer packages directly in stories (no-renderer-packages)
2+
3+
<!-- RULE-CATEGORIES:START -->
4+
5+
**Included in these configurations**: <ul><li>recommended</li><li>flat/recommended</li></ul>
6+
7+
<!-- RULE-CATEGORIES:END -->
8+
9+
## Rule Details
10+
11+
This rule prevents importing Storybook renderer packages directly in stories. Instead, you should use framework-specific packages that are designed for your build tool (e.g., Vite, webpack).
12+
13+
Examples of **incorrect** code for this rule:
14+
15+
```js
16+
import { something } from '@storybook/react'
17+
import { something } from '@storybook/vue3'
18+
import { something } from '@storybook/web-components'
19+
```
20+
21+
Examples of **correct** code for this rule:
22+
23+
```js
24+
import { something } from '@storybook/react-vite'
25+
import { something } from '@storybook/vue3-webpack5'
26+
import { something } from '@storybook/web-components-vite'
27+
```
28+
29+
## When Not To Use It
30+
31+
If you have a specific need to use renderer packages directly in your stories, you can disable this rule. However, it's recommended to use the framework-specific packages as they are optimized for your build tool.
32+
33+
## Further Reading
34+
35+
For more information about Storybook's framework-specific packages and build tools, see:
36+
37+
- [Storybook for React](https://storybook.js.org/docs/react/get-started/install)
38+
- [Storybook for Vue](https://storybook.js.org/docs/vue/get-started/install)
39+
- [Storybook for Web Components](https://storybook.js.org/docs/web-components/get-started/install)

lib/configs/csf-strict.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* in order to update its content, execute "pnpm run update-all"
55
*/
66
export = {
7-
extends: require.resolve('./csf'),
7+
extends: require.resolve('eslint-plugin-storybook/dist/configs/csf'),
88
rules: {
99
'react-hooks/rules-of-hooks': 'off',
1010
'import/no-anonymous-default-export': 'off',

lib/configs/flat/recommended.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export = [
2424
'storybook/default-exports': 'error',
2525
'storybook/hierarchy-separator': 'warn',
2626
'storybook/no-redundant-story-name': 'warn',
27+
'storybook/no-renderer-packages': 'error',
2728
'storybook/prefer-pascal-case': 'warn',
2829
'storybook/story-exports': 'error',
2930
'storybook/use-storybook-expect': 'error',

lib/configs/recommended.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export = {
1616
'storybook/default-exports': 'error',
1717
'storybook/hierarchy-separator': 'warn',
1818
'storybook/no-redundant-story-name': 'warn',
19+
'storybook/no-renderer-packages': 'error',
1920
'storybook/prefer-pascal-case': 'warn',
2021
'storybook/story-exports': 'error',
2122
'storybook/use-storybook-expect': 'error',

lib/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import defaultExports from './rules/default-exports'
2121
import hierarchySeparator from './rules/hierarchy-separator'
2222
import metaInlineProperties from './rules/meta-inline-properties'
2323
import noRedundantStoryName from './rules/no-redundant-story-name'
24+
import noRendererPackages from './rules/no-renderer-packages'
2425
import noStoriesOf from './rules/no-stories-of'
2526
import noTitlePropertyInMeta from './rules/no-title-property-in-meta'
2627
import noUninstalledAddons from './rules/no-uninstalled-addons'
@@ -52,6 +53,7 @@ export = {
5253
'hierarchy-separator': hierarchySeparator,
5354
'meta-inline-properties': metaInlineProperties,
5455
'no-redundant-story-name': noRedundantStoryName,
56+
'no-renderer-packages': noRendererPackages,
5557
'no-stories-of': noStoriesOf,
5658
'no-title-property-in-meta': noTitlePropertyInMeta,
5759
'no-uninstalled-addons': noUninstalledAddons,

lib/rules/await-interactions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export = createStorybookRule({
137137
node.specifiers.find(
138138
(spec) =>
139139
isImportSpecifier(spec) &&
140+
'name' in spec.imported &&
140141
spec.imported.name === 'userEvent' &&
141142
spec.local.name === 'userEvent'
142143
) !== undefined
@@ -147,7 +148,8 @@ export = createStorybookRule({
147148
return (
148149
(node.source.value === '@storybook/jest' || node.source.value === '@storybook/test') &&
149150
node.specifiers.find(
150-
(spec) => isImportSpecifier(spec) && spec.imported.name === 'expect'
151+
(spec) =>
152+
isImportSpecifier(spec) && 'name' in spec.imported && spec.imported.name === 'expect'
151153
) !== undefined
152154
)
153155
}

lib/rules/default-exports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export = createStorybookRule({
6767

6868
return {
6969
ImportSpecifier(node) {
70-
if (node.imported.name === 'storiesOf') {
70+
if ('name' in node.imported && node.imported.name === 'storiesOf') {
7171
hasStoriesOfImport = true
7272
}
7373
},

0 commit comments

Comments
 (0)