eslint-plugin-storybook 0.2.4 → 0.3.2
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
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# v0.3.2 (Thu Nov 11 2021)
|
|
2
|
+
|
|
3
|
+
#### 🐛 Bug Fix
|
|
4
|
+
|
|
5
|
+
- prefer-pascal-case: ignore stories that start with underscore [#38](https://github.com/storybookjs/eslint-plugin-storybook/pull/38) ([@yannbf](https://github.com/yannbf))
|
|
6
|
+
|
|
7
|
+
#### Authors: 1
|
|
8
|
+
|
|
9
|
+
- Yann Braga ([@yannbf](https://github.com/yannbf))
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# v0.3.1 (Thu Nov 11 2021)
|
|
14
|
+
|
|
15
|
+
#### 🐛 Bug Fix
|
|
16
|
+
|
|
17
|
+
- hierarchy-separator: remove dot from checkings [#37](https://github.com/storybookjs/eslint-plugin-storybook/pull/37) ([@yannbf](https://github.com/yannbf))
|
|
18
|
+
|
|
19
|
+
#### Authors: 1
|
|
20
|
+
|
|
21
|
+
- Yann Braga ([@yannbf](https://github.com/yannbf))
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
# v0.3.0 (Thu Nov 11 2021)
|
|
26
|
+
|
|
27
|
+
#### 🚀 Enhancement
|
|
28
|
+
|
|
29
|
+
- Add autofix heuristics for default-exports rule [#36](https://github.com/storybookjs/eslint-plugin-storybook/pull/36) ([@shilman](https://github.com/shilman))
|
|
30
|
+
|
|
31
|
+
#### 🐛 Bug Fix
|
|
32
|
+
|
|
33
|
+
- no-title-property-in-meta: fix dangling comma and highlighting [#32](https://github.com/storybookjs/eslint-plugin-storybook/pull/32) ([@yannbf](https://github.com/yannbf))
|
|
34
|
+
- Update docs [#35](https://github.com/storybookjs/eslint-plugin-storybook/pull/35) ([@kylegach](https://github.com/kylegach) [@yannbf](https://github.com/yannbf))
|
|
35
|
+
- prefer-pascal-case: ignore __namedExportsOrder [#34](https://github.com/storybookjs/eslint-plugin-storybook/pull/34) ([@yannbf](https://github.com/yannbf))
|
|
36
|
+
- hierarchy-separator: fix node highlight [#33](https://github.com/storybookjs/eslint-plugin-storybook/pull/33) ([@yannbf](https://github.com/yannbf))
|
|
37
|
+
- no-redundant-story-name: add CSF2 support [#31](https://github.com/storybookjs/eslint-plugin-storybook/pull/31) ([@yannbf](https://github.com/yannbf))
|
|
38
|
+
- prefer-pascal-case: add non-story exports check [#30](https://github.com/storybookjs/eslint-plugin-storybook/pull/30) ([@yannbf](https://github.com/yannbf))
|
|
39
|
+
- default-exports: target first non-import nodes when reporting [#29](https://github.com/storybookjs/eslint-plugin-storybook/pull/29) ([@yannbf](https://github.com/yannbf))
|
|
40
|
+
- Fix prefer-pascal-case to support typescript & variable references [#26](https://github.com/storybookjs/eslint-plugin-storybook/pull/26) ([@shilman](https://github.com/shilman))
|
|
41
|
+
- await-interactions: Fix bad expect matchers [#27](https://github.com/storybookjs/eslint-plugin-storybook/pull/27) ([@shilman](https://github.com/shilman))
|
|
42
|
+
- Fix/meta as variable [#24](https://github.com/storybookjs/eslint-plugin-storybook/pull/24) ([@shilman](https://github.com/shilman) [@yannbf](https://github.com/yannbf))
|
|
43
|
+
- Docs/update rule docs [#25](https://github.com/storybookjs/eslint-plugin-storybook/pull/25) ([@yannbf](https://github.com/yannbf) [@shilman](https://github.com/shilman))
|
|
44
|
+
- add complex use case to await-interactions [#21](https://github.com/storybookjs/eslint-plugin-storybook/pull/21) ([@yannbf](https://github.com/yannbf) [@shilman](https://github.com/shilman))
|
|
45
|
+
- Chore: add typescript examples to test [#23](https://github.com/storybookjs/eslint-plugin-storybook/pull/23) ([@yannbf](https://github.com/yannbf))
|
|
46
|
+
- Feature/migrate to jest [#22](https://github.com/storybookjs/eslint-plugin-storybook/pull/22) ([@yannbf](https://github.com/yannbf))
|
|
47
|
+
- add support for CSF3 notation in use-storybook-expect [#16](https://github.com/storybookjs/eslint-plugin-storybook/pull/16) ([@yannbf](https://github.com/yannbf))
|
|
48
|
+
- chore(ci): add test workflow [#20](https://github.com/storybookjs/eslint-plugin-storybook/pull/20) ([@yannbf](https://github.com/yannbf))
|
|
49
|
+
- Feature/ts migration [#17](https://github.com/storybookjs/eslint-plugin-storybook/pull/17) ([@yannbf](https://github.com/yannbf))
|
|
50
|
+
- Fix use-storybook-testing-library default export handling [#18](https://github.com/storybookjs/eslint-plugin-storybook/pull/18) ([@shilman](https://github.com/shilman))
|
|
51
|
+
- fix no-redundant-story-name [#14](https://github.com/storybookjs/eslint-plugin-storybook/pull/14) ([@yannbf](https://github.com/yannbf))
|
|
52
|
+
- add exclude rule flag [#13](https://github.com/storybookjs/eslint-plugin-storybook/pull/13) ([@yannbf](https://github.com/yannbf))
|
|
53
|
+
- add await-interactions rule [#12](https://github.com/storybookjs/eslint-plugin-storybook/pull/12) ([@yannbf](https://github.com/yannbf))
|
|
54
|
+
- Fiix/title related rules [#11](https://github.com/storybookjs/eslint-plugin-storybook/pull/11) ([@yannbf](https://github.com/yannbf))
|
|
55
|
+
- fix and improve all tests [#10](https://github.com/storybookjs/eslint-plugin-storybook/pull/10) ([@yannbf](https://github.com/yannbf))
|
|
56
|
+
- Improve rule generation [#9](https://github.com/storybookjs/eslint-plugin-storybook/pull/9) ([@yannbf](https://github.com/yannbf))
|
|
57
|
+
- fix use-storybook-expect rule [#8](https://github.com/storybookjs/eslint-plugin-storybook/pull/8) ([@yannbf](https://github.com/yannbf))
|
|
58
|
+
- fix: add safe check for meta properties [#6](https://github.com/storybookjs/eslint-plugin-storybook/pull/6) ([@yannbf](https://github.com/yannbf))
|
|
59
|
+
- chore: add auto release setup [#4](https://github.com/storybookjs/eslint-plugin-storybook/pull/4) ([@yannbf](https://github.com/yannbf))
|
|
60
|
+
- Add addon interactions rules [#3](https://github.com/storybookjs/eslint-plugin-storybook/pull/3) ([@yannbf](https://github.com/yannbf))
|
|
61
|
+
- fix: resolve plugin category generation [#2](https://github.com/storybookjs/eslint-plugin-storybook/pull/2) ([@yannbf](https://github.com/yannbf))
|
|
62
|
+
- Add auto formatting with prettier + husky + lint-staged [#1](https://github.com/storybookjs/eslint-plugin-storybook/pull/1) ([@yannbf](https://github.com/yannbf))
|
|
63
|
+
|
|
64
|
+
#### ⚠️ Pushed to `main`
|
|
65
|
+
|
|
66
|
+
- 0.2.5 ([@yannbf](https://github.com/yannbf))
|
|
67
|
+
- 0.2.4 ([@yannbf](https://github.com/yannbf))
|
|
68
|
+
- 0.2.3 ([@yannbf](https://github.com/yannbf))
|
|
69
|
+
- 0.2.2 ([@yannbf](https://github.com/yannbf))
|
|
70
|
+
- 0.2.1 ([@yannbf](https://github.com/yannbf))
|
|
71
|
+
- update docs regarding default-exports ([@yannbf](https://github.com/yannbf))
|
|
72
|
+
- 0.2.0 ([@yannbf](https://github.com/yannbf))
|
|
73
|
+
- chore: update version to 0.1.1 ([@yannbf](https://github.com/yannbf))
|
|
74
|
+
- 0.0.1-alpha.9 ([@yannbf](https://github.com/yannbf))
|
|
75
|
+
- 0.0.1-alpha.8 ([@yannbf](https://github.com/yannbf))
|
|
76
|
+
- 0.0.1-alpha.7 ([@yannbf](https://github.com/yannbf))
|
|
77
|
+
- 0.0.1-alpha.6 ([@yannbf](https://github.com/yannbf))
|
|
78
|
+
- 0.0.1-alpha.5 ([@yannbf](https://github.com/yannbf))
|
|
79
|
+
- 0.0.1-alpha.4 ([@yannbf](https://github.com/yannbf))
|
|
80
|
+
- update typescript file generation ([@yannbf](https://github.com/yannbf))
|
|
81
|
+
- 0.0.1-alpha.3 ([@yannbf](https://github.com/yannbf))
|
|
82
|
+
- 0.0.1-alpha.2 ([@yannbf](https://github.com/yannbf))
|
|
83
|
+
- remove logs and test skip ([@yannbf](https://github.com/yannbf))
|
|
84
|
+
- 0.0.1-alpha.1 ([@yannbf](https://github.com/yannbf))
|
|
85
|
+
- chore: add rafael rozon as contributor ([@yannbf](https://github.com/yannbf))
|
|
86
|
+
- 0.0.1-alpha.0 ([@yannbf](https://github.com/yannbf))
|
|
87
|
+
- chore: add feature req and bug report templates ([@yannbf](https://github.com/yannbf))
|
|
88
|
+
- docs: fix inconsistencies in rule docs ([@yannbf](https://github.com/yannbf))
|
|
89
|
+
- Update no-title-property-in-meta.md ([@ghengeveld](https://github.com/ghengeveld))
|
|
90
|
+
- Update no-stories-of.md ([@ghengeveld](https://github.com/ghengeveld))
|
|
91
|
+
- Update default-exports.md ([@ghengeveld](https://github.com/ghengeveld))
|
|
92
|
+
- feat: add docs url to every rule ([@yannbf](https://github.com/yannbf))
|
|
93
|
+
- init project ([@yannbf](https://github.com/yannbf))
|
|
94
|
+
|
|
95
|
+
#### Authors: 4
|
|
96
|
+
|
|
97
|
+
- Gert Hengeveld ([@ghengeveld](https://github.com/ghengeveld))
|
|
98
|
+
- Kyle Gach ([@kylegach](https://github.com/kylegach))
|
|
99
|
+
- Michael Shilman ([@shilman](https://github.com/shilman))
|
|
100
|
+
- Yann Braga ([@yannbf](https://github.com/yannbf))
|
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
* @fileoverview Story files should have a default export
|
|
4
4
|
* @author Yann Braga
|
|
5
5
|
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
6
10
|
const constants_1 = require("../utils/constants");
|
|
7
11
|
const ast_1 = require("../utils/ast");
|
|
8
12
|
const create_storybook_rule_1 = require("../utils/create-storybook-rule");
|
|
@@ -18,7 +22,9 @@ module.exports = (0, create_storybook_rule_1.createStorybookRule)({
|
|
|
18
22
|
},
|
|
19
23
|
messages: {
|
|
20
24
|
shouldHaveDefaultExport: 'The file should have a default export.',
|
|
25
|
+
fixSuggestion: 'Add default export',
|
|
21
26
|
},
|
|
27
|
+
fixable: 'code',
|
|
22
28
|
schema: [],
|
|
23
29
|
},
|
|
24
30
|
create(context) {
|
|
@@ -27,6 +33,17 @@ module.exports = (0, create_storybook_rule_1.createStorybookRule)({
|
|
|
27
33
|
// Helpers
|
|
28
34
|
//----------------------------------------------------------------------
|
|
29
35
|
// any helper functions should go here or else delete this section
|
|
36
|
+
const getComponentName = (node, filePath) => {
|
|
37
|
+
const name = path_1.default.basename(filePath).split('.')[0];
|
|
38
|
+
const imported = node.body.find((stmt) => {
|
|
39
|
+
if ((0, ast_1.isImportDeclaration)(stmt) &&
|
|
40
|
+
(0, ast_1.isLiteral)(stmt.source) &&
|
|
41
|
+
stmt.source.value.startsWith(`./${name}`)) {
|
|
42
|
+
return !!stmt.specifiers.find((spec) => (0, ast_1.isIdentifier)(spec.local) && spec.local.name === name);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return imported ? name : null;
|
|
46
|
+
};
|
|
30
47
|
//----------------------------------------------------------------------
|
|
31
48
|
// Public
|
|
32
49
|
//----------------------------------------------------------------------
|
|
@@ -38,13 +55,27 @@ module.exports = (0, create_storybook_rule_1.createStorybookRule)({
|
|
|
38
55
|
ExportDefaultDeclaration: function () {
|
|
39
56
|
hasDefaultExport = true;
|
|
40
57
|
},
|
|
41
|
-
'Program:exit': function (
|
|
58
|
+
'Program:exit': function (program) {
|
|
42
59
|
if (!hasDefaultExport) {
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
60
|
+
const componentName = getComponentName(program, context.getFilename());
|
|
61
|
+
const firstNonImportStatement = program.body.find((n) => !(0, ast_1.isImportDeclaration)(n));
|
|
62
|
+
const node = firstNonImportStatement || program.body[0] || program;
|
|
63
|
+
const report = {
|
|
64
|
+
node,
|
|
46
65
|
messageId: 'shouldHaveDefaultExport',
|
|
47
|
-
}
|
|
66
|
+
};
|
|
67
|
+
if (!componentName) {
|
|
68
|
+
context.report(report);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const fix = (fixer) => fixer.insertTextBefore(node, `export default { component: ${componentName} }\n`);
|
|
72
|
+
context.report(Object.assign(Object.assign({}, report), { fix, suggest: [
|
|
73
|
+
{
|
|
74
|
+
messageId: 'fixSuggestion',
|
|
75
|
+
fix,
|
|
76
|
+
},
|
|
77
|
+
] }));
|
|
78
|
+
}
|
|
48
79
|
}
|
|
49
80
|
},
|
|
50
81
|
};
|
|
@@ -38,7 +38,7 @@ module.exports = (0, create_storybook_rule_1.createStorybookRule)({
|
|
|
38
38
|
}
|
|
39
39
|
//@ts-ignore
|
|
40
40
|
const metaTitle = titleNode.value.raw || '';
|
|
41
|
-
if (metaTitle.includes('|')
|
|
41
|
+
if (metaTitle.includes('|')) {
|
|
42
42
|
context.report({
|
|
43
43
|
node: titleNode,
|
|
44
44
|
messageId: 'deprecatedHierarchySeparator',
|
|
@@ -47,7 +47,7 @@ module.exports = (0, create_storybook_rule_1.createStorybookRule)({
|
|
|
47
47
|
fix: function (fixer) {
|
|
48
48
|
return fixer.replaceTextRange(
|
|
49
49
|
//@ts-ignore
|
|
50
|
-
titleNode.value.range, metaTitle.replace(
|
|
50
|
+
titleNode.value.range, metaTitle.replace(/\|/g, '/'));
|
|
51
51
|
},
|
|
52
52
|
suggest: [
|
|
53
53
|
{
|
|
@@ -55,7 +55,7 @@ module.exports = (0, create_storybook_rule_1.createStorybookRule)({
|
|
|
55
55
|
fix: function (fixer) {
|
|
56
56
|
return fixer.replaceTextRange(
|
|
57
57
|
//@ts-ignore
|
|
58
|
-
titleNode.value.range, metaTitle.replace(
|
|
58
|
+
titleNode.value.range, metaTitle.replace(/\|/g, '/'));
|
|
59
59
|
},
|
|
60
60
|
},
|
|
61
61
|
],
|
|
@@ -13,13 +13,12 @@ module.exports = (0, create_storybook_rule_1.createStorybookRule)({
|
|
|
13
13
|
type: 'problem',
|
|
14
14
|
fixable: 'code',
|
|
15
15
|
docs: {
|
|
16
|
-
// @TODO check about this, as this only works in Typescript if the title property is optional, likely part of 6.4 typings
|
|
17
16
|
description: 'Do not define a title in meta',
|
|
18
17
|
categories: [constants_1.CategoryId.CSF_STRICT],
|
|
19
18
|
recommended: 'error',
|
|
20
19
|
},
|
|
21
20
|
messages: {
|
|
22
|
-
removeTitleInMeta: '
|
|
21
|
+
removeTitleInMeta: 'Remove title property from meta',
|
|
23
22
|
noTitleInMeta: `CSF3 does not need a title in meta`,
|
|
24
23
|
},
|
|
25
24
|
schema: [],
|
|
@@ -34,21 +33,20 @@ module.exports = (0, create_storybook_rule_1.createStorybookRule)({
|
|
|
34
33
|
const titleNode = meta.properties.find((prop) => prop.key.name === 'title');
|
|
35
34
|
if (titleNode) {
|
|
36
35
|
context.report({
|
|
37
|
-
node,
|
|
36
|
+
node: titleNode,
|
|
38
37
|
messageId: 'noTitleInMeta',
|
|
39
|
-
// In case we want this to be auto fixed by --fix
|
|
40
|
-
// fix: function (fixer) {
|
|
41
|
-
// return fixer.remove(
|
|
42
|
-
// titleNode
|
|
43
|
-
// )
|
|
44
|
-
// },
|
|
45
38
|
suggest: [
|
|
46
39
|
{
|
|
47
40
|
messageId: 'removeTitleInMeta',
|
|
48
|
-
fix
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
41
|
+
fix(fixer) {
|
|
42
|
+
const fullText = context.getSourceCode().text;
|
|
43
|
+
const propertyTextWithExtraCharacter = fullText.slice(titleNode.range[0], titleNode.range[1] + 1);
|
|
44
|
+
const hasComma = propertyTextWithExtraCharacter.slice(-1) === ',';
|
|
45
|
+
const propertyRange = [
|
|
46
|
+
titleNode.range[0],
|
|
47
|
+
hasComma ? titleNode.range[1] + 1 : titleNode.range[1],
|
|
48
|
+
];
|
|
49
|
+
return fixer.removeRange(propertyRange);
|
|
52
50
|
},
|
|
53
51
|
},
|
|
54
52
|
],
|
|
@@ -50,7 +50,7 @@ module.exports = (0, create_storybook_rule_1.createStorybookRule)({
|
|
|
50
50
|
if (!(0, csf_1.isExportStory)(name, nonStoryExportsConfig) || name === '__namedExportsOrder') {
|
|
51
51
|
return null;
|
|
52
52
|
}
|
|
53
|
-
if (!isPascalCase(name)) {
|
|
53
|
+
if (!name.startsWith('_') && !isPascalCase(name)) {
|
|
54
54
|
context.report({
|
|
55
55
|
node: id,
|
|
56
56
|
messageId: 'usePascalCase',
|