diff --git a/packages/eslint-plugin/changelogs/upcoming/9368.md b/packages/eslint-plugin/changelogs/upcoming/9368.md new file mode 100644 index 000000000000..aa3dd7dee6a7 --- /dev/null +++ b/packages/eslint-plugin/changelogs/upcoming/9368.md @@ -0,0 +1,3 @@ +**Bug fixes** + +- Fixed `no-css-color` ESLint rule crash when analyzing functions that return `undefined` or non-object values diff --git a/packages/eslint-plugin/src/rules/no_css_color.ts b/packages/eslint-plugin/src/rules/no_css_color.ts index 6be2f515381c..e47343734d6d 100644 --- a/packages/eslint-plugin/src/rules/no_css_color.ts +++ b/packages/eslint-plugin/src/rules/no_css_color.ts @@ -478,10 +478,20 @@ export const NoCssColor = ESLintUtils.RuleCreator.withoutDocs({ return; } + const returnArgument = ( + functionReturnStatementNode as TSESTree.ReturnStatement + ).argument; + + if ( + !returnArgument || + returnArgument.type !== 'ObjectExpression' + ) { + return; + } + declarationPropertiesNode = ( - (functionReturnStatementNode as TSESTree.ReturnStatement) - .argument as TSESTree.ObjectExpression - )?.properties.filter( + returnArgument as TSESTree.ObjectExpression + ).properties.filter( (property): property is TSESTree.Property => property.type === 'Property' ); diff --git a/packages/eui/.eslintrc.js b/packages/eui/.eslintrc.js index 130d9b577358..3f761f7b57fe 100644 --- a/packages/eui/.eslintrc.js +++ b/packages/eui/.eslintrc.js @@ -37,6 +37,7 @@ module.exports = { 'plugin:@typescript-eslint/recommended', 'plugin:deprecation/recommended', 'plugin:storybook/recommended', + 'plugin:@elastic/eui/recommended', // Prettier options need to come last, in order to override other style rules 'plugin:prettier/recommended', ], @@ -48,7 +49,8 @@ module.exports = { 'react', 'react-hooks', '@emotion', - 'deprecation' + 'deprecation', + '@elastic/eui' ], rules: { 'deprecation/deprecation': 'warn', diff --git a/packages/eui/package.json b/packages/eui/package.json index 3427548d4562..45023bc3f61a 100644 --- a/packages/eui/package.json +++ b/packages/eui/package.json @@ -107,6 +107,7 @@ "@cypress/webpack-dev-server": "^1.7.0", "@elastic/charts": "^64.1.0", "@elastic/datemath": "^5.0.3", + "@elastic/eslint-plugin-eui": "workspace:*", "@elastic/eui-theme-borealis": "workspace:*", "@emotion/babel-preset-css-prop": "^11.11.0", "@emotion/cache": "^11.11.0", diff --git a/yarn.lock b/yarn.lock index a26852ea9890..099a53e81e5f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7062,7 +7062,7 @@ __metadata: languageName: node linkType: hard -"@elastic/eslint-plugin-eui@workspace:packages/eslint-plugin": +"@elastic/eslint-plugin-eui@workspace:*, @elastic/eslint-plugin-eui@workspace:packages/eslint-plugin": version: 0.0.0-use.local resolution: "@elastic/eslint-plugin-eui@workspace:packages/eslint-plugin" dependencies: @@ -7345,6 +7345,7 @@ __metadata: "@cypress/webpack-dev-server": "npm:^1.7.0" "@elastic/charts": "npm:^64.1.0" "@elastic/datemath": "npm:^5.0.3" + "@elastic/eslint-plugin-eui": "workspace:*" "@elastic/eui-theme-borealis": "workspace:*" "@elastic/eui-theme-common": "workspace:*" "@elastic/prismjs-esql": "npm:^1.1.2"