Skip to content

Commit bfb98ce

Browse files
authored
Merge pull request #80 from aurmer/issue-78-key-undefined-error
fix: add optional chaining to object property key
2 parents 0669758 + 16c54d9 commit bfb98ce

7 files changed

Lines changed: 10 additions & 6 deletions

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ yarn update-all
6969

7070
### Useful resources
7171

72-
- The [ESLint official developer](https://eslint.org/docs/developer-guide/working-with-rules) can be useful to assist when writing rules
72+
- The [ESLint official developer guide](https://eslint.org/docs/developer-guide/working-with-rules) can be useful to assist when writing rules
7373
- The [AST Explorer](https://astexplorer.net/) website is the perfect place to get reference to writing rules. Given that ESLint rules are based in AST (Abstract Syntax Tree), you can paste an example code there and visualize all properties of the resulting AST of that code.
7474
- Storybook has a discord community! And we need more people like you. Please [join us](https://discord.gg/storybook) and say hi in the #contributors channel! 👋

lib/rules/csf-component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export = createStorybookRule({
4949
}
5050

5151
const componentProperty = meta.properties.find(
52-
(property: any) => property.key.name === 'component'
52+
(property: any) => property.key?.name === 'component'
5353
)
5454
if (!componentProperty) {
5555
context.report({

lib/rules/hierarchy-separator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export = createStorybookRule({
3939
return null
4040
}
4141

42-
const titleNode = meta.properties.find((prop: any) => prop.key.name === 'title')
42+
const titleNode = meta.properties.find((prop: any) => prop.key?.name === 'title')
4343

4444
//@ts-ignore
4545
if (!titleNode || !isLiteral(titleNode.value)) {

lib/rules/meta-inline-properties.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export = createStorybookRule({
7373

7474
const metaNodes = meta.properties.filter((prop: any) =>
7575
//@ts-ignore
76-
ruleProperties.includes(prop.key.name)
76+
ruleProperties.includes(prop.key?.name)
7777
)
7878

7979
metaNodes.forEach((metaNode: any) => {
@@ -89,7 +89,7 @@ export = createStorybookRule({
8989
node: propertyNode,
9090
messageId: 'metaShouldHaveInlineProperties',
9191
data: {
92-
property: propertyNode.key.name,
92+
property: propertyNode.key?.name,
9393
},
9494
})
9595
})

lib/rules/no-title-property-in-meta.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export = createStorybookRule({
3737
return null
3838
}
3939

40-
const titleNode = meta.properties.find((prop: any) => prop.key.name === 'title')
40+
const titleNode = meta.properties.find((prop: any) => prop.key?.name === 'title')
4141

4242
if (titleNode) {
4343
context.report({

tests/lib/rules/hierarchy-separator.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ import ruleTester from '../../utils/rule-tester'
1919

2020
ruleTester.run('hierarchy-separator', rule, {
2121
valid: [
22+
"export default { }",
2223
"export default { title: 'Examples.Components' }",
2324
"export default { title: 'Examples/Components/Button' }",
2425
"export default { title: 'Examples/Components/Button' } as ComponentMeta<typeof Button>",
26+
"export default { ...props } as ComponentMeta<typeof Button>",
2527
],
2628

2729
invalid: [

tests/lib/rules/no-title-property-in-meta.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ import ruleTester from '../../utils/rule-tester'
1919

2020
ruleTester.run('no-title-property-in-meta', rule, {
2121
valid: [
22+
"export default { }",
2223
'export default { component: Button }',
2324
'export default { component: Button } as ComponentMeta<typeof Button>',
25+
"export default { ...props }",
2426
],
2527

2628
invalid: [

0 commit comments

Comments
 (0)