mirror of
https://github.com/elastic/kibana.git
synced 2025-06-28 11:05:39 -04:00
## Summary This adds an additional custom ESLint rule package which checks certain Eui elements for the existence of an `aria-label` prop. If it exists, it will leave it untouched. If it doesn't, it will warn the engineer it needs to be added, and offers a autofix suggestion for those engineers who have fix on save enabled in their IDE. <img width="739" alt="Screenshot 2025-03-25 at 13 59 28" src="https://github.com/user-attachments/assets/0813b317-c752-40d7-b569-e866a3ecf6b0" /> <img width="804" alt="Screenshot 2025-03-25 at 13 59 36" src="https://github.com/user-attachments/assets/3c45c49c-6db8-4740-b5de-89aa534c248b" /> This package is an offshoot of the `kbn-eslint-plugin-i18n` and `kbn-eslint-plugin-telemetry` packages. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
/*
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
* or more contributor license agreements. Licensed under the "Elastic License
|
|
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
|
|
* Public License v 1"; you may not use this file except in compliance with, at
|
|
* your election, the "Elastic License 2.0", the "GNU Affero General Public
|
|
* License v3.0 only", or the "Server Side Public License, v 1".
|
|
*/
|
|
|
|
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/typescript-estree';
|
|
import { lowerCaseFirstChar } from './utils';
|
|
|
|
export function getFunctionName(func: TSESTree.FunctionDeclaration | TSESTree.Node): string {
|
|
if (
|
|
'id' in func &&
|
|
func.id &&
|
|
func.type === AST_NODE_TYPES.FunctionDeclaration &&
|
|
func.id.type === AST_NODE_TYPES.Identifier
|
|
) {
|
|
return lowerCaseFirstChar(func.id.name);
|
|
}
|
|
|
|
if (
|
|
func.parent &&
|
|
(func.parent.type !== AST_NODE_TYPES.VariableDeclarator ||
|
|
func.parent.id.type !== AST_NODE_TYPES.Identifier)
|
|
) {
|
|
return getFunctionName(func.parent);
|
|
}
|
|
|
|
if (func.parent?.id && 'name' in func.parent.id) {
|
|
return lowerCaseFirstChar(func.parent.id.name);
|
|
}
|
|
|
|
return '';
|
|
}
|