Skip to content

Commit

Permalink
feat: add eslint-plugin-storybook
Browse files Browse the repository at this point in the history
- `createStorybookRules` is now using eslint-plugin-storybook rules
- storybook `files` now also applies to `*.story.*`
- `getDependencies` return value for storybook is now an object: `storybook: { hasStorybook: boolean; hasStorybookTestingLibrary: boolean }`
  • Loading branch information
ljosberinn authored Dec 23, 2021
1 parent f79ef67 commit a58d2f5
Show file tree
Hide file tree
Showing 15 changed files with 566 additions and 293 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ All rules are commented and link to their docs.
- [x] jest-dom
- [x] @testing-library
- [x] prettier
- [x] storybook
- [x] storybook & storybook/testing-library

## What can you do?

Expand Down Expand Up @@ -230,10 +230,16 @@ interface Project {
* whether any `@testing-library/<environment>` is present
*/
hasTestingLibrary: boolean;
/**
* whether any `@storybook/<package>` is present
*/
hasStorybook: boolean;
storybook: {
/**
* whether any `@storybook/` is present that is not `@storybook/testing-library`
*/
hasStorybook: boolean;
/**
* whether `@storybook/testing-library` is present
*/
hasStorybookTestingLibrary: boolean;
};
typescript: {
/**
* whether `typescript` is present
Expand Down
5 changes: 4 additions & 1 deletion integration/cra-js/deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"hasJestDom": true,
"hasNodeTypes": false,
"hasTestingLibrary": true,
"hasStorybook": false,
"storybook": {
"hasStorybook": false,
"hasStorybookTestingLibrary": false
},
"react": {
"hasReact": true,
"isCreateReactApp": true,
Expand Down
5 changes: 4 additions & 1 deletion integration/cra-ts/deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"hasJestDom": true,
"hasNodeTypes": true,
"hasTestingLibrary": true,
"hasStorybook": false,
"storybook": {
"hasStorybook": false,
"hasStorybookTestingLibrary": false
},
"react": {
"hasReact": true,
"isCreateReactApp": true,
Expand Down
5 changes: 4 additions & 1 deletion integration/next-js/deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"hasJestDom": false,
"hasNodeTypes": false,
"hasTestingLibrary": false,
"hasStorybook": false,
"storybook": {
"hasStorybook": false,
"hasStorybookTestingLibrary": false
},
"react": {
"hasReact": true,
"isCreateReactApp": false,
Expand Down
5 changes: 4 additions & 1 deletion integration/next-ts/deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"hasJestDom": false,
"hasNodeTypes": false,
"hasTestingLibrary": false,
"hasStorybook": false,
"storybook": {
"hasStorybook": false,
"hasStorybookTestingLibrary": false
},
"react": {
"hasReact": true,
"isCreateReactApp": false,
Expand Down
5 changes: 4 additions & 1 deletion integration/remix-js/deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"hasJestDom": false,
"hasNodeTypes": false,
"hasTestingLibrary": false,
"hasStorybook": false,
"storybook": {
"hasStorybook": false,
"hasStorybookTestingLibrary": false
},
"react": {
"hasReact": true,
"isCreateReactApp": false,
Expand Down
5 changes: 4 additions & 1 deletion integration/remix-ts/deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"hasJestDom": false,
"hasNodeTypes": false,
"hasTestingLibrary": false,
"hasStorybook": false,
"storybook": {
"hasStorybook": false,
"hasStorybookTestingLibrary": false
},
"react": {
"hasReact": true,
"isCreateReactApp": false,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"eslint-plugin-react": "7.28.0",
"eslint-plugin-react-hooks": "4.3.0",
"eslint-plugin-sonarjs": "0.11.0",
"eslint-plugin-storybook": "0.5.5",
"eslint-plugin-testing-library": "5.0.1",
"eslint-plugin-unicorn": "39.0.0",
"read-pkg-up": "7.0.1",
Expand Down
87 changes: 73 additions & 14 deletions src/__tests__/__snapshots__/createConfig.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5169,7 +5169,6 @@ exports[`getDependencies accepts alternative tsDefaultConfig path 1`] = `
"hasJest": true,
"hasJestDom": false,
"hasNodeTypes": false,
"hasStorybook": false,
"hasTestingLibrary": false,
"react": {
"hasReact": false,
Expand All @@ -5179,6 +5178,10 @@ exports[`getDependencies accepts alternative tsDefaultConfig path 1`] = `
"isRemix": false,
"version": undefined,
},
"storybook": {
"hasStorybook": false,
"hasStorybookTestingLibrary": false,
},
"typescript": {
"config": undefined,
"hasTypeScript": false,
Expand All @@ -5187,12 +5190,11 @@ exports[`getDependencies accepts alternative tsDefaultConfig path 1`] = `
}
`;

exports[`getDependencies adds the storybook override given any @storybook/* dependency - "@storybook/foo" 1`] = `
exports[`getDependencies adds the storybook override given a non @storybook/testing-library dependency - "@storybook/foo" 1`] = `
{
"hasJest": false,
"hasJestDom": false,
"hasNodeTypes": false,
"hasStorybook": true,
"hasTestingLibrary": false,
"react": {
"hasReact": false,
Expand All @@ -5202,6 +5204,10 @@ exports[`getDependencies adds the storybook override given any @storybook/* depe
"isRemix": false,
"version": undefined,
},
"storybook": {
"hasStorybook": true,
"hasStorybookTestingLibrary": false,
},
"typescript": {
"config": undefined,
"hasTypeScript": false,
Expand All @@ -5210,12 +5216,11 @@ exports[`getDependencies adds the storybook override given any @storybook/* depe
}
`;

exports[`getDependencies adds the storybook override given any @storybook/* dependency - "@storybook/react" 1`] = `
exports[`getDependencies adds the storybook override given a non @storybook/testing-library dependency - "@storybook/react" 1`] = `
{
"hasJest": false,
"hasJestDom": false,
"hasNodeTypes": false,
"hasStorybook": true,
"hasTestingLibrary": false,
"react": {
"hasReact": false,
Expand All @@ -5225,6 +5230,10 @@ exports[`getDependencies adds the storybook override given any @storybook/* depe
"isRemix": false,
"version": undefined,
},
"storybook": {
"hasStorybook": true,
"hasStorybookTestingLibrary": false,
},
"typescript": {
"config": undefined,
"hasTypeScript": false,
Expand All @@ -5233,12 +5242,11 @@ exports[`getDependencies adds the storybook override given any @storybook/* depe
}
`;

exports[`getDependencies adds the storybook override given any @storybook/* dependency - "@storybook/vue" 1`] = `
exports[`getDependencies adds the storybook override given a non @storybook/testing-library dependency - "@storybook/vue" 1`] = `
{
"hasJest": false,
"hasJestDom": false,
"hasNodeTypes": false,
"hasStorybook": true,
"hasTestingLibrary": false,
"react": {
"hasReact": false,
Expand All @@ -5248,6 +5256,10 @@ exports[`getDependencies adds the storybook override given any @storybook/* depe
"isRemix": false,
"version": undefined,
},
"storybook": {
"hasStorybook": true,
"hasStorybookTestingLibrary": false,
},
"typescript": {
"config": undefined,
"hasTypeScript": false,
Expand All @@ -5261,7 +5273,6 @@ exports[`getDependencies given CRA, forces jest to true 1`] = `
"hasJest": true,
"hasJestDom": false,
"hasNodeTypes": false,
"hasStorybook": false,
"hasTestingLibrary": false,
"react": {
"hasReact": false,
Expand All @@ -5271,6 +5282,10 @@ exports[`getDependencies given CRA, forces jest to true 1`] = `
"isRemix": false,
"version": undefined,
},
"storybook": {
"hasStorybook": false,
"hasStorybookTestingLibrary": false,
},
"typescript": {
"config": undefined,
"hasTypeScript": false,
Expand All @@ -5284,7 +5299,6 @@ exports[`getDependencies given typescript allows passing an alternative tsConfig
"hasJest": false,
"hasJestDom": false,
"hasNodeTypes": false,
"hasStorybook": false,
"hasTestingLibrary": false,
"react": {
"hasReact": false,
Expand All @@ -5294,6 +5308,10 @@ exports[`getDependencies given typescript allows passing an alternative tsConfig
"isRemix": false,
"version": undefined,
},
"storybook": {
"hasStorybook": false,
"hasStorybookTestingLibrary": false,
},
"typescript": {
"config": {
"compilerOptions": {
Expand All @@ -5311,7 +5329,6 @@ exports[`getDependencies given typescript bails on the first config found with c
"hasJest": false,
"hasJestDom": false,
"hasNodeTypes": false,
"hasStorybook": false,
"hasTestingLibrary": false,
"react": {
"hasReact": false,
Expand All @@ -5321,6 +5338,10 @@ exports[`getDependencies given typescript bails on the first config found with c
"isRemix": false,
"version": undefined,
},
"storybook": {
"hasStorybook": false,
"hasStorybookTestingLibrary": false,
},
"typescript": {
"config": {
"compilerOptions": {
Expand All @@ -5338,7 +5359,6 @@ exports[`getDependencies given typescript does not check tsconfig.json if no ts
"hasJest": false,
"hasJestDom": false,
"hasNodeTypes": false,
"hasStorybook": false,
"hasTestingLibrary": false,
"react": {
"hasReact": false,
Expand All @@ -5348,6 +5368,10 @@ exports[`getDependencies given typescript does not check tsconfig.json if no ts
"isRemix": false,
"version": undefined,
},
"storybook": {
"hasStorybook": false,
"hasStorybookTestingLibrary": false,
},
"typescript": {
"config": undefined,
"hasTypeScript": false,
Expand All @@ -5361,7 +5385,6 @@ exports[`getDependencies given typescript recursively reads extends property and
"hasJest": false,
"hasJestDom": false,
"hasNodeTypes": false,
"hasStorybook": false,
"hasTestingLibrary": false,
"react": {
"hasReact": false,
Expand All @@ -5371,6 +5394,10 @@ exports[`getDependencies given typescript recursively reads extends property and
"isRemix": false,
"version": undefined,
},
"storybook": {
"hasStorybook": false,
"hasStorybookTestingLibrary": false,
},
"typescript": {
"config": {
"compilerOptions": {
Expand All @@ -5388,7 +5415,6 @@ exports[`getDependencies matches snapshot 1`] = `
"hasJest": true,
"hasJestDom": false,
"hasNodeTypes": false,
"hasStorybook": false,
"hasTestingLibrary": false,
"react": {
"hasReact": false,
Expand All @@ -5398,6 +5424,10 @@ exports[`getDependencies matches snapshot 1`] = `
"isRemix": false,
"version": undefined,
},
"storybook": {
"hasStorybook": false,
"hasStorybookTestingLibrary": false,
},
"typescript": {
"config": undefined,
"hasTypeScript": false,
Expand All @@ -5411,7 +5441,6 @@ exports[`getDependencies matches snapshot when erroring 1`] = `
"hasJest": false,
"hasJestDom": false,
"hasNodeTypes": false,
"hasStorybook": false,
"hasTestingLibrary": false,
"react": {
"hasReact": false,
Expand All @@ -5421,6 +5450,36 @@ exports[`getDependencies matches snapshot when erroring 1`] = `
"isRemix": false,
"version": undefined,
},
"storybook": {
"hasStorybook": false,
"hasStorybookTestingLibrary": false,
},
"typescript": {
"config": undefined,
"hasTypeScript": false,
"version": undefined,
},
}
`;

exports[`getDependencies sets hasStorybookTestingLibrary to true given its presence 1`] = `
{
"hasJest": false,
"hasJestDom": false,
"hasNodeTypes": false,
"hasTestingLibrary": false,
"react": {
"hasReact": false,
"isCreateReactApp": false,
"isNext": false,
"isPreact": false,
"isRemix": false,
"version": undefined,
},
"storybook": {
"hasStorybook": false,
"hasStorybookTestingLibrary": true,
},
"typescript": {
"config": undefined,
"hasTypeScript": false,
Expand Down
Loading

0 comments on commit a58d2f5

Please sign in to comment.