eslint-plugin-kerfjs 5.0.0-beta.118 → 5.0.0-beta.119
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/docs/rules/ui-wiring.md +2 -0
- package/index.js +1 -1
- package/lib/rules/ui-wiring.js +66 -3
- package/package.json +1 -1
package/docs/rules/ui-wiring.md
CHANGED
|
@@ -18,6 +18,8 @@ For a page-lifetime root helper, declare the actual app entry in the workspace `
|
|
|
18
18
|
|
|
19
19
|
The entry graph then covers a `SearchField` in an imported view without duplicate wiring in that view. Include every independently mounted application entry. The path must resolve through relative imports from each entry to both the view and the helper; merely naming the helper in the profile does not count as invoking it.
|
|
20
20
|
|
|
21
|
+
For `ChoiceChips`, only `multiple={true}` needs `wireChoiceChips`. The default radio group and `multiple="toggle"` use native inputs, so they create no wiring finding. A dynamic `multiple` expression still requires wiring because it may render the listbox mode.
|
|
22
|
+
|
|
21
23
|
Consumer composition catalogs can name an application helper's defining file in `wiring.sources`:
|
|
22
24
|
|
|
23
25
|
```json
|
package/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import uiPublicBoundaries from './lib/rules/ui-public-boundaries.js';
|
|
|
15
15
|
import uiWiring from './lib/rules/ui-wiring.js';
|
|
16
16
|
|
|
17
17
|
const plugin = {
|
|
18
|
-
meta: { name: 'eslint-plugin-kerfjs', version: '5.0.0-beta.
|
|
18
|
+
meta: { name: 'eslint-plugin-kerfjs', version: '5.0.0-beta.119' },
|
|
19
19
|
rules: {
|
|
20
20
|
'no-inline-jsx-event-handlers': noInlineJsxEventHandlers,
|
|
21
21
|
'no-raw-with-dynamic-arg': noRawWithDynamicArg,
|
package/lib/rules/ui-wiring.js
CHANGED
|
@@ -58,6 +58,56 @@ function entryModules(entryFile, currentFile, currentText) {
|
|
|
58
58
|
return modules;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
// Only the listbox mode needs wireChoiceChips. Static radio and toggle groups
|
|
62
|
+
// use native inputs; an expression whose value is unknown still needs wiring.
|
|
63
|
+
function choiceChipsNeedsWiring(attributes) {
|
|
64
|
+
const multiple = attributes.find(
|
|
65
|
+
(attribute) => attribute.name?.name === 'multiple',
|
|
66
|
+
);
|
|
67
|
+
if (!multiple) return false;
|
|
68
|
+
if (!multiple.value) return true;
|
|
69
|
+
if (multiple.value.type === 'Literal')
|
|
70
|
+
return multiple.value.value !== 'toggle';
|
|
71
|
+
const expression = multiple.value.expression;
|
|
72
|
+
if (expression?.type === 'Literal')
|
|
73
|
+
return expression.value !== 'toggle' && expression.value !== false;
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function sourceChoiceChipsNeedsWiring(source, name) {
|
|
78
|
+
const opening = new RegExp(`<${name}(?=[\\s/>])`, 'g');
|
|
79
|
+
for (const match of source.matchAll(opening)) {
|
|
80
|
+
let braces = 0;
|
|
81
|
+
let quote;
|
|
82
|
+
let end = match.index + match[0].length;
|
|
83
|
+
for (; end < source.length; end++) {
|
|
84
|
+
const char = source[end];
|
|
85
|
+
if (quote) {
|
|
86
|
+
if (char === '\\') end++;
|
|
87
|
+
else if (char === quote) quote = undefined;
|
|
88
|
+
} else if (char === '"' || char === "'" || char === '`') quote = char;
|
|
89
|
+
else if (char === '{') braces++;
|
|
90
|
+
else if (char === '}') braces--;
|
|
91
|
+
else if (char === '>' && braces === 0) break;
|
|
92
|
+
}
|
|
93
|
+
if (end === source.length) continue;
|
|
94
|
+
const attributes = source.slice(match.index + match[0].length, end);
|
|
95
|
+
const multiple = attributes.match(
|
|
96
|
+
/(?:^|\s)multiple(?:\s*=\s*(?:\{\s*([^}]*)\s*\}|(["'])(.*?)\2))?(?=\s|\/|$)/,
|
|
97
|
+
);
|
|
98
|
+
if (!multiple) continue;
|
|
99
|
+
if (
|
|
100
|
+
multiple[3] === 'toggle' ||
|
|
101
|
+
multiple[1]?.trim() === "'toggle'" ||
|
|
102
|
+
multiple[1]?.trim() === '"toggle"' ||
|
|
103
|
+
multiple[1]?.trim() === 'false'
|
|
104
|
+
)
|
|
105
|
+
continue;
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
|
|
61
111
|
// The entry graph is read from disk because ESLint visits one source file at a
|
|
62
112
|
// time. Match only imported JSX names; an unrelated local tag cannot satisfy a
|
|
63
113
|
// catalog obligation. The current entry's in-memory text covers editor linting.
|
|
@@ -84,7 +134,12 @@ function moduleUses(source, file, contract) {
|
|
|
84
134
|
if (!match) continue;
|
|
85
135
|
const [, imported, local = imported] = match;
|
|
86
136
|
const key = keyFor(imported);
|
|
87
|
-
if (
|
|
137
|
+
if (
|
|
138
|
+
key &&
|
|
139
|
+
new RegExp(`<${local}(?=[\\s/>])`).test(source) &&
|
|
140
|
+
(key !== '@kerfjs/ui:choice-chips' ||
|
|
141
|
+
sourceChoiceChipsNeedsWiring(source, local))
|
|
142
|
+
)
|
|
88
143
|
uses.add(key);
|
|
89
144
|
}
|
|
90
145
|
const namespace = bindings.match(/\*\s+as\s+(\w+)/)?.[1];
|
|
@@ -97,7 +152,9 @@ function moduleUses(source, file, contract) {
|
|
|
97
152
|
const key = keyFor(name);
|
|
98
153
|
if (
|
|
99
154
|
key &&
|
|
100
|
-
new RegExp(`<${namespace}\\.${name}(?=[\\s/>])`).test(source)
|
|
155
|
+
new RegExp(`<${namespace}\\.${name}(?=[\\s/>])`).test(source) &&
|
|
156
|
+
(key !== '@kerfjs/ui:choice-chips' ||
|
|
157
|
+
sourceChoiceChipsNeedsWiring(source, `${namespace}\\.${name}`))
|
|
101
158
|
)
|
|
102
159
|
uses.add(key);
|
|
103
160
|
}
|
|
@@ -243,7 +300,13 @@ export default {
|
|
|
243
300
|
JSXOpeningElement(node) {
|
|
244
301
|
if (!registry) return;
|
|
245
302
|
const key = jsxKey(node.name, registry, contract);
|
|
246
|
-
if (
|
|
303
|
+
if (
|
|
304
|
+
key &&
|
|
305
|
+
!used.has(key) &&
|
|
306
|
+
(key !== '@kerfjs/ui:choice-chips' ||
|
|
307
|
+
choiceChipsNeedsWiring(node.attributes))
|
|
308
|
+
)
|
|
309
|
+
used.set(key, node.name);
|
|
247
310
|
},
|
|
248
311
|
CallExpression(node) {
|
|
249
312
|
if (!registry) return;
|
package/package.json
CHANGED