eslint-plugin-storybook 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/rules/story-exports.js +2 -14
- package/dist/utils/index.js +25 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
# v0.5.3 (Fri Dec 03 2021)
|
|
2
|
+
|
|
3
|
+
#### 🐛 Bug Fix
|
|
4
|
+
|
|
5
|
+
- extend story-exports rule to support export lists, fixes #57 [#58](https://github.com/storybookjs/eslint-plugin-storybook/pull/58) (stephen@Stephens-MacBook-Air.local [@yannbf](https://github.com/yannbf))
|
|
6
|
+
|
|
7
|
+
#### Authors: 2
|
|
8
|
+
|
|
9
|
+
- Stephen Marsh ([@stephenhmarsh](https://github.com/stephenhmarsh))
|
|
10
|
+
- Yann Braga ([@yannbf](https://github.com/yannbf))
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
1
14
|
# v0.5.2 (Thu Dec 02 2021)
|
|
2
15
|
|
|
3
16
|
#### 🐛 Bug Fix
|
|
@@ -3,11 +3,9 @@
|
|
|
3
3
|
* @fileoverview A story file must contain at least one story export
|
|
4
4
|
* @author Yann Braga
|
|
5
5
|
*/
|
|
6
|
-
const csf_1 = require("@storybook/csf");
|
|
7
6
|
const create_storybook_rule_1 = require("../utils/create-storybook-rule");
|
|
8
7
|
const constants_1 = require("../utils/constants");
|
|
9
8
|
const utils_1 = require("../utils");
|
|
10
|
-
const ast_1 = require("../utils/ast");
|
|
11
9
|
module.exports = (0, create_storybook_rule_1.createStorybookRule)({
|
|
12
10
|
name: 'story-exports',
|
|
13
11
|
defaultOptions: [],
|
|
@@ -30,7 +28,6 @@ module.exports = (0, create_storybook_rule_1.createStorybookRule)({
|
|
|
30
28
|
//----------------------------------------------------------------------
|
|
31
29
|
// Helpers
|
|
32
30
|
//----------------------------------------------------------------------
|
|
33
|
-
const isValidStoryExport = (node) => (0, csf_1.isExportStory)(node.name, nonStoryExportsConfig) && node.name !== '__namedExportsOrder';
|
|
34
31
|
//----------------------------------------------------------------------
|
|
35
32
|
// Public
|
|
36
33
|
//----------------------------------------------------------------------
|
|
@@ -54,22 +51,13 @@ module.exports = (0, create_storybook_rule_1.createStorybookRule)({
|
|
|
54
51
|
}
|
|
55
52
|
},
|
|
56
53
|
ExportNamedDeclaration: function (node) {
|
|
57
|
-
|
|
58
|
-
if (!node.declaration)
|
|
59
|
-
return;
|
|
60
|
-
const decl = node.declaration;
|
|
61
|
-
if ((0, ast_1.isVariableDeclaration)(decl)) {
|
|
62
|
-
const { id } = decl.declarations[0];
|
|
63
|
-
if ((0, ast_1.isIdentifier)(id)) {
|
|
64
|
-
namedExports.push(id);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
54
|
+
namedExports.push(...(0, utils_1.getAllNamedExports)(node));
|
|
67
55
|
},
|
|
68
56
|
'Program:exit': function (node) {
|
|
69
57
|
if (hasStoriesOfImport || !meta) {
|
|
70
58
|
return;
|
|
71
59
|
}
|
|
72
|
-
const storyExports = namedExports.filter(isValidStoryExport);
|
|
60
|
+
const storyExports = namedExports.filter((exp) => (0, utils_1.isValidStoryExport)(exp, nonStoryExportsConfig));
|
|
73
61
|
if (storyExports.length) {
|
|
74
62
|
return;
|
|
75
63
|
}
|
package/dist/utils/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDescriptor = exports.getMetaObjectExpression = exports.isPlayFunction = exports.docsUrl = void 0;
|
|
3
|
+
exports.getAllNamedExports = exports.isValidStoryExport = exports.getDescriptor = exports.getMetaObjectExpression = exports.isPlayFunction = exports.docsUrl = void 0;
|
|
4
|
+
const csf_1 = require("@storybook/csf");
|
|
4
5
|
const ast_utils_1 = require("@typescript-eslint/experimental-utils/dist/ast-utils");
|
|
5
6
|
const ast_1 = require("./ast");
|
|
6
7
|
const docsUrl = (ruleName) => `https://github.com/storybookjs/eslint-plugin-storybook/blob/main/docs/rules/${ruleName}.md`;
|
|
@@ -47,3 +48,26 @@ const getDescriptor = (metaDeclaration, propertyName) => {
|
|
|
47
48
|
}
|
|
48
49
|
};
|
|
49
50
|
exports.getDescriptor = getDescriptor;
|
|
51
|
+
const isValidStoryExport = (node, nonStoryExportsConfig) => (0, csf_1.isExportStory)(node.name, nonStoryExportsConfig) && node.name !== '__namedExportsOrder';
|
|
52
|
+
exports.isValidStoryExport = isValidStoryExport;
|
|
53
|
+
const getAllNamedExports = (node) => {
|
|
54
|
+
// e.g. export { MyStory }
|
|
55
|
+
if (!node.declaration && node.specifiers) {
|
|
56
|
+
return node.specifiers.reduce((acc, specifier) => {
|
|
57
|
+
if ((0, ast_1.isIdentifier)(specifier.exported)) {
|
|
58
|
+
acc.push(specifier.exported);
|
|
59
|
+
}
|
|
60
|
+
return acc;
|
|
61
|
+
}, []);
|
|
62
|
+
}
|
|
63
|
+
const decl = node.declaration;
|
|
64
|
+
if ((0, ast_1.isVariableDeclaration)(decl)) {
|
|
65
|
+
const { id } = decl.declarations[0];
|
|
66
|
+
// e.g. export const MyStory
|
|
67
|
+
if ((0, ast_1.isIdentifier)(id)) {
|
|
68
|
+
return [id];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return [];
|
|
72
|
+
};
|
|
73
|
+
exports.getAllNamedExports = getAllNamedExports;
|