Skip to content

Commit 9eae85c

Browse files
committed
Implement no-renderer-packages rule and update configurations
- Added a new ESLint rule `no-renderer-packages` to prevent direct imports of Storybook renderer packages in stories, promoting the use of framework-specific packages. - Updated the `README.md` to include documentation for the new rule. - Modified `tsup.config.ts` to include additional entry points for TypeScript files. - Adjusted ESLint configurations in `csf-strict.ts` and `recommended.ts` to enforce the new rule. - Refactored Prettier configuration to use ES module syntax for consistency.
1 parent c93de38 commit 9eae85c

File tree

9 files changed

+48
-6
lines changed

9 files changed

+48
-6
lines changed

.prettierrc.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
const config = {
1+
module.exports = {
22
trailingComma: 'es5',
33
tabWidth: 2,
44
semi: false,
55
singleQuote: true,
66
printWidth: 100,
77
bracketSpacing: true,
88
}
9-
10-
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,

tools/update-lib-configs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function formatCategory(category: TCategory) {
4343
* in order to update its content, execute "pnpm run update-all"
4444
*/
4545
export = {
46-
extends: require.resolve('./${extendsCategoryId}'),
46+
extends: require.resolve('eslint-plugin-storybook/dist/configs/${extendsCategoryId}'),
4747
rules: ${formatRules(category.rules)}
4848
}
4949
`

tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineConfig } from 'tsup'
22

33
export default defineConfig({
4-
entry: ['lib/index.ts'],
4+
entry: ['lib/index.ts', 'lib/configs/**/*.ts'],
55
format: ['cjs'],
66
dts: true,
77
clean: true,

0 commit comments

Comments
 (0)