Skip to content

Commit 7e6b510

Browse files
committed
Fix optional chaining for style attribute checks in ESLint rules
1 parent f7b9173 commit 7e6b510

File tree

4 files changed

+6
-2
lines changed

4 files changed

+6
-2
lines changed

eslint-plugin/lib/rules/avoid-css-animations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = {
3737
return {
3838
JSXOpeningElement(node) {
3939
const styleAttribute = node.attributes.find(
40-
(attribute) => attribute.name.name === "style",
40+
(attribute) => attribute.name?.name === "style",
4141
);
4242

4343
if (styleAttribute?.value.expression) {

eslint-plugin/lib/rules/prefer-shorthand-css-notations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ module.exports = {
8484
return {
8585
JSXOpeningElement(node) {
8686
const styleAttribute = node.attributes.find(
87-
(attr) => attr.name.name === "style",
87+
(attr) => attr.name?.name === "style",
8888
);
8989
if (styleAttribute) {
9090
const nodePropertyNames =

eslint-plugin/tests/lib/rules/avoid-css-animations.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ ruleTester.run("avoid-css-animations", rule, {
5353
`,
5454
`<div style={{ width: '100px', height: '100px' }}>Hello world</div>`,
5555
`<div style="border: 2px solid red">My red element</div>`,
56+
// spread attributes should not throw an error (#49)
57+
"<input {...inputProps} className={styles.input} onChange={handleChange}/>",
5658
],
5759

5860
invalid: [

eslint-plugin/tests/lib/rules/prefer-shorthand-css-notations.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ ruleTester.run("prefer-shorthand-css-notations", rule, {
7373
code: "<div style={{ animationName: 'example', animationDuration: '5s' }}/>",
7474
options: [{ disableProperties: ["animation"] }],
7575
},
76+
// spread attributes should not throw an error (#49)
77+
"<input {...inputProps} className={styles.input} onChange={handleChange}/>",
7678
],
7779
invalid: [
7880
{

0 commit comments

Comments
 (0)