Skip to content

Commit

Permalink
Fix optional chaining for style attribute checks in ESLint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
utarwyn committed Jan 19, 2025
1 parent f7b9173 commit af1eeb2
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#56](https://github.com/green-code-initiative/creedengo-javascript/issues/56) **BREAKING:** Rename plugin to creedengo-javascript
- [#44](https://github.com/green-code-initiative/creedengo-javascript/pull/44) Implement the rule GCI523 for React Native
- [#52](https://github.com/green-code-initiative/creedengo-javascript/pull/52) Remove trailing dots in Sonar rules descriptions
- [#62](https://github.com/green-code-initiative/creedengo-javascript/pull/62) Fix style attribute checks in GCI26 and GCI29
- Update Docker Compose configuration file to V2

### Deleted
Expand Down
2 changes: 1 addition & 1 deletion eslint-plugin/lib/rules/avoid-css-animations.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = {
return {
JSXOpeningElement(node) {
const styleAttribute = node.attributes.find(
(attribute) => attribute.name.name === "style",
(attribute) => attribute.name?.name === "style",
);

if (styleAttribute?.value.expression) {
Expand Down
2 changes: 1 addition & 1 deletion eslint-plugin/lib/rules/prefer-shorthand-css-notations.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ module.exports = {
return {
JSXOpeningElement(node) {
const styleAttribute = node.attributes.find(
(attr) => attr.name.name === "style",
(attr) => attr.name?.name === "style",
);
if (styleAttribute) {
const nodePropertyNames =
Expand Down
2 changes: 2 additions & 0 deletions eslint-plugin/tests/lib/rules/avoid-css-animations.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ ruleTester.run("avoid-css-animations", rule, {
`,
`<div style={{ width: '100px', height: '100px' }}>Hello world</div>`,
`<div style="border: 2px solid red">My red element</div>`,
// spread attributes should not throw an error (#49)
"<input {...inputProps} className={styles.input} onChange={handleChange}/>",
],

invalid: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ ruleTester.run("prefer-shorthand-css-notations", rule, {
code: "<div style={{ animationName: 'example', animationDuration: '5s' }}/>",
options: [{ disableProperties: ["animation"] }],
},
// spread attributes should not throw an error (#49)
"<input {...inputProps} className={styles.input} onChange={handleChange}/>",
],
invalid: [
{
Expand Down

0 comments on commit af1eeb2

Please sign in to comment.