Skip to content

Commit 05b9837

Browse files
committed
Adds optional chaining to getJSXOpeningElementAttribute to avoid error when no name is present
1 parent 974d9e8 commit 05b9837

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

.changeset/loud-bears-wave.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
'eslint-plugin-primer-react': patch
33
---
44

5-
Fixes `nonInteractiveLink` rule for links that pass values through JSX rather than a string.
5+
* Fixes `nonInteractiveLink` rule for links that pass values through JSX rather than a string
6+
* Adds optional chaining to `getJSXOpeningElementAttribute` to avoid error when no `name` is present

src/rules/__tests__/a11y-explicit-heading.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ ruleTester.run('a11y-explicit-heading', rule, {
3434
const args = {};
3535
<Heading as="h2" {...args}>Heading level 2</Heading>
3636
`,
37+
`
38+
import {Heading} from '@primer/react';
39+
<Heading
40+
{...someProps}
41+
as="h3"
42+
>
43+
Passed spread props
44+
</Heading>
45+
`
3746

3847
],
3948
invalid: [

src/utils/get-jsx-opening-element-attribute.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function getJSXOpeningElementAttribute(openingEl, name) {
22
const attributes = openingEl.attributes
33
const attribute = attributes.find(attribute => {
4-
return attribute.name.name === name
4+
return attribute.name?.name === name
55
})
66

77
return attribute

0 commit comments

Comments
 (0)