@elastic/eslint-plugin-eui 2.16.0-snapshot.1788177701701 → 3.0.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.
- package/README.md +71 -2
- package/lib/cjs/index.js +4 -1
- package/lib/cjs/rules/button_group_no_invalid_children.d.ts +1 -3
- package/lib/cjs/rules/button_group_no_invalid_children.d.ts.map +1 -1
- package/lib/cjs/rules/button_group_no_invalid_children.js +28 -38
- package/lib/cjs/rules/button_group_selection_require_id.d.ts +3 -0
- package/lib/cjs/rules/button_group_selection_require_id.d.ts.map +1 -0
- package/lib/cjs/rules/button_group_selection_require_id.js +114 -0
- package/lib/cjs/rules/no_deprecated_icon_aliases.d.ts +45 -4
- package/lib/cjs/rules/no_deprecated_icon_aliases.d.ts.map +1 -1
- package/lib/cjs/rules/no_deprecated_icon_aliases.js +61 -7
- package/lib/cjs/utils/button_group_constants.d.ts +6 -0
- package/lib/cjs/utils/button_group_constants.d.ts.map +1 -0
- package/lib/cjs/utils/button_group_constants.js +19 -0
- package/lib/cjs/utils/collect_jsx_children.d.ts +3 -0
- package/lib/cjs/utils/collect_jsx_children.d.ts.map +1 -0
- package/lib/cjs/utils/collect_jsx_children.js +26 -0
- package/lib/esm/index.js +3 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/rules/button_group_no_invalid_children.d.ts +1 -3
- package/lib/esm/rules/button_group_no_invalid_children.js +34 -42
- package/lib/esm/rules/button_group_no_invalid_children.js.map +1 -1
- package/lib/esm/rules/button_group_selection_require_id.d.ts +2 -0
- package/lib/esm/rules/button_group_selection_require_id.js +118 -0
- package/lib/esm/rules/button_group_selection_require_id.js.map +1 -0
- package/lib/esm/rules/no_deprecated_icon_aliases.d.ts +45 -4
- package/lib/esm/rules/no_deprecated_icon_aliases.js +66 -5
- package/lib/esm/rules/no_deprecated_icon_aliases.js.map +1 -1
- package/lib/esm/utils/button_group_constants.d.ts +5 -0
- package/lib/esm/utils/button_group_constants.js +20 -0
- package/lib/esm/utils/button_group_constants.js.map +1 -0
- package/lib/esm/utils/collect_jsx_children.d.ts +2 -0
- package/lib/esm/utils/collect_jsx_children.js +21 -0
- package/lib/esm/utils/collect_jsx_children.js.map +1 -0
- package/package.json +2 -3
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.NoDeprecatedIconAliases = exports.DEPRECATED_ICON_ALIASES = exports.DEPRECATED_ICONS_WITHOUT_REPLACEMENT = void 0;
|
|
6
|
+
exports.NoDeprecatedIconAliases = exports.DEPRECATED_ICON_ALIASES = exports.DEPRECATED_ICONS_WITH_GUIDANCE = exports.DEPRECATED_ICONS_WITHOUT_REPLACEMENT = void 0;
|
|
7
7
|
var _utils = require("@typescript-eslint/utils");
|
|
8
8
|
/*
|
|
9
9
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
@@ -15,7 +15,11 @@ var _utils = require("@typescript-eslint/utils");
|
|
|
15
15
|
|
|
16
16
|
const DEPRECATED_ICON_ALIASES = exports.DEPRECATED_ICON_ALIASES = {
|
|
17
17
|
alert: 'warning',
|
|
18
|
+
analyzeEvent: 'cube',
|
|
18
19
|
anomalyChart: 'chartAnomaly',
|
|
20
|
+
anomalySwimLane: 'chartHeatmap',
|
|
21
|
+
annotation: 'flag',
|
|
22
|
+
apps: 'grid',
|
|
19
23
|
apmTrace: 'chartWaterfall',
|
|
20
24
|
arrowDown: 'chevronSingleDown',
|
|
21
25
|
arrowEnd: 'chevronLimitRight',
|
|
@@ -35,6 +39,9 @@ const DEPRECATED_ICON_ALIASES = exports.DEPRECATED_ICON_ALIASES = {
|
|
|
35
39
|
color: 'paintBucket',
|
|
36
40
|
compute: 'processor',
|
|
37
41
|
console: 'commandLine',
|
|
42
|
+
container: 'package',
|
|
43
|
+
continuityAbove: 'upload',
|
|
44
|
+
continuityWithin: 'maximize',
|
|
38
45
|
contrastHigh: 'contrastFill',
|
|
39
46
|
controlsHorizontal: 'controls',
|
|
40
47
|
controlsVertical: 'controls',
|
|
@@ -81,6 +88,7 @@ const DEPRECATED_ICON_ALIASES = exports.DEPRECATED_ICON_ALIASES = {
|
|
|
81
88
|
editorUnorderedList: 'listBullet',
|
|
82
89
|
email: 'mail',
|
|
83
90
|
eql: 'query',
|
|
91
|
+
esqlVis: 'query',
|
|
84
92
|
errorFilled: 'errorFill',
|
|
85
93
|
exit: 'logOut',
|
|
86
94
|
expand: 'maximize',
|
|
@@ -90,15 +98,23 @@ const DEPRECATED_ICON_ALIASES = exports.DEPRECATED_ICON_ALIASES = {
|
|
|
90
98
|
eyeClosed: 'eyeSlash',
|
|
91
99
|
fieldStatistics: 'tableInfo',
|
|
92
100
|
filterInCircle: 'filter',
|
|
101
|
+
fold: 'minimize',
|
|
93
102
|
folderCheck: 'check',
|
|
103
|
+
folderClose: 'folder',
|
|
104
|
+
folderClosed: 'folder',
|
|
94
105
|
folderOpened: 'folderOpen',
|
|
106
|
+
frameNext: 'chevronSingleRight',
|
|
107
|
+
framePrevious: 'chevronSingleLeft',
|
|
95
108
|
glasses: 'readOnly',
|
|
109
|
+
help: 'question',
|
|
96
110
|
grab: 'dragVertical',
|
|
97
111
|
grabHorizontal: 'dragHorizontal',
|
|
98
112
|
grabOmnidirectional: 'drag',
|
|
99
113
|
heatmap: 'chartHeatmap',
|
|
100
114
|
importAction: 'download',
|
|
115
|
+
index: 'table',
|
|
101
116
|
indexClose: 'tableCross',
|
|
117
|
+
ip: 'tokenIP',
|
|
102
118
|
indexEdit: 'tablePencil',
|
|
103
119
|
indexFlush: 'chartThreshold',
|
|
104
120
|
indexMapping: 'mapping',
|
|
@@ -121,7 +137,10 @@ const DEPRECATED_ICON_ALIASES = exports.DEPRECATED_ICON_ALIASES = {
|
|
|
121
137
|
listAdd: 'plusCircle',
|
|
122
138
|
logPatternAnalysis: 'pattern',
|
|
123
139
|
logRateAnalysis: 'chartBarVertical',
|
|
140
|
+
logstashFilter: 'filter',
|
|
124
141
|
logstashIf: 'if',
|
|
142
|
+
logstashInput: 'download',
|
|
143
|
+
logstashOutput: 'upload',
|
|
125
144
|
logstashQueue: 'queue',
|
|
126
145
|
magnifyWithExclamation: 'magnifyExclamation',
|
|
127
146
|
magnifyWithMinus: 'magnifyMinus',
|
|
@@ -138,6 +157,7 @@ const DEPRECATED_ICON_ALIASES = exports.DEPRECATED_ICON_ALIASES = {
|
|
|
138
157
|
offline: 'wifiSlash',
|
|
139
158
|
online: 'wifi',
|
|
140
159
|
pagesSelect: 'documentsCheck',
|
|
160
|
+
payment: 'money',
|
|
141
161
|
pinFilled: 'pinFill',
|
|
142
162
|
pipeBreaks: 'lineBreak',
|
|
143
163
|
pipeNoBreaks: 'lineBreakSlash',
|
|
@@ -150,15 +170,27 @@ const DEPRECATED_ICON_ALIASES = exports.DEPRECATED_ICON_ALIASES = {
|
|
|
150
170
|
returnKey: 'return',
|
|
151
171
|
search: 'magnify',
|
|
152
172
|
securitySignal: 'radar',
|
|
173
|
+
sessionViewer: 'commandLine',
|
|
174
|
+
singleMetricViewer: 'chartArea',
|
|
175
|
+
spaces: 'grid',
|
|
153
176
|
starEmpty: 'star',
|
|
177
|
+
starEmptySpace: 'star',
|
|
178
|
+
starFillSpace: 'starFill',
|
|
154
179
|
starFilled: 'starFill',
|
|
155
|
-
starFilledSpace: '
|
|
156
|
-
|
|
157
|
-
|
|
180
|
+
starFilledSpace: 'starFill',
|
|
181
|
+
starMinusEmpty: 'star',
|
|
182
|
+
starMinusFill: 'starFill',
|
|
183
|
+
starMinusFilled: 'starFill',
|
|
184
|
+
starPlusEmpty: 'star',
|
|
185
|
+
starPlusFill: 'starFill',
|
|
186
|
+
starPlusFilled: 'starFill',
|
|
158
187
|
stopFilled: 'stopFill',
|
|
188
|
+
stats: 'chartLine',
|
|
159
189
|
streamsClassic: 'productStreamsClassic',
|
|
160
190
|
streamsWired: 'productStreamsWired',
|
|
191
|
+
string: 'tokenString',
|
|
161
192
|
submodule: 'merge',
|
|
193
|
+
tableOfContents: 'listBullet',
|
|
162
194
|
tableDensityCompact: 'tableDensityHigh',
|
|
163
195
|
tableDensityExpanded: 'tableDensityLow',
|
|
164
196
|
tableDensityNormal: 'table',
|
|
@@ -168,6 +200,7 @@ const DEPRECATED_ICON_ALIASES = exports.DEPRECATED_ICON_ALIASES = {
|
|
|
168
200
|
timeslider: 'clockControl',
|
|
169
201
|
tokenDenseVector: 'tokenVectorDense',
|
|
170
202
|
training: 'presentation',
|
|
203
|
+
unfold: 'maximize',
|
|
171
204
|
unlink: 'linkSlash',
|
|
172
205
|
userAvatar: 'user',
|
|
173
206
|
vector: 'vectorSquare',
|
|
@@ -178,6 +211,7 @@ const DEPRECATED_ICON_ALIASES = exports.DEPRECATED_ICON_ALIASES = {
|
|
|
178
211
|
visBarVertical: 'chartBarVertical',
|
|
179
212
|
visBarVerticalStacked: 'chartBarVerticalStack',
|
|
180
213
|
visGauge: 'chartGauge',
|
|
214
|
+
visGoal: 'chartGauge',
|
|
181
215
|
visLine: 'chartLine',
|
|
182
216
|
visMapCoordinate: 'waypoint',
|
|
183
217
|
visMapRegion: 'map',
|
|
@@ -189,9 +223,17 @@ const DEPRECATED_ICON_ALIASES = exports.DEPRECATED_ICON_ALIASES = {
|
|
|
189
223
|
visTimelion: 'productTimelion',
|
|
190
224
|
visVega: 'code',
|
|
191
225
|
visVisualBuilder: 'productTSVB',
|
|
192
|
-
warningFilled: 'warningFill'
|
|
226
|
+
warningFilled: 'warningFill',
|
|
227
|
+
wordWrap: 'lineBreak',
|
|
228
|
+
wordWrapDisabled: 'lineBreakSlash'
|
|
193
229
|
};
|
|
194
|
-
const DEPRECATED_ICONS_WITHOUT_REPLACEMENT = exports.DEPRECATED_ICONS_WITHOUT_REPLACEMENT = new Set(['mobile']);
|
|
230
|
+
const DEPRECATED_ICONS_WITHOUT_REPLACEMENT = exports.DEPRECATED_ICONS_WITHOUT_REPLACEMENT = new Set(['article', 'dotInCircle', 'kubernetesNode', 'mobile', 'scale', 'securitySignalDetected']);
|
|
231
|
+
const DEPRECATED_ICONS_WITH_GUIDANCE = exports.DEPRECATED_ICONS_WITH_GUIDANCE = {
|
|
232
|
+
folderExclamation: 'Use `linkSlash` for unlink actions or `hourglass` for Kibana Cases status.',
|
|
233
|
+
stopFill: 'Use `EuiColorPickerSwatch` for a color chip or `stop` otherwise.',
|
|
234
|
+
stopSlash: 'Use `EuiColorPickerSwatch` for no/transparent color or `stop` otherwise.'
|
|
235
|
+
};
|
|
236
|
+
const isDeprecatedIconWithGuidance = value => value in DEPRECATED_ICONS_WITH_GUIDANCE;
|
|
195
237
|
const getComponentName = node => node.name.type === 'JSXIdentifier' ? node.name.name : undefined;
|
|
196
238
|
const COMPONENT_ICON_ATTRIBUTES = {
|
|
197
239
|
EuiCommentTimeline: new Set(['timelineAvatar']),
|
|
@@ -266,6 +308,17 @@ const NoDeprecatedIconAliases = exports.NoDeprecatedIconAliases = _utils.ESLintU
|
|
|
266
308
|
return;
|
|
267
309
|
}
|
|
268
310
|
if (!isDeprecatedIconAlias(iconType)) {
|
|
311
|
+
if (isDeprecatedIconWithGuidance(iconType)) {
|
|
312
|
+
context.report({
|
|
313
|
+
node: staticStringNode,
|
|
314
|
+
messageId: 'deprecatedIconGuidance',
|
|
315
|
+
data: {
|
|
316
|
+
iconType,
|
|
317
|
+
guidance: DEPRECATED_ICONS_WITH_GUIDANCE[iconType]
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
269
322
|
if (DEPRECATED_ICONS_WITHOUT_REPLACEMENT.has(iconType)) {
|
|
270
323
|
context.report({
|
|
271
324
|
node: staticStringNode,
|
|
@@ -303,7 +356,8 @@ const NoDeprecatedIconAliases = exports.NoDeprecatedIconAliases = _utils.ESLintU
|
|
|
303
356
|
schema: [],
|
|
304
357
|
messages: {
|
|
305
358
|
deprecatedIcon: 'Icon `{{iconType}}` is deprecated and has no direct replacement.',
|
|
306
|
-
deprecatedIconAlias: 'Icon alias `{{alias}}` is deprecated. Use `{{replacement}}` instead.'
|
|
359
|
+
deprecatedIconAlias: 'Icon alias `{{alias}}` is deprecated. Use `{{replacement}}` instead.',
|
|
360
|
+
deprecatedIconGuidance: 'Icon `{{iconType}}` is deprecated. {{guidance}}'
|
|
307
361
|
}
|
|
308
362
|
},
|
|
309
363
|
defaultOptions: []
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const BUTTON_GROUP = "EuiButtonGroup";
|
|
2
|
+
export declare const VALID_BUTTONS: Set<string>;
|
|
3
|
+
export declare const SEGMENTED_VALID_BUTTONS: Set<string>;
|
|
4
|
+
export declare const SELECTION_VALID_BUTTONS: Set<string>;
|
|
5
|
+
export declare const VALID_WRAPPERS: Set<string>;
|
|
6
|
+
//# sourceMappingURL=button_group_constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"button_group_constants.d.ts","sourceRoot":"","sources":["../../../src/utils/button_group_constants.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,YAAY,mBAAmB,CAAC;AAE7C,eAAO,MAAM,aAAa,aAIxB,CAAC;AAEH,eAAO,MAAM,uBAAuB,aAA0C,CAAC;AAE/E,eAAO,MAAM,uBAAuB,aAA0C,CAAC;AAE/E,eAAO,MAAM,cAAc,aAAmD,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.VALID_WRAPPERS = exports.VALID_BUTTONS = exports.SELECTION_VALID_BUTTONS = exports.SEGMENTED_VALID_BUTTONS = exports.BUTTON_GROUP = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
9
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
10
|
+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
11
|
+
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
12
|
+
* Side Public License, v 1.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const BUTTON_GROUP = exports.BUTTON_GROUP = 'EuiButtonGroup';
|
|
16
|
+
const VALID_BUTTONS = exports.VALID_BUTTONS = new Set(['EuiButton', 'EuiButtonEmpty', 'EuiButtonIcon']);
|
|
17
|
+
const SEGMENTED_VALID_BUTTONS = exports.SEGMENTED_VALID_BUTTONS = new Set(['EuiButton', 'EuiButtonIcon']);
|
|
18
|
+
const SELECTION_VALID_BUTTONS = exports.SELECTION_VALID_BUTTONS = new Set(['EuiButton', 'EuiButtonIcon']);
|
|
19
|
+
const VALID_WRAPPERS = exports.VALID_WRAPPERS = new Set(['EuiToolTip', 'EuiPopover', 'EuiCopy']);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collect_jsx_children.d.ts","sourceRoot":"","sources":["../../../src/utils/collect_jsx_children.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAGxE,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,QAAQ,CAAC,IAAI,EACnB,UAAU,EAAE,QAAQ,CAAC,UAAU,GAC9B,QAAQ,CAAC,UAAU,EAAE,CAYvB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.collectJsxChildren = collectJsxChildren;
|
|
7
|
+
var _walk_jsx_children = require("./walk_jsx_children");
|
|
8
|
+
/*
|
|
9
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
10
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
11
|
+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
12
|
+
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
13
|
+
* Side Public License, v 1.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
function collectJsxChildren(node, sourceCode) {
|
|
17
|
+
const results = [];
|
|
18
|
+
(0, _walk_jsx_children.walkJsxChildren)(node, leaf => {
|
|
19
|
+
if (leaf.type === 'JSXElement') {
|
|
20
|
+
results.push(leaf);
|
|
21
|
+
}
|
|
22
|
+
}, {
|
|
23
|
+
sourceCode
|
|
24
|
+
});
|
|
25
|
+
return results;
|
|
26
|
+
}
|
package/lib/esm/index.js
CHANGED
|
@@ -31,6 +31,7 @@ const tooltip_no_interactive_content_1 = require("./rules/a11y/tooltip_no_intera
|
|
|
31
31
|
const tooltip_button_icon_wrap_1 = require("./rules/a11y/tooltip_button_icon_wrap");
|
|
32
32
|
const no_deprecated_icon_aliases_1 = require("./rules/no_deprecated_icon_aliases");
|
|
33
33
|
const button_group_no_invalid_children_1 = require("./rules/button_group_no_invalid_children");
|
|
34
|
+
const button_group_selection_require_id_1 = require("./rules/button_group_selection_require_id");
|
|
34
35
|
const config = {
|
|
35
36
|
rules: {
|
|
36
37
|
'accessible-interactive-element': accessible_interactive_element_1.AccessibleInteractiveElements,
|
|
@@ -57,6 +58,7 @@ const config = {
|
|
|
57
58
|
'tooltip-no-interactive-content': tooltip_no_interactive_content_1.TooltipNoInteractiveContent,
|
|
58
59
|
'tooltip-button-icon-wrap': tooltip_button_icon_wrap_1.TooltipButtonIconWrap,
|
|
59
60
|
'button-group-no-invalid-children': button_group_no_invalid_children_1.ButtonGroupNoInvalidChildren,
|
|
61
|
+
'button-group-selection-require-id': button_group_selection_require_id_1.ButtonGroupSelectionRequireId,
|
|
60
62
|
},
|
|
61
63
|
configs: {
|
|
62
64
|
recommended: {
|
|
@@ -64,6 +66,7 @@ const config = {
|
|
|
64
66
|
rules: {
|
|
65
67
|
'@elastic/eui/accessible-interactive-element': 'warn',
|
|
66
68
|
'@elastic/eui/button-group-no-invalid-children': 'error',
|
|
69
|
+
'@elastic/eui/button-group-selection-require-id': 'error',
|
|
67
70
|
'@elastic/eui/callout-announce-on-mount': 'warn',
|
|
68
71
|
'@elastic/eui/callout-prefer-props-for-content': 'warn',
|
|
69
72
|
'@elastic/eui/consistent-is-invalid-props': 'warn',
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AAEH,gGAA4F;AAC5F,sFAAgF;AAChF,+FAAwF;AACxF,0FAAoF;AACpF,+DAAuD;AACvD,yEAAmE;AACnE,uDAAkD;AAClD,gFAA0E;AAC1E,iFAA2E;AAC3E,iEAA2D;AAC3D,gGAA0F;AAC1F,gFAA0E;AAC1E,0EAAoE;AACpE,8FAAuF;AACvF,8EAAyE;AACzE,wFAA4F;AAC5F,oFAA+E;AAC/E,iHAAyG;AACzG,sFAAoF;AACpF,oFAAkF;AAClF,gGAA0F;AAC1F,oFAA8E;AAC9E,mFAA6E;AAC7E,+FAAwF;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AAEH,gGAA4F;AAC5F,sFAAgF;AAChF,+FAAwF;AACxF,0FAAoF;AACpF,+DAAuD;AACvD,yEAAmE;AACnE,uDAAkD;AAClD,gFAA0E;AAC1E,iFAA2E;AAC3E,iEAA2D;AAC3D,gGAA0F;AAC1F,gFAA0E;AAC1E,0EAAoE;AACpE,8FAAuF;AACvF,8EAAyE;AACzE,wFAA4F;AAC5F,oFAA+E;AAC/E,iHAAyG;AACzG,sFAAoF;AACpF,oFAAkF;AAClF,gGAA0F;AAC1F,oFAA8E;AAC9E,mFAA6E;AAC7E,+FAAwF;AACxF,iGAA0F;AAE1F,MAAM,MAAM,GAAG;IACb,KAAK,EAAE;QACL,gCAAgC,EAAE,8DAA6B;QAC/D,2B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BACpD,oCAAoC,EAAE,MAAM;gBAC5C,yCAAyC,EAAE,MAAM;gBACjD,uCAAuC,EAAE,MAAM;gBAC/C,wDAAwD,EAAE,MAAM;gBAChE,wCAAwC,EAAE,MAAM;gBAChD,uCAAuC,EAAE,MAAM;gBAC/C,oCAAoC,EAAE,MAAM;gBAC5C,6CAA6C,EAAE,MAAM;gBACrD,uCAAuC,EAAE,MAAM;aAChD;SACF;KACF;CACF,CAAC;AAEF,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC"}
|
|
@@ -1,4 +1,2 @@
|
|
|
1
1
|
import { type TSESLint } from '@typescript-eslint/utils';
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const SEGMENTED_VALID_BUTTONS: Set<string>;
|
|
4
|
-
export declare const ButtonGroupNoInvalidChildren: TSESLint.RuleModule<"invalidUnresolvableWrapperChild" | "invalidWrapperChild" | "invalidChild" | "invalidUnresolvableChild" | "invalidPopoverButton" | "invalidUnresolvablePopoverButton" | "invalidSegmentedMixedTypes", [], unknown, TSESLint.RuleListener>;
|
|
2
|
+
export declare const ButtonGroupNoInvalidChildren: TSESLint.RuleModule<"invalidUnresolvableWrapperChild" | "invalidWrapperChild" | "invalidChild" | "invalidUnresolvableChild" | "invalidPopoverButton" | "invalidUnresolvablePopoverButton" | "invalidMixedTypes", [], unknown, TSESLint.RuleListener>;
|
|
@@ -7,36 +7,20 @@
|
|
|
7
7
|
* Side Public License, v 1.
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.ButtonGroupNoInvalidChildren =
|
|
10
|
+
exports.ButtonGroupNoInvalidChildren = void 0;
|
|
11
11
|
const utils_1 = require("@typescript-eslint/utils");
|
|
12
12
|
const has_spread_1 = require("../utils/has_spread");
|
|
13
13
|
const flat_map_1 = require("../utils/flat_map");
|
|
14
14
|
const get_element_name_1 = require("../utils/get_element_name");
|
|
15
|
-
const walk_jsx_children_1 = require("../utils/walk_jsx_children");
|
|
16
15
|
const get_attr_value_1 = require("../utils/get_attr_value");
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
'EuiButtonEmpty',
|
|
21
|
-
'EuiButtonIcon',
|
|
22
|
-
]);
|
|
23
|
-
exports.SEGMENTED_VALID_BUTTONS = new Set(['EuiButton', 'EuiButtonIcon']);
|
|
24
|
-
const VALID_WRAPPERS = new Set(['EuiToolTip', 'EuiPopover', 'EuiCopy']);
|
|
25
|
-
const VALID_WRAPPERS_LIST = Array.from(VALID_WRAPPERS).join(', ');
|
|
16
|
+
const collect_jsx_children_1 = require("../utils/collect_jsx_children");
|
|
17
|
+
const button_group_constants_1 = require("../utils/button_group_constants");
|
|
18
|
+
const VALID_WRAPPERS_LIST = Array.from(button_group_constants_1.VALID_WRAPPERS).join(', ');
|
|
26
19
|
function isCustomComponent(name) {
|
|
27
20
|
return name[0] === name[0].toUpperCase();
|
|
28
21
|
}
|
|
29
|
-
function collectJsxChildren(node, sourceCode) {
|
|
30
|
-
const results = [];
|
|
31
|
-
(0, walk_jsx_children_1.walkJsxChildren)(node, (leaf) => {
|
|
32
|
-
if (leaf.type === 'JSXElement') {
|
|
33
|
-
results.push(leaf);
|
|
34
|
-
}
|
|
35
|
-
}, { sourceCode });
|
|
36
|
-
return results;
|
|
37
|
-
}
|
|
38
22
|
function reportInvalidWrapperChildren(wrapper, wrapperName, context, validButtons, allowed, seenButtonTypes) {
|
|
39
|
-
const children = (0, flat_map_1.flatMap)(wrapper.children, (c) => collectJsxChildren(c, context.sourceCode));
|
|
23
|
+
const children = (0, flat_map_1.flatMap)(wrapper.children, (c) => (0, collect_jsx_children_1.collectJsxChildren)(c, context.sourceCode));
|
|
40
24
|
for (const wrapperChild of children) {
|
|
41
25
|
if ((0, has_spread_1.hasSpread)(wrapperChild.openingElement.attributes))
|
|
42
26
|
continue;
|
|
@@ -49,7 +33,8 @@ function reportInvalidWrapperChildren(wrapper, wrapperName, context, validButton
|
|
|
49
33
|
}
|
|
50
34
|
context.report({
|
|
51
35
|
node: wrapperChild.openingElement,
|
|
52
|
-
messageId: isCustomComponent(wrapperChildName) &&
|
|
36
|
+
messageId: isCustomComponent(wrapperChildName) &&
|
|
37
|
+
!button_group_constants_1.VALID_BUTTONS.has(wrapperChildName)
|
|
53
38
|
? 'invalidUnresolvableWrapperChild'
|
|
54
39
|
: 'invalidWrapperChild',
|
|
55
40
|
data: { name: wrapperChildName, wrapper: wrapperName, allowed },
|
|
@@ -62,27 +47,31 @@ exports.ButtonGroupNoInvalidChildren = utils_1.ESLintUtils.RuleCreator.withoutDo
|
|
|
62
47
|
JSXElement(node) {
|
|
63
48
|
const { openingElement } = node;
|
|
64
49
|
if (openingElement.name.type !== 'JSXIdentifier' ||
|
|
65
|
-
openingElement.name.name !== BUTTON_GROUP) {
|
|
50
|
+
openingElement.name.name !== button_group_constants_1.BUTTON_GROUP) {
|
|
66
51
|
return;
|
|
67
52
|
}
|
|
68
|
-
// Validate "default" and "
|
|
53
|
+
// Validate "default", "segmented", and "selection" variants.
|
|
69
54
|
// Dynamic variant values (variables) are conservatively skipped.
|
|
70
55
|
const variant = (0, get_attr_value_1.findAttrValue)(context, openingElement.attributes, 'variant');
|
|
71
56
|
if (variant !== undefined &&
|
|
72
57
|
variant !== 'default' &&
|
|
73
|
-
variant !== 'segmented'
|
|
58
|
+
variant !== 'segmented' &&
|
|
59
|
+
variant !== 'selection')
|
|
74
60
|
return;
|
|
75
61
|
const isSegmented = variant === 'segmented';
|
|
62
|
+
const isSelection = variant === 'selection';
|
|
76
63
|
const validButtons = isSegmented
|
|
77
|
-
?
|
|
78
|
-
:
|
|
64
|
+
? button_group_constants_1.SEGMENTED_VALID_BUTTONS
|
|
65
|
+
: isSelection
|
|
66
|
+
? button_group_constants_1.SELECTION_VALID_BUTTONS
|
|
67
|
+
: button_group_constants_1.VALID_BUTTONS;
|
|
79
68
|
const allowed = Array.from(validButtons).join(', ');
|
|
80
|
-
const children = (0, flat_map_1.flatMap)(node.children, (c) => collectJsxChildren(c, context.sourceCode));
|
|
69
|
+
const children = (0, flat_map_1.flatMap)(node.children, (c) => (0, collect_jsx_children_1.collectJsxChildren)(c, context.sourceCode));
|
|
81
70
|
if (children.length === 0)
|
|
82
71
|
return;
|
|
83
|
-
// Collect seen button types for the segmented mixed-type check.
|
|
72
|
+
// Collect seen button types for the segmented/selection mixed-type check.
|
|
84
73
|
// Populated during the main loop to avoid a second traversal.
|
|
85
|
-
const seenButtonTypes = isSegmented ? new Set() : null;
|
|
74
|
+
const seenButtonTypes = isSegmented || isSelection ? new Set() : null;
|
|
86
75
|
for (const child of children) {
|
|
87
76
|
const name = (0, get_element_name_1.getElementName)(child.openingElement);
|
|
88
77
|
if (name === null)
|
|
@@ -91,7 +80,7 @@ exports.ButtonGroupNoInvalidChildren = utils_1.ESLintUtils.RuleCreator.withoutDo
|
|
|
91
80
|
seenButtonTypes?.add(name);
|
|
92
81
|
continue;
|
|
93
82
|
}
|
|
94
|
-
if (VALID_WRAPPERS.has(name)) {
|
|
83
|
+
if (button_group_constants_1.VALID_WRAPPERS.has(name)) {
|
|
95
84
|
if (name === 'EuiToolTip') {
|
|
96
85
|
// Validate JSX children (expanding fragments/conditionals).
|
|
97
86
|
// Also collects button types for the segmented mixed-type check.
|
|
@@ -106,7 +95,7 @@ exports.ButtonGroupNoInvalidChildren = utils_1.ESLintUtils.RuleCreator.withoutDo
|
|
|
106
95
|
attr.name.type === 'JSXIdentifier' &&
|
|
107
96
|
attr.name.name === 'button');
|
|
108
97
|
if (buttonProp?.value != null) {
|
|
109
|
-
const triggerElements = collectJsxChildren(buttonProp.value, context.sourceCode);
|
|
98
|
+
const triggerElements = (0, collect_jsx_children_1.collectJsxChildren)(buttonProp.value, context.sourceCode);
|
|
110
99
|
for (const triggerElement of triggerElements) {
|
|
111
100
|
if ((0, has_spread_1.hasSpread)(triggerElement.openingElement.attributes))
|
|
112
101
|
continue;
|
|
@@ -119,7 +108,7 @@ exports.ButtonGroupNoInvalidChildren = utils_1.ESLintUtils.RuleCreator.withoutDo
|
|
|
119
108
|
}
|
|
120
109
|
if (triggerElementName === 'EuiToolTip') {
|
|
121
110
|
// EuiToolTip wrapping the trigger — validate its children.
|
|
122
|
-
const tooltipChildren = (0, flat_map_1.flatMap)(triggerElement.children, (c) => collectJsxChildren(c, context.sourceCode));
|
|
111
|
+
const tooltipChildren = (0, flat_map_1.flatMap)(triggerElement.children, (c) => (0, collect_jsx_children_1.collectJsxChildren)(c, context.sourceCode));
|
|
123
112
|
for (const tooltipChild of tooltipChildren) {
|
|
124
113
|
if ((0, has_spread_1.hasSpread)(tooltipChild.openingElement.attributes))
|
|
125
114
|
continue;
|
|
@@ -132,7 +121,8 @@ exports.ButtonGroupNoInvalidChildren = utils_1.ESLintUtils.RuleCreator.withoutDo
|
|
|
132
121
|
}
|
|
133
122
|
context.report({
|
|
134
123
|
node: tooltipChild.openingElement,
|
|
135
|
-
messageId: isCustomComponent(tooltipChildName) &&
|
|
124
|
+
messageId: isCustomComponent(tooltipChildName) &&
|
|
125
|
+
!button_group_constants_1.VALID_BUTTONS.has(tooltipChildName)
|
|
136
126
|
? 'invalidUnresolvablePopoverButton'
|
|
137
127
|
: 'invalidPopoverButton',
|
|
138
128
|
data: { name: tooltipChildName, allowed },
|
|
@@ -142,7 +132,8 @@ exports.ButtonGroupNoInvalidChildren = utils_1.ESLintUtils.RuleCreator.withoutDo
|
|
|
142
132
|
}
|
|
143
133
|
context.report({
|
|
144
134
|
node: triggerElement.openingElement,
|
|
145
|
-
messageId: isCustomComponent(triggerElementName) &&
|
|
135
|
+
messageId: isCustomComponent(triggerElementName) &&
|
|
136
|
+
!button_group_constants_1.VALID_BUTTONS.has(triggerElementName)
|
|
146
137
|
? 'invalidUnresolvablePopoverButton'
|
|
147
138
|
: 'invalidPopoverButton',
|
|
148
139
|
data: { name: triggerElementName, allowed },
|
|
@@ -165,20 +156,21 @@ exports.ButtonGroupNoInvalidChildren = utils_1.ESLintUtils.RuleCreator.withoutDo
|
|
|
165
156
|
continue;
|
|
166
157
|
context.report({
|
|
167
158
|
node: child.openingElement,
|
|
168
|
-
messageId: isCustomComponent(name) && !
|
|
159
|
+
messageId: isCustomComponent(name) && !button_group_constants_1.VALID_BUTTONS.has(name)
|
|
169
160
|
? 'invalidUnresolvableChild'
|
|
170
161
|
: 'invalidChild',
|
|
171
162
|
data: { name, allowed },
|
|
172
163
|
});
|
|
173
164
|
}
|
|
174
|
-
// For segmented, all children must be the same button type —
|
|
175
|
-
// all EuiButton or all EuiButtonIcon. Types are collected during
|
|
176
|
-
// main loop above, including from EuiToolTip, EuiPopover, and EuiCopy.
|
|
165
|
+
// For segmented/selection, all children must be the same button type —
|
|
166
|
+
// either all EuiButton or all EuiButtonIcon. Types are collected during
|
|
167
|
+
// the main loop above, including from EuiToolTip, EuiPopover, and EuiCopy.
|
|
177
168
|
if (seenButtonTypes?.has('EuiButton') &&
|
|
178
169
|
seenButtonTypes.has('EuiButtonIcon')) {
|
|
179
170
|
context.report({
|
|
180
171
|
node: openingElement,
|
|
181
|
-
messageId: '
|
|
172
|
+
messageId: 'invalidMixedTypes',
|
|
173
|
+
data: { variant: isSelection ? 'selection' : 'segmented' },
|
|
182
174
|
});
|
|
183
175
|
}
|
|
184
176
|
},
|
|
@@ -228,8 +220,8 @@ exports.ButtonGroupNoInvalidChildren = utils_1.ESLintUtils.RuleCreator.withoutDo
|
|
|
228
220
|
`with a comment explaining why it renders valid button children:`,
|
|
229
221
|
`// eslint-disable-next-line @elastic/eui/button-group-no-invalid-children -- SaveButton wraps EuiButton`,
|
|
230
222
|
].join(' '),
|
|
231
|
-
|
|
232
|
-
`EuiButtonGroup with variant="
|
|
223
|
+
invalidMixedTypes: [
|
|
224
|
+
`EuiButtonGroup with variant="{{ variant }}" must use a single button type throughout.`,
|
|
233
225
|
`Use either all EuiButton or all EuiButtonIcon children — not both.`,
|
|
234
226
|
].join(' '),
|
|
235
227
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"button_group_no_invalid_children.js","sourceRoot":"","sources":["../../../src/rules/button_group_no_invalid_children.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,oDAIkC;AAClC,oDAAgD;AAChD,gDAA4C;AAC5C,gEAA2D;AAC3D,
|
|
1
|
+
{"version":3,"file":"button_group_no_invalid_children.js","sourceRoot":"","sources":["../../../src/rules/button_group_no_invalid_children.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,oDAIkC;AAClC,oDAAgD;AAChD,gDAA4C;AAC5C,gEAA2D;AAC3D,4DAAwD;AACxD,wEAAmE;AACnE,4EAMyC;AAEzC,MAAM,mBAAmB,GAAG,KAAK,CAAC,IAAI,CAAC,uCAAc,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAElE,SAAS,iBAAiB,CAAC,IAAY;IACrC,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;AAC3C,CAAC;AAED,SAAS,4BAA4B,CAGnC,OAA4B,EAC5B,WAAmB,EACnB,OAAiB,EACjB,YAAyB,EACzB,OAAe,EACf,eAA6B;IAE7B,MAAM,QAAQ,GAAG,IAAA,kBAAO,EAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAC/C,IAAA,yCAAkB,EAAC,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAC1C,CAAC;IACF,KAAK,MAAM,YAAY,IAAI,QAAQ,EAAE,CAAC;QACpC,IAAI,IAAA,sBAAS,EAAC,YAAY,CAAC,cAAc,CAAC,UAAU,CAAC;YAAE,SAAS;QAEhE,MAAM,gBAAgB,GAAG,IAAA,iCAAc,EAAC,YAAY,CAAC,cAAc,CAAC,CAAC;QAErE,IAAI,gBAAgB,KAAK,IAAI;YAAE,SAAS;QAExC,IAAI,YAAY,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAAE,CAAC;YACvC,eAAe,EAAE,GAAG,C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E,4BAA4B;gBAC5B,8GAA8G;aAC/G,CAAC,IAAI,CAAC,GAAG,CAAC;YACX,mBAAmB,EAAE;gBACnB,2EAA2E;gBAC3E,yCAAyC;aAC1C,CAAC,IAAI,CAAC,GAAG,CAAC;YACX,+BAA+B,EAAE;gBAC/B,0FAA0F;gBAC1F,yCAAyC;gBACzC,+EAA+E;gBAC/E,iEAAiE;gBACjE,yGAAyG;aAC1G,CAAC,IAAI,CAAC,GAAG,CAAC;YACX,iBAAiB,EAAE;gBACjB,uFAAuF;gBACvF,oEAAoE;aACrE,CAAC,IAAI,CAAC,GAAG,CAAC;SACZ;KACF;IACD,cAAc,EAAE,EAAE;CACnB,CACF,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
4
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
5
|
+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
6
|
+
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
7
|
+
* Side Public License, v 1.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.ButtonGroupSelectionRequireId = void 0;
|
|
11
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
12
|
+
const has_spread_1 = require("../utils/has_spread");
|
|
13
|
+
const flat_map_1 = require("../utils/flat_map");
|
|
14
|
+
const get_element_name_1 = require("../utils/get_element_name");
|
|
15
|
+
const get_attr_value_1 = require("../utils/get_attr_value");
|
|
16
|
+
const has_meaningful_attr_1 = require("../utils/has_meaningful_attr");
|
|
17
|
+
const collect_jsx_children_1 = require("../utils/collect_jsx_children");
|
|
18
|
+
const button_group_constants_1 = require("../utils/button_group_constants");
|
|
19
|
+
function checkButtonForId(element, context) {
|
|
20
|
+
const name = (0, get_element_name_1.getElementName)(element.openingElement);
|
|
21
|
+
if (name === null || !button_group_constants_1.SELECTION_VALID_BUTTONS.has(name))
|
|
22
|
+
return;
|
|
23
|
+
const { attributes } = element.openingElement;
|
|
24
|
+
if ((0, has_meaningful_attr_1.hasMeaningfulAttr)(element.openingElement, 'id'))
|
|
25
|
+
return;
|
|
26
|
+
if ((0, has_spread_1.hasSpread)(attributes))
|
|
27
|
+
return;
|
|
28
|
+
context.report({
|
|
29
|
+
node: element.openingElement,
|
|
30
|
+
messageId: 'missingId',
|
|
31
|
+
data: { name },
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
exports.ButtonGroupSelectionRequireId = utils_1.ESLintUtils.RuleCreator.withoutDocs({
|
|
35
|
+
create(context) {
|
|
36
|
+
return {
|
|
37
|
+
JSXElement(node) {
|
|
38
|
+
const { openingElement } = node;
|
|
39
|
+
if (openingElement.name.type !== 'JSXIdentifier' ||
|
|
40
|
+
openingElement.name.name !== button_group_constants_1.BUTTON_GROUP) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
// Only validate variant="selection". Dynamic or other variants are skipped.
|
|
44
|
+
const variant = (0, get_attr_value_1.findAttrValue)(context, openingElement.attributes, 'variant');
|
|
45
|
+
if (variant !== 'selection')
|
|
46
|
+
return;
|
|
47
|
+
const children = (0, flat_map_1.flatMap)(node.children, (c) => (0, collect_jsx_children_1.collectJsxChildren)(c, context.sourceCode));
|
|
48
|
+
if (children.length === 0)
|
|
49
|
+
return;
|
|
50
|
+
for (const child of children) {
|
|
51
|
+
const name = (0, get_element_name_1.getElementName)(child.openingElement);
|
|
52
|
+
if (name === null)
|
|
53
|
+
continue;
|
|
54
|
+
if (button_group_constants_1.SELECTION_VALID_BUTTONS.has(name)) {
|
|
55
|
+
checkButtonForId(child, context);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (button_group_constants_1.VALID_WRAPPERS.has(name)) {
|
|
59
|
+
if (name === 'EuiToolTip') {
|
|
60
|
+
const wrapperChildren = (0, flat_map_1.flatMap)(child.children, (c) => (0, collect_jsx_children_1.collectJsxChildren)(c, context.sourceCode));
|
|
61
|
+
for (const wrapperChild of wrapperChildren) {
|
|
62
|
+
checkButtonForId(wrapperChild, context);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else if (name === 'EuiPopover') {
|
|
66
|
+
const buttonProp = child.openingElement.attributes.find((attr) => attr.type === 'JSXAttribute' &&
|
|
67
|
+
attr.name.type === 'JSXIdentifier' &&
|
|
68
|
+
attr.name.name === 'button');
|
|
69
|
+
if (buttonProp?.value != null) {
|
|
70
|
+
const triggerElements = (0, collect_jsx_children_1.collectJsxChildren)(buttonProp.value, context.sourceCode);
|
|
71
|
+
for (const triggerElement of triggerElements) {
|
|
72
|
+
const triggerName = (0, get_element_name_1.getElementName)(triggerElement.openingElement);
|
|
73
|
+
if (triggerName === null)
|
|
74
|
+
continue;
|
|
75
|
+
if (button_group_constants_1.SELECTION_VALID_BUTTONS.has(triggerName)) {
|
|
76
|
+
checkButtonForId(triggerElement, context);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (triggerName === 'EuiToolTip') {
|
|
80
|
+
// EuiToolTip wrapping the popover trigger — check its children.
|
|
81
|
+
const tooltipChildren = (0, flat_map_1.flatMap)(triggerElement.children, (c) => (0, collect_jsx_children_1.collectJsxChildren)(c, context.sourceCode));
|
|
82
|
+
for (const tooltipChild of tooltipChildren) {
|
|
83
|
+
checkButtonForId(tooltipChild, context);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else if (name === 'EuiCopy') {
|
|
90
|
+
// Children is a render prop; walkJsxChildren expands it.
|
|
91
|
+
const wrapperChildren = (0, flat_map_1.flatMap)(child.children, (c) => (0, collect_jsx_children_1.collectJsxChildren)(c, context.sourceCode));
|
|
92
|
+
for (const wrapperChild of wrapperChildren) {
|
|
93
|
+
checkButtonForId(wrapperChild, context);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
// Non-button, non-wrapper children are skipped — the other rule handles those.
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
meta: {
|
|
104
|
+
type: 'problem',
|
|
105
|
+
docs: {
|
|
106
|
+
description: 'Enforce that EuiButtonGroup children have an id prop when variant="selection"',
|
|
107
|
+
},
|
|
108
|
+
schema: [],
|
|
109
|
+
messages: {
|
|
110
|
+
missingId: [
|
|
111
|
+
`{{ name }} inside EuiButtonGroup with variant="selection" is missing a required id prop.`,
|
|
112
|
+
`Each button must have a unique id so the group can track selection state.`,
|
|
113
|
+
].join(' '),
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
defaultOptions: [],
|
|
117
|
+
});
|
|
118
|
+
//# sourceMappingURL=button_group_selection_require_id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"button_group_selection_require_id.js","sourceRoot":"","sources":["../../../src/rules/button_group_selection_require_id.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,oDAIkC;AAClC,oDAAgD;AAChD,gDAA4C;AAC5C,gEAA2D;AAC3D,4DAAwD;AACxD,sEAAiE;AACjE,wEAAmE;AACnE,4EAIyC;AAEzC,SAAS,gBAAgB,CAEvB,OAA4B,EAAE,OAAiB;IAC/C,MAAM,IAAI,GAAG,IAAA,iCAAc,EAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IACpD,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,gDAAuB,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,OAAO;IAEhE,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAC9C,IAAI,IAAA,uCAAiB,EAAC,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC;QAAE,OAAO;IAC5D,IAAI,IAAA,sBAAS,EAAC,UAAU,CAAC;QAAE,OAAO;IAElC,OAAO,CAAC,M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