@elastic/eslint-plugin-eui 2.3.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +8 -0
  2. package/lib/cjs/index.js +8 -2
  3. package/lib/cjs/rules/a11y/callout_announce_on_mount.d.ts +3 -0
  4. package/lib/cjs/rules/a11y/callout_announce_on_mount.d.ts.map +1 -0
  5. package/lib/cjs/rules/a11y/callout_announce_on_mount.js +67 -0
  6. package/lib/cjs/rules/a11y/no_unnamed_interactive_element.d.ts +3 -0
  7. package/lib/cjs/rules/a11y/no_unnamed_interactive_element.d.ts.map +1 -0
  8. package/lib/cjs/rules/a11y/no_unnamed_interactive_element.js +89 -0
  9. package/lib/cjs/utils/get_allowed_a11y_prop_names_for_component.d.ts +24 -0
  10. package/lib/cjs/utils/get_allowed_a11y_prop_names_for_component.d.ts.map +1 -0
  11. package/lib/cjs/utils/get_allowed_a11y_prop_names_for_component.js +50 -0
  12. package/lib/cjs/utils/has_a11y_prop_for_component.d.ts +20 -0
  13. package/lib/cjs/utils/has_a11y_prop_for_component.d.ts.map +1 -0
  14. package/lib/cjs/utils/has_a11y_prop_for_component.js +47 -0
  15. package/lib/cjs/utils/has_spread.d.ts +12 -0
  16. package/lib/cjs/utils/has_spread.d.ts.map +1 -0
  17. package/lib/cjs/utils/has_spread.js +38 -0
  18. package/lib/cjs/utils/is_in_conditional_rendering.d.ts +3 -0
  19. package/lib/cjs/utils/is_in_conditional_rendering.d.ts.map +1 -0
  20. package/lib/cjs/utils/is_in_conditional_rendering.js +35 -0
  21. package/lib/esm/index.js +6 -0
  22. package/lib/esm/index.js.map +1 -1
  23. package/lib/esm/rules/a11y/callout_announce_on_mount.d.ts +2 -0
  24. package/lib/esm/rules/a11y/callout_announce_on_mount.js +76 -0
  25. package/lib/esm/rules/a11y/callout_announce_on_mount.js.map +1 -0
  26. package/lib/esm/rules/a11y/no_unnamed_interactive_element.d.ts +2 -0
  27. package/lib/esm/rules/a11y/no_unnamed_interactive_element.js +106 -0
  28. package/lib/esm/rules/a11y/no_unnamed_interactive_element.js.map +1 -0
  29. package/lib/esm/utils/get_allowed_a11y_prop_names_for_component.d.ts +23 -0
  30. package/lib/esm/utils/get_allowed_a11y_prop_names_for_component.js +45 -0
  31. package/lib/esm/utils/get_allowed_a11y_prop_names_for_component.js.map +1 -0
  32. package/lib/esm/utils/has_a11y_prop_for_component.d.ts +19 -0
  33. package/lib/esm/utils/has_a11y_prop_for_component.js +45 -0
  34. package/lib/esm/utils/has_a11y_prop_for_component.js.map +1 -0
  35. package/lib/esm/utils/has_spread.d.ts +11 -0
  36. package/lib/esm/utils/has_spread.js +34 -0
  37. package/lib/esm/utils/has_spread.js.map +1 -0
  38. package/lib/esm/utils/is_in_conditional_rendering.d.ts +2 -0
  39. package/lib/esm/utils/is_in_conditional_rendering.js +34 -0
  40. package/lib/esm/utils/is_in_conditional_rendering.js.map +1 -0
  41. package/package.json +1 -1
package/README.md CHANGED
@@ -147,6 +147,14 @@ Ensure `EuiIconTip` is used rather than `<EuiToolTip><EuiIcon/></EuiToolTip>`, a
147
147
 
148
148
  Ensure that all radio input components (`EuiRadio`, `EuiRadioGroup`) have a `name` attribute. The `name` attribute is required for radio inputs to be grouped correctly, allowing users to select only one option from a set. Without a `name`, radios may not behave as expected and can cause accessibility issues for assistive technologies.
149
149
 
150
+ ### `@elastic/eui/callout-announce-on-mount`
151
+
152
+ Ensures that `EuiCallOut` components rendered conditionally have the `announceOnMount` prop for better accessibility. When callouts appear dynamically (e.g., after user interactions, form validation errors, or status changes), screen readers may not announce their content to users. The `announceOnMount` prop ensures these messages are properly announced to users with assistive technologies.
153
+
154
+ ### `@elastic/eui/no-unnamed-interactive-element`
155
+
156
+ Ensure that appropriate aria-attributes are set for `EuiBetaBadge`, `EuiButtonIcon`, `EuiComboBox`, `EuiSelect`, `EuiSelectWithWidth`,`EuiSuperSelect`,`EuiPagination`, `EuiTreeView`, `EuiBreadcrumbs`. Without this rule, screen reader users lose context, keyboard navigation can be confusing.
157
+
150
158
  ## Testing
151
159
 
152
160
  ### Running unit tests
package/lib/cjs/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ var _callout_announce_on_mount = require("./rules/a11y/callout_announce_on_mount");
3
4
  var _href_or_on_click = require("./rules/href_or_on_click");
4
5
  var _no_restricted_eui_imports = require("./rules/no_restricted_eui_imports");
5
6
  var _no_css_color = require("./rules/no_css_color");
@@ -8,6 +9,7 @@ var _consistent_is_invalid_props = require("./rules/a11y/consistent_is_invalid_p
8
9
  var _sr_output_disabled_tooltip = require("./rules/a11y/sr_output_disabled_tooltip");
9
10
  var _prefer_eui_icon_tip = require("./rules/a11y/prefer_eui_icon_tip");
10
11
  var _no_unnamed_radio_group = require("./rules/a11y/no_unnamed_radio_group");
12
+ var _no_unnamed_interactive_element = require("./rules/a11y/no_unnamed_interactive_element");
11
13
  /*
12
14
  * Licensed to Elasticsearch B.V. under one or more contributor
13
15
  * license agreements. See the NOTICE file distributed with
@@ -36,7 +38,9 @@ const config = {
36
38
  'consistent-is-invalid-props': _consistent_is_invalid_props.ConsistentIsInvalidProps,
37
39
  'sr-output-disabled-tooltip': _sr_output_disabled_tooltip.ScreenReaderOutputDisabledTooltip,
38
40
  'prefer-eui-icon-tip': _prefer_eui_icon_tip.PreferEuiIconTip,
39
- 'no-unnamed-radio-group': _no_unnamed_radio_group.NoUnnamedRadioGroup
41
+ 'no-unnamed-radio-group': _no_unnamed_radio_group.NoUnnamedRadioGroup,
42
+ 'callout-announce-on-mount': _callout_announce_on_mount.CallOutAnnounceOnMount,
43
+ 'no-unnamed-interactive-element': _no_unnamed_interactive_element.NoUnnamedInteractiveElement
40
44
  },
41
45
  configs: {
42
46
  recommended: {
@@ -49,7 +53,9 @@ const config = {
49
53
  '@elastic/eui/consistent-is-invalid-props': 'warn',
50
54
  '@elastic/eui/sr-output-disabled-tooltip': 'warn',
51
55
  '@elastic/eui/prefer-eui-icon-tip': 'warn',
52
- '@elastic/eui/no-unnamed-radio-group': 'warn'
56
+ '@elastic/eui/no-unnamed-radio-group': 'warn',
57
+ '@elastic/eui/callout-announce-on-mount': 'warn',
58
+ '@elastic/eui/no-unnamed-interactive-element': 'warn'
53
59
  }
54
60
  }
55
61
  }
@@ -0,0 +1,3 @@
1
+ import { ESLintUtils } from '@typescript-eslint/utils';
2
+ export declare const CallOutAnnounceOnMount: ESLintUtils.RuleModule<"missingAnnounceOnMount", [], unknown, ESLintUtils.RuleListener>;
3
+ //# sourceMappingURL=callout_announce_on_mount.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callout_announce_on_mount.d.ts","sourceRoot":"","sources":["../../../../src/rules/a11y/callout_announce_on_mount.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAG,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAMxD,eAAO,MAAM,sBAAsB,yFAsDjC,CAAC"}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CallOutAnnounceOnMount = void 0;
7
+ var _utils = require("@typescript-eslint/utils");
8
+ var _is_in_conditional_rendering = require("../../utils/is_in_conditional_rendering");
9
+ var _has_spread = require("../../utils/has_spread");
10
+ /*
11
+ * Licensed to Elasticsearch B.V. under one or more contributor
12
+ * license agreements. See the NOTICE file distributed with
13
+ * this work for additional information regarding copyright
14
+ * ownership. Elasticsearch B.V. licenses this file to you under
15
+ * the Apache License, Version 2.0 (the "License"); you may
16
+ * not use this file except in compliance with the License.
17
+ * You may obtain a copy of the License at
18
+ *
19
+ * http://www.apache.org/licenses/LICENSE-2.0
20
+ *
21
+ * Unless required by applicable law or agreed to in writing,
22
+ * software distributed under the License is distributed on an
23
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
24
+ * KIND, either express or implied. See the License for the
25
+ * specific language governing permissions and limitations
26
+ * under the License.
27
+ */
28
+
29
+ const CALLOUT_COMPONENT = 'EuiCallOut';
30
+ const CallOutAnnounceOnMount = exports.CallOutAnnounceOnMount = _utils.ESLintUtils.RuleCreator.withoutDocs({
31
+ create(context) {
32
+ return {
33
+ JSXElement(node) {
34
+ const {
35
+ openingElement
36
+ } = node;
37
+ if (openingElement.name.type !== 'JSXIdentifier' || openingElement.name.name !== CALLOUT_COMPONENT) {
38
+ return;
39
+ }
40
+ if (openingElement.attributes.some(attr => attr.type === 'JSXAttribute' && attr.name.type === 'JSXIdentifier' && attr.name.name === 'announceOnMount')) {
41
+ return;
42
+ }
43
+ if ((0, _is_in_conditional_rendering.isInConditionalRendering)(node)) {
44
+ context.report({
45
+ node: openingElement,
46
+ messageId: 'missingAnnounceOnMount',
47
+ fix: (0, _has_spread.hasSpread)(openingElement.attributes) ? undefined : fixer => {
48
+ return fixer.insertTextAfterRange([openingElement.name.range[1], openingElement.name.range[1]], ' announceOnMount');
49
+ }
50
+ });
51
+ }
52
+ }
53
+ };
54
+ },
55
+ meta: {
56
+ type: 'problem',
57
+ docs: {
58
+ description: `Ensure ${CALLOUT_COMPONENT} components that are conditionally rendered have announceOnMount prop for better accessibility`
59
+ },
60
+ fixable: 'code',
61
+ schema: [],
62
+ messages: {
63
+ missingAnnounceOnMount: [`${CALLOUT_COMPONENT} should have \`announceOnMount\` prop when conditionally rendered for better accessibility.`, '\n', `When ${CALLOUT_COMPONENT} appears dynamically (e.g., after user interaction, form validation, etc.),`, 'screen readers may not announce its content. Adding `announceOnMount` ensures the callout', 'is properly announced to users with assistive technologies.', '\n', 'Example:', ` <${CALLOUT_COMPONENT} announceOnMount title="Error" color="danger">`, ' This message will be announced when it appears', ` </${CALLOUT_COMPONENT}>`].join('\n')
64
+ }
65
+ },
66
+ defaultOptions: []
67
+ });
@@ -0,0 +1,3 @@
1
+ import { ESLintUtils } from '@typescript-eslint/utils';
2
+ export declare const NoUnnamedInteractiveElement: ESLintUtils.RuleModule<"missingA11y", [], unknown, ESLintUtils.RuleListener>;
3
+ //# sourceMappingURL=no_unnamed_interactive_element.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no_unnamed_interactive_element.d.ts","sourceRoot":"","sources":["../../../../src/rules/a11y/no_unnamed_interactive_element.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,WAAW,EAAiB,MAAM,0BAA0B,CAAC;AAgCtE,eAAO,MAAM,2BAA2B,8EAyEtC,CAAC"}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.NoUnnamedInteractiveElement = void 0;
7
+ var _utils = require("@typescript-eslint/utils");
8
+ var _has_spread = require("../../utils/has_spread");
9
+ var _get_allowed_a11y_prop_names_for_component = require("../../utils/get_allowed_a11y_prop_names_for_component");
10
+ var _has_a11y_prop_for_component = require("../../utils/has_a11y_prop_for_component");
11
+ /*
12
+ * Licensed to Elasticsearch B.V. under one or more contributor
13
+ * license agreements. See the NOTICE file distributed with
14
+ * this work for additional information regarding copyright
15
+ * ownership. Elasticsearch B.V. licenses this file to you under
16
+ * the Apache License, Version 2.0 (the "License"); you may
17
+ * not use this file except in compliance with the License.
18
+ * You may obtain a copy of the License at
19
+ *
20
+ * http://www.apache.org/licenses/LICENSE-2.0
21
+ *
22
+ * Unless required by applicable law or agreed to in writing,
23
+ * software distributed under the License is distributed on an
24
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
25
+ * KIND, either express or implied. See the License for the
26
+ * specific language governing permissions and limitations
27
+ * under the License.
28
+ */
29
+
30
+ const interactiveComponents = ['EuiBetaBadge', 'EuiButtonEmpty', 'EuiButtonIcon', 'EuiComboBox', 'EuiSelect', 'EuiSelectWithWidth', 'EuiSuperSelect', 'EuiPagination', 'EuiTreeView', 'EuiBreadcrumbs'];
31
+ const wrappingComponents = ['EuiFormRow'];
32
+ const interactiveComponentsWithLabel = ['EuiBetaBadge'];
33
+ const baseA11yProps = ['aria-label', 'aria-labelledby'];
34
+
35
+ // Single source of truth for the utils (keeps them reusable)
36
+ const a11yConfig = {
37
+ interactiveComponentsWithLabel: [...interactiveComponentsWithLabel],
38
+ wrappingComponents: [...wrappingComponents],
39
+ baseA11yProps: [...baseA11yProps]
40
+ };
41
+ const NoUnnamedInteractiveElement = exports.NoUnnamedInteractiveElement = _utils.ESLintUtils.RuleCreator.withoutDocs({
42
+ meta: {
43
+ type: 'problem',
44
+ hasSuggestions: false,
45
+ schema: [],
46
+ messages: {
47
+ missingA11y: '{{component}} must include an accessible label. Use one of: {{a11yProps}}'
48
+ }
49
+ },
50
+ defaultOptions: [],
51
+ create(context) {
52
+ const sourceCode = context.sourceCode;
53
+ function report(opening) {
54
+ if (opening.name.type !== 'JSXIdentifier') return;
55
+ const component = opening.name.name;
56
+ const allowed = (0, _get_allowed_a11y_prop_names_for_component.getAllowedA11yPropNamesForComponent)(component, a11yConfig).join(', ');
57
+ context.report({
58
+ node: opening,
59
+ messageId: 'missingA11y',
60
+ data: {
61
+ component,
62
+ a11yProps: allowed
63
+ }
64
+ });
65
+ }
66
+ return {
67
+ JSXOpeningElement(node) {
68
+ if (node.name.type !== 'JSXIdentifier') return;
69
+ const componentName = node.name.name;
70
+ const isInteractive = interactiveComponents.includes(componentName);
71
+ if (!isInteractive) return;
72
+ if ((0, _has_spread.hasSpread)(node.attributes) || (0, _has_a11y_prop_for_component.hasA11yPropForComponent)(componentName, node.attributes, a11yConfig)) {
73
+ return;
74
+ }
75
+ const ancestors = sourceCode.getAncestors(node);
76
+ const wrapper = [...ancestors].reverse().find(a => a.type === 'JSXElement' && a.openingElement.name.type === 'JSXIdentifier' && wrappingComponents.includes(a.openingElement.name.name));
77
+ if (wrapper) {
78
+ const open = wrapper.openingElement;
79
+ const wrapperName = open.name.type === 'JSXIdentifier' ? open.name.name : '';
80
+ if (!(0, _has_spread.hasSpread)(open.attributes) && !(0, _has_a11y_prop_for_component.hasA11yPropForComponent)(wrapperName, open.attributes, a11yConfig)) {
81
+ report(open);
82
+ }
83
+ } else {
84
+ report(node);
85
+ }
86
+ }
87
+ };
88
+ }
89
+ });
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Configuration describing which components accept a `label` prop
3
+ * and the baseline set of accessibility prop names allowed across components.
4
+ */
5
+ export type A11yConfig = {
6
+ interactiveComponentsWithLabel: ReadonlyArray<string>;
7
+ wrappingComponents: ReadonlyArray<string>;
8
+ baseA11yProps: ReadonlyArray<string>;
9
+ };
10
+ /**
11
+ * Compute the set of allowed accessibility prop names for a given component.
12
+ *
13
+ * - Always includes the provided `baseA11yProps`.
14
+ * - Conditionally includes `label` if the component is listed in either
15
+ * `interactiveComponentsWithLabel` or `wrappingComponents`.
16
+ * - Does **not** mutate the provided configuration; a new array is returned.
17
+ *
18
+ * @param componentName - The EUI component name (e.g., `'EuiButtonIcon'`).
19
+ * @param cfg - The accessibility configuration to use when resolving allowed props.
20
+ * @returns A new array of allowed prop names for `componentName`.
21
+ *
22
+ */
23
+ export declare function getAllowedA11yPropNamesForComponent(componentName: string, cfg: A11yConfig): string[];
24
+ //# sourceMappingURL=get_allowed_a11y_prop_names_for_component.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get_allowed_a11y_prop_names_for_component.d.ts","sourceRoot":"","sources":["../../../src/utils/get_allowed_a11y_prop_names_for_component.ts"],"names":[],"mappings":"AAmBA;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,8BAA8B,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACtD,kBAAkB,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC1C,aAAa,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CACtC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,mCAAmC,CACjD,aAAa,EAAE,MAAM,EACrB,GAAG,EAAE,UAAU,GACd,MAAM,EAAE,CAUV"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getAllowedA11yPropNamesForComponent = getAllowedA11yPropNamesForComponent;
7
+ /*
8
+ * Licensed to Elasticsearch B.V. under one or more contributor
9
+ * license agreements. See the NOTICE file distributed with
10
+ * this work for additional information regarding copyright
11
+ * ownership. Elasticsearch B.V. licenses this file to you under
12
+ * the Apache License, Version 2.0 (the "License"); you may
13
+ * not use this file except in compliance with the License.
14
+ * You may obtain a copy of the License at
15
+ *
16
+ * http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing,
19
+ * software distributed under the License is distributed on an
20
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21
+ * KIND, either express or implied. See the License for the
22
+ * specific language governing permissions and limitations
23
+ * under the License.
24
+ */
25
+
26
+ /**
27
+ * Configuration describing which components accept a `label` prop
28
+ * and the baseline set of accessibility prop names allowed across components.
29
+ */
30
+
31
+ /**
32
+ * Compute the set of allowed accessibility prop names for a given component.
33
+ *
34
+ * - Always includes the provided `baseA11yProps`.
35
+ * - Conditionally includes `label` if the component is listed in either
36
+ * `interactiveComponentsWithLabel` or `wrappingComponents`.
37
+ * - Does **not** mutate the provided configuration; a new array is returned.
38
+ *
39
+ * @param componentName - The EUI component name (e.g., `'EuiButtonIcon'`).
40
+ * @param cfg - The accessibility configuration to use when resolving allowed props.
41
+ * @returns A new array of allowed prop names for `componentName`.
42
+ *
43
+ */
44
+ function getAllowedA11yPropNamesForComponent(componentName, cfg) {
45
+ const componentsWithLabel = new Set([...cfg.interactiveComponentsWithLabel, ...cfg.wrappingComponents]);
46
+ if (componentsWithLabel.has(componentName)) {
47
+ return [...cfg.baseA11yProps, 'label'];
48
+ }
49
+ return [...cfg.baseA11yProps];
50
+ }
@@ -0,0 +1,20 @@
1
+ import type { TSESTree } from '@typescript-eslint/utils';
2
+ import { type A11yConfig } from './get_allowed_a11y_prop_names_for_component';
3
+ /**
4
+ * Determines whether a JSX element declares at least one **allowed**
5
+ * accessibility-related prop for a given component.
6
+ *
7
+ * Allowed prop names are resolved via {@link getAllowedA11yPropNamesForComponent},
8
+ * which combines baseline a11y props (e.g. `aria-*`) and conditionally adds
9
+ * `label` for components that support it per the provided configuration.
10
+ *
11
+ * Only plain `JSXAttribute` nodes are considered—spread attributes are ignored here.
12
+ *
13
+ * @param componentName - The component name being checked (e.g., `"EuiButtonIcon"`).
14
+ * @param attrs - The attributes array from a `JSXOpeningElement` (ESTree).
15
+ * @param cfg - Accessibility configuration that defines base props and which
16
+ * components may accept a `label` prop.
17
+ * @returns `true` if any attribute name on the element is in the allowed set; otherwise `false`.
18
+ */
19
+ export declare function hasA11yPropForComponent(componentName: string, attrs: TSESTree.JSXOpeningElement['attributes'], cfg: A11yConfig): boolean;
20
+ //# sourceMappingURL=has_a11y_prop_for_component.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has_a11y_prop_for_component.d.ts","sourceRoot":"","sources":["../../../src/utils/has_a11y_prop_for_component.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAEL,KAAK,UAAU,EAChB,MAAM,6CAA6C,CAAC;AAErD;;;;;;;;;;;;;;;GAeG;AAEH,wBAAgB,uBAAuB,CACrC,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,QAAQ,CAAC,iBAAiB,CAAC,YAAY,CAAC,EAC/C,GAAG,EAAE,UAAU,GACd,OAAO,CAUT"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.hasA11yPropForComponent = hasA11yPropForComponent;
7
+ var _get_allowed_a11y_prop_names_for_component = require("./get_allowed_a11y_prop_names_for_component");
8
+ /*
9
+ * Licensed to Elasticsearch B.V. under one or more contributor
10
+ * license agreements. See the NOTICE file distributed with
11
+ * this work for additional information regarding copyright
12
+ * ownership. Elasticsearch B.V. licenses this file to you under
13
+ * the Apache License, Version 2.0 (the "License"); you may
14
+ * not use this file except in compliance with the License.
15
+ * You may obtain a copy of the License at
16
+ *
17
+ * http://www.apache.org/licenses/LICENSE-2.0
18
+ *
19
+ * Unless required by applicable law or agreed to in writing,
20
+ * software distributed under the License is distributed on an
21
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
22
+ * KIND, either express or implied. See the License for the
23
+ * specific language governing permissions and limitations
24
+ * under the License.
25
+ */
26
+
27
+ /**
28
+ * Determines whether a JSX element declares at least one **allowed**
29
+ * accessibility-related prop for a given component.
30
+ *
31
+ * Allowed prop names are resolved via {@link getAllowedA11yPropNamesForComponent},
32
+ * which combines baseline a11y props (e.g. `aria-*`) and conditionally adds
33
+ * `label` for components that support it per the provided configuration.
34
+ *
35
+ * Only plain `JSXAttribute` nodes are considered—spread attributes are ignored here.
36
+ *
37
+ * @param componentName - The component name being checked (e.g., `"EuiButtonIcon"`).
38
+ * @param attrs - The attributes array from a `JSXOpeningElement` (ESTree).
39
+ * @param cfg - Accessibility configuration that defines base props and which
40
+ * components may accept a `label` prop.
41
+ * @returns `true` if any attribute name on the element is in the allowed set; otherwise `false`.
42
+ */
43
+
44
+ function hasA11yPropForComponent(componentName, attrs, cfg) {
45
+ const allowed = new Set((0, _get_allowed_a11y_prop_names_for_component.getAllowedA11yPropNamesForComponent)(componentName, cfg));
46
+ return attrs.some(attr => attr.type === 'JSXAttribute' && attr.name.type === 'JSXIdentifier' && allowed.has(attr.name.name));
47
+ }
@@ -0,0 +1,12 @@
1
+ import type { TSESTree } from '@typescript-eslint/utils';
2
+ /**
3
+ * Checks whether a JSX opening element contains a spread attribute
4
+ * (e.g., `...props`). Spreads make it impossible to statically know
5
+ * all props present on an element, so ESLint rules often use this as
6
+ * a quick bail-out to avoid false positives.
7
+ *
8
+ * @param attrs - The attributes array from a `JSXOpeningElement` node (ESTree).
9
+ * @returns `true` if any attribute is a `JSXSpreadAttribute`; otherwise `false`.
10
+ */
11
+ export declare function hasSpread(attrs: TSESTree.JSXOpeningElement['attributes']): boolean;
12
+ //# sourceMappingURL=has_spread.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has_spread.d.ts","sourceRoot":"","sources":["../../../src/utils/has_spread.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEzD;;;;;;;;GAQG;AAEH,wBAAgB,SAAS,CACvB,KAAK,EAAE,QAAQ,CAAC,iBAAiB,CAAC,YAAY,CAAC,GAC9C,OAAO,CAET"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.hasSpread = hasSpread;
7
+ /*
8
+ * Licensed to Elasticsearch B.V. under one or more contributor
9
+ * license agreements. See the NOTICE file distributed with
10
+ * this work for additional information regarding copyright
11
+ * ownership. Elasticsearch B.V. licenses this file to you under
12
+ * the Apache License, Version 2.0 (the "License"); you may
13
+ * not use this file except in compliance with the License.
14
+ * You may obtain a copy of the License at
15
+ *
16
+ * http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing,
19
+ * software distributed under the License is distributed on an
20
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21
+ * KIND, either express or implied. See the License for the
22
+ * specific language governing permissions and limitations
23
+ * under the License.
24
+ */
25
+
26
+ /**
27
+ * Checks whether a JSX opening element contains a spread attribute
28
+ * (e.g., `...props`). Spreads make it impossible to statically know
29
+ * all props present on an element, so ESLint rules often use this as
30
+ * a quick bail-out to avoid false positives.
31
+ *
32
+ * @param attrs - The attributes array from a `JSXOpeningElement` node (ESTree).
33
+ * @returns `true` if any attribute is a `JSXSpreadAttribute`; otherwise `false`.
34
+ */
35
+
36
+ function hasSpread(attrs) {
37
+ return attrs.some(a => a.type === 'JSXSpreadAttribute');
38
+ }
@@ -0,0 +1,3 @@
1
+ import { TSESTree } from '@typescript-eslint/utils';
2
+ export declare function isInConditionalRendering(node: TSESTree.JSXElement): boolean;
3
+ //# sourceMappingURL=is_in_conditional_rendering.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is_in_conditional_rendering.d.ts","sourceRoot":"","sources":["../../../src/utils/is_in_conditional_rendering.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,QAAQ,CAAC,UAAU,GAAG,OAAO,CAW3E"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isInConditionalRendering = isInConditionalRendering;
7
+ /*
8
+ * Licensed to Elasticsearch B.V. under one or more contributor
9
+ * license agreements. See the NOTICE file distributed with
10
+ * this work for additional information regarding copyright
11
+ * ownership. Elasticsearch B.V. licenses this file to you under
12
+ * the Apache License, Version 2.0 (the "License"); you may
13
+ * not use this file except in compliance with the License.
14
+ * You may obtain a copy of the License at
15
+ *
16
+ * http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing,
19
+ * software distributed under the License is distributed on an
20
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21
+ * KIND, either express or implied. See the License for the
22
+ * specific language governing permissions and limitations
23
+ * under the License.
24
+ */
25
+
26
+ function isInConditionalRendering(node) {
27
+ let parent = node.parent;
28
+ while (parent) {
29
+ if (parent.type === 'ConditionalExpression' || parent.type === 'IfStatement' || parent.type === 'LogicalExpression' && parent.operator === '&&') {
30
+ return true;
31
+ }
32
+ parent = parent.parent;
33
+ }
34
+ return false;
35
+ }
package/lib/esm/index.js CHANGED
@@ -18,6 +18,7 @@
18
18
  * under the License.
19
19
  */
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
+ const callout_announce_on_mount_1 = require("./rules/a11y/callout_announce_on_mount");
21
22
  const href_or_on_click_1 = require("./rules/href_or_on_click");
22
23
  const no_restricted_eui_imports_1 = require("./rules/no_restricted_eui_imports");
23
24
  const no_css_color_1 = require("./rules/no_css_color");
@@ -26,6 +27,7 @@ const consistent_is_invalid_props_1 = require("./rules/a11y/consistent_is_invali
26
27
  const sr_output_disabled_tooltip_1 = require("./rules/a11y/sr_output_disabled_tooltip");
27
28
  const prefer_eui_icon_tip_1 = require("./rules/a11y/prefer_eui_icon_tip");
28
29
  const no_unnamed_radio_group_1 = require("./rules/a11y/no_unnamed_radio_group");
30
+ const no_unnamed_interactive_element_1 = require("./rules/a11y/no_unnamed_interactive_element");
29
31
  const config = {
30
32
  rules: {
31
33
  'href-or-on-click': href_or_on_click_1.HrefOnClick,
@@ -36,6 +38,8 @@ const config = {
36
38
  'sr-output-disabled-tooltip': sr_output_disabled_tooltip_1.ScreenReaderOutputDisabledTooltip,
37
39
  'prefer-eui-icon-tip': prefer_eui_icon_tip_1.PreferEuiIconTip,
38
40
  'no-unnamed-radio-group': no_unnamed_radio_group_1.NoUnnamedRadioGroup,
41
+ 'callout-announce-on-mount': callout_announce_on_mount_1.CallOutAnnounceOnMount,
42
+ 'no-unnamed-interactive-element': no_unnamed_interactive_element_1.NoUnnamedInteractiveElement,
39
43
  },
40
44
  configs: {
41
45
  recommended: {
@@ -49,6 +53,8 @@ const config = {
49
53
  '@elastic/eui/sr-output-disabled-tooltip': 'warn',
50
54
  '@elastic/eui/prefer-eui-icon-tip': 'warn',
51
55
  '@elastic/eui/no-unnamed-radio-group': 'warn',
56
+ '@elastic/eui/callout-announce-on-mount': 'warn',
57
+ '@elastic/eui/no-unnamed-interactive-element': 'warn',
52
58
  },
53
59
  },
54
60
  },
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;AAEH,+DAAuD;AACvD,iFAA2E;AAC3E,uDAAkD;AAElD,8FAAuF;AACvF,0FAAoF;AACpF,wFAA4F;AAC5F,0EAAoE;AACpE,gFAA0E;AAE1E,MAAM,MAAM,GAAG;IACb,KAAK,EAAE;QACL,kBAAkB,EAAE,8BAAW;QAC/B,2BAA2B,EAAE,kDAAsB;QACnD,cAAc,EAAE,yBAAU;QAC1B,+BAA+B,EAAE,yDAAyB;QAC1D,6BAA6B,EAAE,sDAAwB;QACvD,4BAA4B,EAAE,8DAAiC;QAC/D,qBAAqB,EAAE,sCAAgB;QACvC,wBAAwB,EAAG,4CAAmB;KAC/C;IACD,OAAO,EAAE;QACP,WAAW,EAAE;YACX,OAAO,EAAE,CAAC,4BAA4B,CAAC;YACvC,KAAK,EAAE;gBACL,+BAA+B,EAAE,MAAM;gBACvC,wCAAwC,EAAE,MAAM;gBAChD,2BAA2B,EAAE,MAAM;gBACnC,4CAA4C,EAAE,MAAM;gBACpD,0CAA0C,EAAE,MAAM;gBAClD,yCAAyC,EAAE,MAAM;gBACjD,kCAAkC,EAAE,MAAM;gBAC1C,qCAAqC,EAAE,MAAM;aAC9C;SACF;KACF;CACF,CAAC;AAEF,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;AAEH,sFAAgF;AAChF,+DAAuD;AACvD,iFAA2E;AAC3E,uDAAkD;AAElD,8FAAuF;AACvF,0FAAoF;AACpF,wFAA4F;AAC5F,0EAAoE;AACpE,gFAA0E;AAC1E,gGAA0F;AAG1F,MAAM,MAAM,GAAG;IACb,KAAK,EAAE;QACL,kBAAkB,EAAE,8BAAW;QAC/B,2BAA2B,EAAE,kDAAsB;QACnD,cAAc,EAAE,yBAAU;QAC1B,+BAA+B,EAAE,yDAAyB;QAC1D,6BAA6B,EAAE,sDAAwB;QACvD,4BAA4B,EAAE,8DAAiC;QAC/D,qBAAqB,EAAE,sCAAgB;QACvC,wBAAwB,EAAG,4CAAmB;QAC9C,2BAA2B,EAAE,kDAAsB;QACnD,gCAAgC,EAAE,4DAA2B;KAC9D;IACD,OAAO,EAAE;QACP,WAAW,EAAE;YACX,OAAO,EAAE,CAAC,4BAA4B,CAAC;YACvC,KAAK,EAAE;gBACL,+BAA+B,EAAE,MAAM;gBACvC,wCAAwC,EAAE,MAAM;gBAChD,2BAA2B,EAAE,MAAM;gBACnC,4CAA4C,EAAE,MAAM;gBACpD,0CAA0C,EAAE,MAAM;gBAClD,yCAAyC,EAAE,MAAM;gBACjD,kCAAkC,EAAE,MAAM;gBAC1C,qCAAqC,EAAE,MAAM;gBAC7C,wCAAwC,EAAE,MAAM;gBAChD,6CAA6C,EAAE,MAAM;aACtD;SACF;KACF;CACF,CAAC;AAEF,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { ESLintUtils } from '@typescript-eslint/utils';
2
+ export declare const CallOutAnnounceOnMount: ESLintUtils.RuleModule<"missingAnnounceOnMount", [], unknown, ESLintUtils.RuleListener>;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ /*
3
+ * Licensed to Elasticsearch B.V. under one or more contributor
4
+ * license agreements. See the NOTICE file distributed with
5
+ * this work for additional information regarding copyright
6
+ * ownership. Elasticsearch B.V. licenses this file to you under
7
+ * the Apache License, Version 2.0 (the "License"); you may
8
+ * not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing,
14
+ * software distributed under the License is distributed on an
15
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ * KIND, either express or implied. See the License for the
17
+ * specific language governing permissions and limitations
18
+ * under the License.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.CallOutAnnounceOnMount = void 0;
22
+ const utils_1 = require("@typescript-eslint/utils");
23
+ const is_in_conditional_rendering_1 = require("../../utils/is_in_conditional_rendering");
24
+ const has_spread_1 = require("../../utils/has_spread");
25
+ const CALLOUT_COMPONENT = 'EuiCallOut';
26
+ exports.CallOutAnnounceOnMount = utils_1.ESLintUtils.RuleCreator.withoutDocs({
27
+ create(context) {
28
+ return {
29
+ JSXElement(node) {
30
+ const { openingElement } = node;
31
+ if (openingElement.name.type !== 'JSXIdentifier' ||
32
+ openingElement.name.name !== CALLOUT_COMPONENT) {
33
+ return;
34
+ }
35
+ if (openingElement.attributes.some(attr => attr.type === 'JSXAttribute' &&
36
+ attr.name.type === 'JSXIdentifier' &&
37
+ attr.name.name === 'announceOnMount')) {
38
+ return;
39
+ }
40
+ if ((0, is_in_conditional_rendering_1.isInConditionalRendering)(node)) {
41
+ context.report({
42
+ node: openingElement,
43
+ messageId: 'missingAnnounceOnMount',
44
+ fix: (0, has_spread_1.hasSpread)(openingElement.attributes) ? undefined : (fixer) => {
45
+ return fixer.insertTextAfterRange([openingElement.name.range[1], openingElement.name.range[1]], ' announceOnMount');
46
+ },
47
+ });
48
+ }
49
+ },
50
+ };
51
+ },
52
+ meta: {
53
+ type: 'problem',
54
+ docs: {
55
+ description: `Ensure ${CALLOUT_COMPONENT} components that are conditionally rendered have announceOnMount prop for better accessibility`
56
+ },
57
+ fixable: 'code',
58
+ schema: [],
59
+ messages: {
60
+ missingAnnounceOnMount: [
61
+ `${CALLOUT_COMPONENT} should have \`announceOnMount\` prop when conditionally rendered for better accessibility.`,
62
+ '\n',
63
+ `When ${CALLOUT_COMPONENT} appears dynamically (e.g., after user interaction, form validation, etc.),`,
64
+ 'screen readers may not announce its content. Adding `announceOnMount` ensures the callout',
65
+ 'is properly announced to users with assistive technologies.',
66
+ '\n',
67
+ 'Example:',
68
+ ` <${CALLOUT_COMPONENT} announceOnMount title="Error" color="danger">`,
69
+ ' This message will be announced when it appears',
70
+ ` </${CALLOUT_COMPONENT}>`,
71
+ ].join('\n'),
72
+ },
73
+ },
74
+ defaultOptions: [],
75
+ });
76
+ //# sourceMappingURL=callout_announce_on_mount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callout_announce_on_mount.js","sourceRoot":"","sources":["../../../../src/rules/a11y/callout_announce_on_mount.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAEH,oDAAwD;AACxD,yFAAmF;AACnF,uDAAmD;AAEnD,MAAM,iBAAiB,GAAG,YAAY,CAAC;AAE1B,QAAA,sBAAsB,GAAG,mBAAW,CAAC,WAAW,CAAC,WAAW,CAAC;IACxE,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,UAAU,CAAC,IAAI;gBACb,MAAM,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;gBAChC,IAAI,cAAc,CAAC,IAAI,CAAC,IAAI,KAAK,eAAe;oBAC5C,cAAc,CAAC,IAAI,CAAC,IAAI,KAAK,iBAAiB,EAAE,CAAC;oBACnD,OAAO;gBACT,CAAC;gBACD,IAAI,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACxC,IAAI,CAAC,IAAI,KAAK,cAAc;oBAC5B,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,eAAe;oBAClC,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,iBAAiB,CACrC,EAAE,CAAC;oBACF,OAAO;gBACT,CAAC;gBACD,IAAI,IAAA,sDAAwB,EAAC,IAAI,CAAC,EAAE,CAAC;oBACnC,OAAO,CAAC,MAAM,CAAC;wBACb,IAAI,EAAE,cAAc;wBACpB,SAAS,EAAE,wBAAwB;wBACnC,GAAG,EAAE,IAAA,sBAAS,EAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE;4BAChE,OAAO,KAAK,CAAC,oBAAoB,CAC/B,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAC5D,kBAAkB,CACnB,CAAC;wBACJ,CAAC;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,UAAU,iBAAiB,gGAAgG;SACzI;QACD,OAAO,EAAE,MAAM;QACf,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,sBAAsB,EAAE;gBACtB,GAAG,iBAAiB,6FAA6F;gBACjH,IAAI;gBACJ,QAAQ,iBAAiB,6EAA6E;gBACtG,2FAA2F;gBAC3F,6DAA6D;gBAC7D,IAAI;gBACJ,UAAU;gBACV,MAAM,iBAAiB,gDAAgD;gBACvE,oDAAoD;gBACpD,OAAO,iBAAiB,GAAG;aAC5B,CAAC,IAAI,CAAC,IAAI,CAAC;SACb;KACF;IACD,cAAc,EAAE,EAAE;CACnB,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { ESLintUtils } from '@typescript-eslint/utils';
2
+ export declare const NoUnnamedInteractiveElement: ESLintUtils.RuleModule<"missingA11y", [], unknown, ESLintUtils.RuleListener>;
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ /*
3
+ * Licensed to Elasticsearch B.V. under one or more contributor
4
+ * license agreements. See the NOTICE file distributed with
5
+ * this work for additional information regarding copyright
6
+ * ownership. Elasticsearch B.V. licenses this file to you under
7
+ * the Apache License, Version 2.0 (the "License"); you may
8
+ * not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing,
14
+ * software distributed under the License is distributed on an
15
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ * KIND, either express or implied. See the License for the
17
+ * specific language governing permissions and limitations
18
+ * under the License.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.NoUnnamedInteractiveElement = void 0;
22
+ const utils_1 = require("@typescript-eslint/utils");
23
+ const has_spread_1 = require("../../utils/has_spread");
24
+ const get_allowed_a11y_prop_names_for_component_1 = require("../../utils/get_allowed_a11y_prop_names_for_component");
25
+ const has_a11y_prop_for_component_1 = require("../../utils/has_a11y_prop_for_component");
26
+ const interactiveComponents = [
27
+ 'EuiBetaBadge',
28
+ 'EuiButtonEmpty',
29
+ 'EuiButtonIcon',
30
+ 'EuiComboBox',
31
+ 'EuiSelect',
32
+ 'EuiSelectWithWidth',
33
+ 'EuiSuperSelect',
34
+ 'EuiPagination',
35
+ 'EuiTreeView',
36
+ 'EuiBreadcrumbs',
37
+ ];
38
+ const wrappingComponents = ['EuiFormRow'];
39
+ const interactiveComponentsWithLabel = ['EuiBetaBadge'];
40
+ const baseA11yProps = ['aria-label', 'aria-labelledby'];
41
+ // Single source of truth for the utils (keeps them reusable)
42
+ const a11yConfig = {
43
+ interactiveComponentsWithLabel: [...interactiveComponentsWithLabel],
44
+ wrappingComponents: [...wrappingComponents],
45
+ baseA11yProps: [...baseA11yProps],
46
+ };
47
+ exports.NoUnnamedInteractiveElement = utils_1.ESLintUtils.RuleCreator.withoutDocs({
48
+ meta: {
49
+ type: 'problem',
50
+ hasSuggestions: false,
51
+ schema: [],
52
+ messages: {
53
+ missingA11y: '{{component}} must include an accessible label. Use one of: {{a11yProps}}',
54
+ },
55
+ },
56
+ defaultOptions: [],
57
+ create(context) {
58
+ const sourceCode = context.sourceCode;
59
+ function report(opening) {
60
+ if (opening.name.type !== 'JSXIdentifier')
61
+ return;
62
+ const component = opening.name.name;
63
+ const allowed = (0, get_allowed_a11y_prop_names_for_component_1.getAllowedA11yPropNamesForComponent)(component, a11yConfig).join(', ');
64
+ context.report({
65
+ node: opening,
66
+ messageId: 'missingA11y',
67
+ data: {
68
+ component,
69
+ a11yProps: allowed,
70
+ },
71
+ });
72
+ }
73
+ return {
74
+ JSXOpeningElement(node) {
75
+ if (node.name.type !== 'JSXIdentifier')
76
+ return;
77
+ const componentName = node.name.name;
78
+ const isInteractive = interactiveComponents.includes(componentName);
79
+ if (!isInteractive)
80
+ return;
81
+ if ((0, has_spread_1.hasSpread)(node.attributes) ||
82
+ (0, has_a11y_prop_for_component_1.hasA11yPropForComponent)(componentName, node.attributes, a11yConfig)) {
83
+ return;
84
+ }
85
+ const ancestors = sourceCode.getAncestors(node);
86
+ const wrapper = [...ancestors]
87
+ .reverse()
88
+ .find((a) => a.type === 'JSXElement' &&
89
+ a.openingElement.name.type === 'JSXIdentifier' &&
90
+ wrappingComponents.includes(a.openingElement.name.name));
91
+ if (wrapper) {
92
+ const open = wrapper.openingElement;
93
+ const wrapperName = open.name.type === 'JSXIdentifier' ? open.name.name : '';
94
+ if (!(0, has_spread_1.hasSpread)(open.attributes) &&
95
+ !(0, has_a11y_prop_for_component_1.hasA11yPropForComponent)(wrapperName, open.attributes, a11yConfig)) {
96
+ report(open);
97
+ }
98
+ }
99
+ else {
100
+ report(node);
101
+ }
102
+ },
103
+ };
104
+ },
105
+ });
106
+ //# sourceMappingURL=no_unnamed_interactive_element.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no_unnamed_interactive_element.js","sourceRoot":"","sources":["../../../../src/rules/a11y/no_unnamed_interactive_element.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAEH,oDAAsE;AACtE,uDAAmD;AACnD,qHAG+D;AAC/D,yFAAkF;AAElF,MAAM,qBAAqB,GAAG;IAC5B,cAAc;IACd,gBAAgB;IAChB,eAAe;IACf,aAAa;IACb,WAAW;IACX,oBAAoB;IACpB,gBAAgB;IAChB,eAAe;IACf,aAAa;IACb,gBAAgB;CACR,CAAC;AAEX,MAAM,kBAAkB,GAAG,CAAC,YAAY,CAAU,CAAC;AACnD,MAAM,8BAA8B,GAAG,CAAC,cAAc,CAAU,CAAC;AACjE,MAAM,aAAa,GAAG,CAAC,YAAY,EAAE,iBAAiB,CAAU,CAAC;AAEjE,6DAA6D;AAC7D,MAAM,UAAU,GAAe;IAC7B,8BAA8B,EAAE,CAAC,GAAG,8BAA8B,CAAC;IACnE,kBAAkB,EAAE,CAAC,GAAG,kBAAkB,CAAC;IAC3C,aAAa,EAAE,CAAC,GAAG,aAAa,CAAC;CAClC,CAAC;AAEW,QAAA,2BAA2B,GAAG,mBAAW,CAAC,WAAW,CAAC,WAAW,CAAC;IAC7E,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,cAAc,EAAE,KAAK;QACrB,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,WAAW,EACT,2EAA2E;SAC9E;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,CAAC,OAAO;QACZ,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QAEtC,SAAS,MAAM,CAAC,OAAmC;YACjD,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,eAAe;gBAAE,OAAO;YAClD,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;YACpC,MAAM,OAAO,GAAG,IAAA,+EAAmC,EAAC,SAAS,EAAE,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACtF,OAAO,CAAC,MAAM,CAAC;gBACb,IAAI,EAAE,OAAO;gBACb,SAAS,EAAE,aAAa;gBACxB,IAAI,EAAE;oBACJ,SAAS;oBACT,SAAS,EAAE,OAAO;iBACnB;aACF,CAAC,CAAC;QACL,CAAC;QAED,OAAO;YACL,iBAAiB,CAAC,IAAI;gBACpB,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,eAAe;oBAAE,OAAO;gBAE/C,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;gBACrC,MAAM,aAAa,GACjB,qBACD,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;gBAC1B,IAAI,CAAC,aAAa;oBAAE,OAAO;gBAE3B,IACE,IAAA,sBAAS,EAAC,IAAI,CAAC,UAAU,CAAC;oBAC1B,IAAA,qDAAuB,EAAC,aAAa,EAAE,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,EACnE,CAAC;oBACD,OAAO;gBACT,CAAC;gBAED,MAAM,SAAS,GAAG,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;gBAChD,MAAM,OAAO,GAAG,CAAC,GAAG,SAAS,CAAC;qBAC3B,OAAO,EAAE;qBACT,IAAI,CACH,CAAC,CAAC,EAA4B,EAAE,CAC9B,CAAC,CAAC,IAAI,KAAK,YAAY;oBACvB,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,KAAK,eAAe;oBAC7C,kBAAwC,CAAC,QAAQ,CAChD,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAC3B,CACJ,CAAC;gBAEJ,IAAI,OAAO,EAAE,CAAC;oBACZ,MAAM,IAAI,GAAG,OAAO,CAAC,cAAc,CAAC;oBACpC,MAAM,WAAW,GACf,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC3D,IACE,CAAC,IAAA,sBAAS,EAAC,IAAI,CAAC,UAAU,CAAC;wBAC3B,CAAC,IAAA,qDAAuB,EAAC,WAAW,EAAE,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,EAClE,CAAC;wBACD,MAAM,CAAC,IAAI,CAAC,CAAC;oBACf,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,IAAI,CAAC,CAAC;gBACf,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Configuration describing which components accept a `label` prop
3
+ * and the baseline set of accessibility prop names allowed across components.
4
+ */
5
+ export type A11yConfig = {
6
+ interactiveComponentsWithLabel: ReadonlyArray<string>;
7
+ wrappingComponents: ReadonlyArray<string>;
8
+ baseA11yProps: ReadonlyArray<string>;
9
+ };
10
+ /**
11
+ * Compute the set of allowed accessibility prop names for a given component.
12
+ *
13
+ * - Always includes the provided `baseA11yProps`.
14
+ * - Conditionally includes `label` if the component is listed in either
15
+ * `interactiveComponentsWithLabel` or `wrappingComponents`.
16
+ * - Does **not** mutate the provided configuration; a new array is returned.
17
+ *
18
+ * @param componentName - The EUI component name (e.g., `'EuiButtonIcon'`).
19
+ * @param cfg - The accessibility configuration to use when resolving allowed props.
20
+ * @returns A new array of allowed prop names for `componentName`.
21
+ *
22
+ */
23
+ export declare function getAllowedA11yPropNamesForComponent(componentName: string, cfg: A11yConfig): string[];
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ /*
3
+ * Licensed to Elasticsearch B.V. under one or more contributor
4
+ * license agreements. See the NOTICE file distributed with
5
+ * this work for additional information regarding copyright
6
+ * ownership. Elasticsearch B.V. licenses this file to you under
7
+ * the Apache License, Version 2.0 (the "License"); you may
8
+ * not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing,
14
+ * software distributed under the License is distributed on an
15
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ * KIND, either express or implied. See the License for the
17
+ * specific language governing permissions and limitations
18
+ * under the License.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.getAllowedA11yPropNamesForComponent = getAllowedA11yPropNamesForComponent;
22
+ /**
23
+ * Compute the set of allowed accessibility prop names for a given component.
24
+ *
25
+ * - Always includes the provided `baseA11yProps`.
26
+ * - Conditionally includes `label` if the component is listed in either
27
+ * `interactiveComponentsWithLabel` or `wrappingComponents`.
28
+ * - Does **not** mutate the provided configuration; a new array is returned.
29
+ *
30
+ * @param componentName - The EUI component name (e.g., `'EuiButtonIcon'`).
31
+ * @param cfg - The accessibility configuration to use when resolving allowed props.
32
+ * @returns A new array of allowed prop names for `componentName`.
33
+ *
34
+ */
35
+ function getAllowedA11yPropNamesForComponent(componentName, cfg) {
36
+ const componentsWithLabel = new Set([
37
+ ...cfg.interactiveComponentsWithLabel,
38
+ ...cfg.wrappingComponents,
39
+ ]);
40
+ if (componentsWithLabel.has(componentName)) {
41
+ return [...cfg.baseA11yProps, 'label'];
42
+ }
43
+ return [...cfg.baseA11yProps];
44
+ }
45
+ //# sourceMappingURL=get_allowed_a11y_prop_names_for_component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get_allowed_a11y_prop_names_for_component.js","sourceRoot":"","sources":["../../../src/utils/get_allowed_a11y_prop_names_for_component.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;AAyBH,kFAaC;AA1BD;;;;;;;;;;;;GAYG;AACH,SAAgB,mCAAmC,CACjD,aAAqB,EACrB,GAAe;IAEf,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAS;QAC1C,GAAG,GAAG,CAAC,8BAA8B;QACrC,GAAG,GAAG,CAAC,kBAAkB;KAC1B,CAAC,CAAC;IAEH,IAAI,mBAAmB,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC;QAC3C,OAAO,CAAC,GAAG,GAAG,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,CAAC,GAAG,GAAG,CAAC,aAAa,CAAC,CAAC;AAChC,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { TSESTree } from '@typescript-eslint/utils';
2
+ import { type A11yConfig } from './get_allowed_a11y_prop_names_for_component';
3
+ /**
4
+ * Determines whether a JSX element declares at least one **allowed**
5
+ * accessibility-related prop for a given component.
6
+ *
7
+ * Allowed prop names are resolved via {@link getAllowedA11yPropNamesForComponent},
8
+ * which combines baseline a11y props (e.g. `aria-*`) and conditionally adds
9
+ * `label` for components that support it per the provided configuration.
10
+ *
11
+ * Only plain `JSXAttribute` nodes are considered—spread attributes are ignored here.
12
+ *
13
+ * @param componentName - The component name being checked (e.g., `"EuiButtonIcon"`).
14
+ * @param attrs - The attributes array from a `JSXOpeningElement` (ESTree).
15
+ * @param cfg - Accessibility configuration that defines base props and which
16
+ * components may accept a `label` prop.
17
+ * @returns `true` if any attribute name on the element is in the allowed set; otherwise `false`.
18
+ */
19
+ export declare function hasA11yPropForComponent(componentName: string, attrs: TSESTree.JSXOpeningElement['attributes'], cfg: A11yConfig): boolean;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ /*
3
+ * Licensed to Elasticsearch B.V. under one or more contributor
4
+ * license agreements. See the NOTICE file distributed with
5
+ * this work for additional information regarding copyright
6
+ * ownership. Elasticsearch B.V. licenses this file to you under
7
+ * the Apache License, Version 2.0 (the "License"); you may
8
+ * not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing,
14
+ * software distributed under the License is distributed on an
15
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ * KIND, either express or implied. See the License for the
17
+ * specific language governing permissions and limitations
18
+ * under the License.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.hasA11yPropForComponent = hasA11yPropForComponent;
22
+ const get_allowed_a11y_prop_names_for_component_1 = require("./get_allowed_a11y_prop_names_for_component");
23
+ /**
24
+ * Determines whether a JSX element declares at least one **allowed**
25
+ * accessibility-related prop for a given component.
26
+ *
27
+ * Allowed prop names are resolved via {@link getAllowedA11yPropNamesForComponent},
28
+ * which combines baseline a11y props (e.g. `aria-*`) and conditionally adds
29
+ * `label` for components that support it per the provided configuration.
30
+ *
31
+ * Only plain `JSXAttribute` nodes are considered—spread attributes are ignored here.
32
+ *
33
+ * @param componentName - The component name being checked (e.g., `"EuiButtonIcon"`).
34
+ * @param attrs - The attributes array from a `JSXOpeningElement` (ESTree).
35
+ * @param cfg - Accessibility configuration that defines base props and which
36
+ * components may accept a `label` prop.
37
+ * @returns `true` if any attribute name on the element is in the allowed set; otherwise `false`.
38
+ */
39
+ function hasA11yPropForComponent(componentName, attrs, cfg) {
40
+ const allowed = new Set((0, get_allowed_a11y_prop_names_for_component_1.getAllowedA11yPropNamesForComponent)(componentName, cfg));
41
+ return attrs.some((attr) => attr.type === 'JSXAttribute' &&
42
+ attr.name.type === 'JSXIdentifier' &&
43
+ allowed.has(attr.name.name));
44
+ }
45
+ //# sourceMappingURL=has_a11y_prop_for_component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has_a11y_prop_for_component.js","sourceRoot":"","sources":["../../../src/utils/has_a11y_prop_for_component.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;AAyBH,0DAcC;AApCD,2GAGqD;AAErD;;;;;;;;;;;;;;;GAeG;AAEH,SAAgB,uBAAuB,CACrC,aAAqB,EACrB,KAA+C,EAC/C,GAAe;IAEf,MAAM,OAAO,GAAG,IAAI,GAAG,CACrB,IAAA,+EAAmC,EAAC,aAAa,EAAE,GAAG,CAAC,CACxD,CAAC;IACF,OAAO,KAAK,CAAC,IAAI,CACf,CAAC,IAAI,EAAiC,EAAE,CACtC,IAAI,CAAC,IAAI,KAAK,cAAc;QAC5B,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,eAAe;QAClC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAC9B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { TSESTree } from '@typescript-eslint/utils';
2
+ /**
3
+ * Checks whether a JSX opening element contains a spread attribute
4
+ * (e.g., `...props`). Spreads make it impossible to statically know
5
+ * all props present on an element, so ESLint rules often use this as
6
+ * a quick bail-out to avoid false positives.
7
+ *
8
+ * @param attrs - The attributes array from a `JSXOpeningElement` node (ESTree).
9
+ * @returns `true` if any attribute is a `JSXSpreadAttribute`; otherwise `false`.
10
+ */
11
+ export declare function hasSpread(attrs: TSESTree.JSXOpeningElement['attributes']): boolean;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ /*
3
+ * Licensed to Elasticsearch B.V. under one or more contributor
4
+ * license agreements. See the NOTICE file distributed with
5
+ * this work for additional information regarding copyright
6
+ * ownership. Elasticsearch B.V. licenses this file to you under
7
+ * the Apache License, Version 2.0 (the "License"); you may
8
+ * not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing,
14
+ * software distributed under the License is distributed on an
15
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ * KIND, either express or implied. See the License for the
17
+ * specific language governing permissions and limitations
18
+ * under the License.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.hasSpread = hasSpread;
22
+ /**
23
+ * Checks whether a JSX opening element contains a spread attribute
24
+ * (e.g., `...props`). Spreads make it impossible to statically know
25
+ * all props present on an element, so ESLint rules often use this as
26
+ * a quick bail-out to avoid false positives.
27
+ *
28
+ * @param attrs - The attributes array from a `JSXOpeningElement` node (ESTree).
29
+ * @returns `true` if any attribute is a `JSXSpreadAttribute`; otherwise `false`.
30
+ */
31
+ function hasSpread(attrs) {
32
+ return attrs.some((a) => a.type === 'JSXSpreadAttribute');
33
+ }
34
+ //# sourceMappingURL=has_spread.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has_spread.js","sourceRoot":"","sources":["../../../src/utils/has_spread.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;AAcH,8BAIC;AAdD;;;;;;;;GAQG;AAEH,SAAgB,SAAS,CACvB,KAA+C;IAE/C,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,oBAAoB,CAAC,CAAC;AAC5D,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { TSESTree } from '@typescript-eslint/utils';
2
+ export declare function isInConditionalRendering(node: TSESTree.JSXElement): boolean;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ /*
3
+ * Licensed to Elasticsearch B.V. under one or more contributor
4
+ * license agreements. See the NOTICE file distributed with
5
+ * this work for additional information regarding copyright
6
+ * ownership. Elasticsearch B.V. licenses this file to you under
7
+ * the Apache License, Version 2.0 (the "License"); you may
8
+ * not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing,
14
+ * software distributed under the License is distributed on an
15
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ * KIND, either express or implied. See the License for the
17
+ * specific language governing permissions and limitations
18
+ * under the License.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.isInConditionalRendering = isInConditionalRendering;
22
+ function isInConditionalRendering(node) {
23
+ let parent = node.parent;
24
+ while (parent) {
25
+ if (parent.type === 'ConditionalExpression' ||
26
+ parent.type === 'IfStatement' ||
27
+ (parent.type === 'LogicalExpression' && parent.operator === '&&')) {
28
+ return true;
29
+ }
30
+ parent = parent.parent;
31
+ }
32
+ return false;
33
+ }
34
+ //# sourceMappingURL=is_in_conditional_rendering.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is_in_conditional_rendering.js","sourceRoot":"","sources":["../../../src/utils/is_in_conditional_rendering.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;AAIH,4DAWC;AAXD,SAAgB,wBAAwB,CAAC,IAAyB;IAChE,IAAI,MAAM,GAA8B,IAAI,CAAC,MAAM,CAAC;IACpD,OAAO,MAAM,EAAE,CAAC;QACd,IAAI,MAAM,CAAC,IAAI,KAAK,uBAAuB;YACzC,MAAM,CAAC,IAAI,KAAK,aAAa;YAC7B,CAAC,MAAM,CAAC,IAAI,KAAK,mBAAmB,IAAI,MAAM,CAAC,QAAQ,KAAK,IAAI,CAAC,EAAE,CAAC;YACpE,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IACzB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elastic/eslint-plugin-eui",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",