Skip to content

Commit c267f87

Browse files
committed
chore(eslint-config): remove storybook as transitive dep
1 parent cad279d commit c267f87

File tree

6 files changed

+28
-9
lines changed

6 files changed

+28
-9
lines changed

.changeset/thin-adults-yawn.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@guardian/eslint-config': major
3+
---
4+
5+
Make `eslint-plugin-storybook` into an optional peer dependency
6+
7+
tl;dr if using the `storybook` config from `@guardian/eslint-config`, then you must have both `eslint-plugin-storybook` and `storybook` installed. If you are not using the `storybook` config, then you do not need to have either of these installed.
8+
9+
- Issue was found that since `eslint-plugin-storybook` is a direct dependency of `@guardian/eslint-config`, and that `storybook` is a peer dependency of `eslint-plugin-storybook`, then `storybook` is always installed as a transitive dependency of `@guardian/eslint-config`. This causes issues for projects that use `@guardian/eslint-config` but do not use Storybook, as they will have an unnecessary dependency on Storybook and may encounter issues if they have a different version of Storybook installed.
10+
- Now we've moved `eslint-plugin-storybook` from `dependencies` to `peerDependencies` and mark it as optional via `peerDependenciesMeta`. This means that projects that use `@guardian/eslint-config` but do not use Storybook will not have `eslint-plugin-storybook` or `storybook` installed, and will not encounter any issues. Projects that do use the `storybook` config from `@guardian/eslint-config` will need to have both `eslint-plugin-storybook` and `storybook` installed as direct dependencies.

libs/@guardian/eslint-config/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,5 @@ Provides a collection of configs for checking React components.
106106
#### [`configs.storybook`](./configs/storybook.js)
107107

108108
Provides a collection of configs for checking Storybook stories.
109+
110+
When using the storybook config, be sure to also have `eslint-plugin-storybook` and `storybook` installed in your project, otherwise the config will be ignored.

libs/@guardian/eslint-config/configs/storybook.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
// eslint-plugin-storybook has a dependency on on Storybook which causes it
2-
// to crash eslint when it is imported if Storybook is not installed.
1+
// eslint-plugin-storybook is an optional peer dependency.
2+
// It also has its own peer dependency on Storybook which can cause it
3+
// to crash eslint when imported if Storybook is not installed.
34
const loadStorybookRecommended = async () => {
45
try {
5-
// eslint-disable-next-line import/no-unresolved -- We're checking if Storybook is resolveable
6+
// eslint-disable-next-line import/no-unresolved -- We're checking if Storybook is resolvable
67
await import('storybook');
8+
// Check that plugin is also available
9+
const storybook = await import('eslint-plugin-storybook');
10+
return storybook.configs['flat/recommended'];
711
} catch {
812
return [];
913
}
10-
11-
const storybook = await import('eslint-plugin-storybook');
12-
return storybook.configs['flat/recommended'];
1314
};
1415

1516
export default [

libs/@guardian/eslint-config/package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"eslint-plugin-jsx-a11y": "6.10.2",
2323
"eslint-plugin-react": "7.37.5",
2424
"eslint-plugin-react-hooks": "7.0.1",
25-
"eslint-plugin-storybook": "10.2.13",
2625
"globals": "17.3.0",
2726
"read-package-up": "12.0.0",
2827
"typescript-eslint": "8.55.0"
@@ -32,7 +31,13 @@
3231
"wireit": "0.14.12"
3332
},
3433
"peerDependencies": {
35-
"eslint": "^9.39.1"
34+
"eslint": "^9.39.1",
35+
"eslint-plugin-storybook": "^10.2.13"
36+
},
37+
"peerDependenciesMeta": {
38+
"eslint-plugin-storybook": {
39+
"optional": true
40+
}
3641
},
3742
"wireit": {
3843
"lint": {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"ignoreMissing": [
2929
"@types/node",
3030
"eslint",
31+
"eslint-plugin-storybook",
3132
"prettier"
3233
]
3334
},

pnpm-lock.yaml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)