@dloizides/frontend-devtools 1.3.0 → 1.5.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/CHANGELOG.md +22 -0
- package/README.md +12 -1
- package/dist/eslint/index.d.mts +6 -1
- package/dist/eslint/index.d.ts +6 -1
- package/dist/eslint/index.js +215 -17
- package/dist/eslint/index.js.map +1 -1
- package/dist/eslint/index.mjs +213 -18
- package/dist/eslint/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/eslint/index.mjs
CHANGED
|
@@ -84,11 +84,27 @@ function removeSuggestion(sourceCode, comment) {
|
|
|
84
84
|
// src/rules/doc-comment-max-lines.js
|
|
85
85
|
var DEFAULT_MAX = 3;
|
|
86
86
|
var DEFAULT_ALLOWED_TAGS = ["param", "returns"];
|
|
87
|
+
var DEFAULT_SUMMARY_MAX_LINES = 1;
|
|
88
|
+
var DEFAULT_LINE_MAX_CHARS = 120;
|
|
89
|
+
var CALL_CHAIN = /(→|->|^Flow\s*:)/i;
|
|
90
|
+
var PARAM_LINE = /^@(param|returns?)\b/i;
|
|
91
|
+
function firstShapeProblem(lines, limits) {
|
|
92
|
+
if (lines.length > limits.max)
|
|
93
|
+
return { messageId: "tooLong", data: { actual: String(lines.length), max: String(limits.max) } };
|
|
94
|
+
if (lines.some((line) => CALL_CHAIN.test(line))) return { messageId: "callChain", data: {} };
|
|
95
|
+
const summary = lines.filter((line) => !PARAM_LINE.test(line)).length;
|
|
96
|
+
if (summary > limits.summaryMaxLines)
|
|
97
|
+
return { messageId: "summaryTooLong", data: { actual: String(summary), max: String(limits.summaryMaxLines) } };
|
|
98
|
+
const long = lines.find((line) => line.length > limits.lineMaxChars);
|
|
99
|
+
if (long !== void 0)
|
|
100
|
+
return { messageId: "lineTooLong", data: { actual: String(long.length), max: String(limits.lineMaxChars) } };
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
87
103
|
var docCommentMaxLinesRule = {
|
|
88
104
|
meta: {
|
|
89
105
|
type: "suggestion",
|
|
90
106
|
docs: {
|
|
91
|
-
description: "Cap a doc comment at a few lines and
|
|
107
|
+
description: "Cap a doc comment at a few lines, a one-line summary with no call chain, and only @param / @returns tags (RV-1, D-CMT-3, D-CMT-4)"
|
|
92
108
|
},
|
|
93
109
|
schema: [
|
|
94
110
|
{
|
|
@@ -96,20 +112,29 @@ var docCommentMaxLinesRule = {
|
|
|
96
112
|
properties: {
|
|
97
113
|
max: { type: "integer", minimum: 1 },
|
|
98
114
|
allowedTags: { type: "array", items: { type: "string" } },
|
|
99
|
-
bannedTags: { type: "array", items: { type: "string" } }
|
|
115
|
+
bannedTags: { type: "array", items: { type: "string" } },
|
|
116
|
+
summaryMaxLines: { type: "integer", minimum: 1 },
|
|
117
|
+
lineMaxChars: { type: "integer", minimum: 1 }
|
|
100
118
|
},
|
|
101
119
|
additionalProperties: false
|
|
102
120
|
}
|
|
103
121
|
],
|
|
104
122
|
messages: {
|
|
105
123
|
tooLong: "RV-1: doc comment is {{actual}} lines; the cap is {{max}}.",
|
|
106
|
-
bannedTag: "RV-1: @{{tag}} is not allowed in a doc comment (allowed: {{allowed}})."
|
|
124
|
+
bannedTag: "RV-1: @{{tag}} is not allowed in a doc comment (allowed: {{allowed}}).",
|
|
125
|
+
summaryTooLong: "RV-1: doc summary is {{actual}} lines; it must be one line saying what the member is for.",
|
|
126
|
+
callChain: "RV-1: no call chain or Flow: in a doc comment; say what the member is for, not how it runs.",
|
|
127
|
+
lineTooLong: "RV-1: doc line is {{actual}} chars; the cap is {{max}}."
|
|
107
128
|
}
|
|
108
129
|
},
|
|
109
130
|
create(context) {
|
|
110
131
|
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
111
132
|
const options = context.options[0] ?? {};
|
|
112
|
-
const
|
|
133
|
+
const limits = {
|
|
134
|
+
max: options.max ?? DEFAULT_MAX,
|
|
135
|
+
summaryMaxLines: options.summaryMaxLines ?? DEFAULT_SUMMARY_MAX_LINES,
|
|
136
|
+
lineMaxChars: options.lineMaxChars ?? DEFAULT_LINE_MAX_CHARS
|
|
137
|
+
};
|
|
113
138
|
const allowed = new Set(options.allowedTags ?? DEFAULT_ALLOWED_TAGS);
|
|
114
139
|
for (const tag of options.bannedTags ?? []) allowed.delete(tag);
|
|
115
140
|
const allowedText = [...allowed].map((tag) => `@${tag}`).join(", ") || "none";
|
|
@@ -118,19 +143,12 @@ var docCommentMaxLinesRule = {
|
|
|
118
143
|
for (const comment of sourceCode.getAllComments()) {
|
|
119
144
|
if (!isDocBlock(comment) || isTypeAnnotationDoc(comment)) continue;
|
|
120
145
|
const lines = docBodyLines(comment);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
for (const tag of blockTags(lines))
|
|
128
|
-
if (!allowed.has(tag))
|
|
129
|
-
context.report({
|
|
130
|
-
loc: comment.loc,
|
|
131
|
-
messageId: "bannedTag",
|
|
132
|
-
data: { tag, allowed: allowedText }
|
|
133
|
-
});
|
|
146
|
+
const banned = blockTags(lines).filter((tag) => !allowed.has(tag));
|
|
147
|
+
for (const tag of banned)
|
|
148
|
+
context.report({ loc: comment.loc, messageId: "bannedTag", data: { tag, allowed: allowedText } });
|
|
149
|
+
if (banned.length > 0) continue;
|
|
150
|
+
const problem = firstShapeProblem(lines, limits);
|
|
151
|
+
if (problem) context.report({ loc: comment.loc, ...problem });
|
|
134
152
|
}
|
|
135
153
|
}
|
|
136
154
|
};
|
|
@@ -2121,6 +2139,171 @@ var require_stable_hook_args_default = {
|
|
|
2121
2139
|
}
|
|
2122
2140
|
};
|
|
2123
2141
|
|
|
2142
|
+
// src/rules/single-row-action-source.js
|
|
2143
|
+
var UI_BUTTONS_MODULE = "@dloizides/ui-buttons";
|
|
2144
|
+
var GROUP_NAME = "RowActionGroup";
|
|
2145
|
+
var ACTIONS_PROP = "actions";
|
|
2146
|
+
var SPEC_TYPE = "RowActionSpec";
|
|
2147
|
+
var MEMO_HOOKS = /* @__PURE__ */ new Set(["useMemo", "useCallback"]);
|
|
2148
|
+
var MAX_DEPTH = 8;
|
|
2149
|
+
var Source = Object.freeze({ LOCAL: "local", EXTERNAL: "external" });
|
|
2150
|
+
function getScopeFor(context, node) {
|
|
2151
|
+
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
2152
|
+
if (typeof sourceCode.getScope === "function") return sourceCode.getScope(node);
|
|
2153
|
+
return context.getScope();
|
|
2154
|
+
}
|
|
2155
|
+
function findVariable(scope, name) {
|
|
2156
|
+
let current = scope;
|
|
2157
|
+
while (current) {
|
|
2158
|
+
const found = current.set.get(name);
|
|
2159
|
+
if (found) return found;
|
|
2160
|
+
current = current.upper;
|
|
2161
|
+
}
|
|
2162
|
+
return void 0;
|
|
2163
|
+
}
|
|
2164
|
+
function rootIdentifier(node) {
|
|
2165
|
+
let current = node;
|
|
2166
|
+
while (current && current.type === "MemberExpression") current = current.object;
|
|
2167
|
+
return current && current.type === "Identifier" ? current : void 0;
|
|
2168
|
+
}
|
|
2169
|
+
function calleeName(callee) {
|
|
2170
|
+
if (callee.type === "Identifier") return callee.name;
|
|
2171
|
+
if (callee.type === "MemberExpression" && callee.property.type === "Identifier") return callee.property.name;
|
|
2172
|
+
return void 0;
|
|
2173
|
+
}
|
|
2174
|
+
function isSpecArrayType(annotation) {
|
|
2175
|
+
const type = annotation && annotation.typeAnnotation;
|
|
2176
|
+
if (!type) return false;
|
|
2177
|
+
const isSpecRef = (ref) => ref && ref.type === "TSTypeReference" && ref.typeName.name === SPEC_TYPE;
|
|
2178
|
+
if (type.type === "TSArrayType") return isSpecRef(type.elementType);
|
|
2179
|
+
if (type.type === "TSTypeOperator") return type.typeAnnotation.type === "TSArrayType" && isSpecRef(type.typeAnnotation.elementType);
|
|
2180
|
+
const params = type.typeParameters && type.typeParameters.params;
|
|
2181
|
+
return type.type === "TSTypeReference" && params !== void 0 && params.some(isSpecRef);
|
|
2182
|
+
}
|
|
2183
|
+
function returnedExpressions(fn) {
|
|
2184
|
+
if (fn.body.type !== "BlockStatement") return [fn.body];
|
|
2185
|
+
const found = [];
|
|
2186
|
+
const visit = (node) => {
|
|
2187
|
+
if (!node || typeof node.type !== "string") return;
|
|
2188
|
+
if (node.type === "ReturnStatement") {
|
|
2189
|
+
if (node.argument) found.push(node.argument);
|
|
2190
|
+
return;
|
|
2191
|
+
}
|
|
2192
|
+
if (node.type.includes("Function")) return;
|
|
2193
|
+
for (const key of Object.keys(node)) {
|
|
2194
|
+
if (key === "parent") continue;
|
|
2195
|
+
const child = node[key];
|
|
2196
|
+
if (Array.isArray(child)) child.forEach(visit);
|
|
2197
|
+
else if (child && typeof child.type === "string") visit(child);
|
|
2198
|
+
}
|
|
2199
|
+
};
|
|
2200
|
+
fn.body.body.forEach(visit);
|
|
2201
|
+
return found;
|
|
2202
|
+
}
|
|
2203
|
+
function isFunctionNode(node) {
|
|
2204
|
+
return node && (node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression" || node.type === "FunctionDeclaration");
|
|
2205
|
+
}
|
|
2206
|
+
function createClassifier(context) {
|
|
2207
|
+
const anyLocal = (nodes, depth, seen) => nodes.some((n) => classify(n, depth, seen) === Source.LOCAL);
|
|
2208
|
+
function classifyVariable(variable, depth, seen) {
|
|
2209
|
+
if (seen.has(variable)) return Source.EXTERNAL;
|
|
2210
|
+
seen.add(variable);
|
|
2211
|
+
const def = variable.defs[0];
|
|
2212
|
+
if (!def) return Source.EXTERNAL;
|
|
2213
|
+
if (def.type === "ImportBinding" || def.type === "Parameter") return Source.EXTERNAL;
|
|
2214
|
+
if (def.type === "FunctionName") return Source.LOCAL;
|
|
2215
|
+
if (def.type !== "Variable" || def.node.id.type !== "Identifier") return Source.EXTERNAL;
|
|
2216
|
+
const writes = variable.references.filter((ref) => ref.isWrite() && ref.writeExpr).map((ref) => ref.writeExpr);
|
|
2217
|
+
if (writes.length === 0) return isSpecArrayType(def.node.id.typeAnnotation) ? Source.LOCAL : Source.EXTERNAL;
|
|
2218
|
+
return anyLocal(writes, depth + 1, seen) ? Source.LOCAL : Source.EXTERNAL;
|
|
2219
|
+
}
|
|
2220
|
+
function classifyCall(node, depth, seen) {
|
|
2221
|
+
const name = calleeName(node.callee);
|
|
2222
|
+
if (MEMO_HOOKS.has(name) && isFunctionNode(node.arguments[0])) {
|
|
2223
|
+
return anyLocal(returnedExpressions(node.arguments[0]), depth + 1, seen) ? Source.LOCAL : Source.EXTERNAL;
|
|
2224
|
+
}
|
|
2225
|
+
const root = rootIdentifier(node.callee);
|
|
2226
|
+
if (!root) return Source.EXTERNAL;
|
|
2227
|
+
const variable = findVariable(getScopeFor(context, node), root.name);
|
|
2228
|
+
if (!variable || variable.defs.length === 0) return Source.EXTERNAL;
|
|
2229
|
+
const def = variable.defs[0];
|
|
2230
|
+
if (def.type === "ImportBinding" || def.type === "Parameter") return Source.EXTERNAL;
|
|
2231
|
+
if (def.type === "FunctionName") return Source.LOCAL;
|
|
2232
|
+
const init = def.node.init;
|
|
2233
|
+
if (isFunctionNode(init)) return Source.LOCAL;
|
|
2234
|
+
return classifyVariable(variable, depth, seen);
|
|
2235
|
+
}
|
|
2236
|
+
function classify(node, depth, seen) {
|
|
2237
|
+
if (!node || depth > MAX_DEPTH) return Source.EXTERNAL;
|
|
2238
|
+
switch (node.type) {
|
|
2239
|
+
case "ArrayExpression":
|
|
2240
|
+
return Source.LOCAL;
|
|
2241
|
+
case "TSAsExpression":
|
|
2242
|
+
case "TSSatisfiesExpression":
|
|
2243
|
+
case "TSNonNullExpression":
|
|
2244
|
+
return classify(node.expression, depth + 1, seen);
|
|
2245
|
+
case "ConditionalExpression":
|
|
2246
|
+
return anyLocal([node.consequent, node.alternate], depth + 1, seen) ? Source.LOCAL : Source.EXTERNAL;
|
|
2247
|
+
case "LogicalExpression":
|
|
2248
|
+
return anyLocal([node.left, node.right], depth + 1, seen) ? Source.LOCAL : Source.EXTERNAL;
|
|
2249
|
+
case "CallExpression":
|
|
2250
|
+
return classifyCall(node, depth, seen);
|
|
2251
|
+
case "Identifier": {
|
|
2252
|
+
const variable = findVariable(getScopeFor(context, node), node.name);
|
|
2253
|
+
return variable ? classifyVariable(variable, depth, seen) : Source.EXTERNAL;
|
|
2254
|
+
}
|
|
2255
|
+
default:
|
|
2256
|
+
return Source.EXTERNAL;
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
return (node) => classify(node, 0, /* @__PURE__ */ new Set());
|
|
2260
|
+
}
|
|
2261
|
+
function groupNameMatcher(imports) {
|
|
2262
|
+
return (nameNode) => {
|
|
2263
|
+
if (nameNode.type === "JSXIdentifier") return imports.named.has(nameNode.name);
|
|
2264
|
+
const isNamespaceMember = nameNode.type === "JSXMemberExpression" && nameNode.object.type === "JSXIdentifier" && imports.namespaces.has(nameNode.object.name);
|
|
2265
|
+
return isNamespaceMember && nameNode.property.name === GROUP_NAME;
|
|
2266
|
+
};
|
|
2267
|
+
}
|
|
2268
|
+
var singleRowActionSourceRule = {
|
|
2269
|
+
meta: {
|
|
2270
|
+
type: "problem",
|
|
2271
|
+
docs: {
|
|
2272
|
+
description: "RowActionGroup actions must come from a shared defineRowActions set, never a locally built array",
|
|
2273
|
+
recommended: true
|
|
2274
|
+
},
|
|
2275
|
+
schema: [],
|
|
2276
|
+
messages: {
|
|
2277
|
+
localRowActions: "Build row actions once per entity with defineRowActions in a *RowActions module; tables may only omit with a reason."
|
|
2278
|
+
}
|
|
2279
|
+
},
|
|
2280
|
+
create(context) {
|
|
2281
|
+
const imports = { named: /* @__PURE__ */ new Set(), namespaces: /* @__PURE__ */ new Set() };
|
|
2282
|
+
const isGroup = groupNameMatcher(imports);
|
|
2283
|
+
const classify = createClassifier(context);
|
|
2284
|
+
return {
|
|
2285
|
+
ImportDeclaration(node) {
|
|
2286
|
+
if (node.source.value !== UI_BUTTONS_MODULE) return;
|
|
2287
|
+
for (const spec of node.specifiers) {
|
|
2288
|
+
if (spec.type === "ImportNamespaceSpecifier") imports.namespaces.add(spec.local.name);
|
|
2289
|
+
else if (spec.type === "ImportSpecifier" && spec.imported.name === GROUP_NAME) imports.named.add(spec.local.name);
|
|
2290
|
+
}
|
|
2291
|
+
},
|
|
2292
|
+
JSXOpeningElement(node) {
|
|
2293
|
+
if (!isGroup(node.name)) return;
|
|
2294
|
+
const attr = node.attributes.find((a) => a.type === "JSXAttribute" && a.name.name === ACTIONS_PROP);
|
|
2295
|
+
if (!attr || !attr.value || attr.value.type !== "JSXExpressionContainer") return;
|
|
2296
|
+
if (classify(attr.value.expression) === Source.LOCAL) context.report({ node: attr, messageId: "localRowActions" });
|
|
2297
|
+
}
|
|
2298
|
+
};
|
|
2299
|
+
}
|
|
2300
|
+
};
|
|
2301
|
+
var single_row_action_source_default = {
|
|
2302
|
+
rules: {
|
|
2303
|
+
"single-row-action-source": singleRowActionSourceRule
|
|
2304
|
+
}
|
|
2305
|
+
};
|
|
2306
|
+
|
|
2124
2307
|
// src/rules/smart-max-lines.js
|
|
2125
2308
|
var COMPONENT_MAX_DEFAULT = 200;
|
|
2126
2309
|
var FUNCTION_MAX_DEFAULT = 50;
|
|
@@ -2392,6 +2575,7 @@ var ruleModules = [
|
|
|
2392
2575
|
no_raw_color_literal_default,
|
|
2393
2576
|
prefer_const_enum_default,
|
|
2394
2577
|
require_stable_hook_args_default,
|
|
2578
|
+
single_row_action_source_default,
|
|
2395
2579
|
smart_max_lines_default
|
|
2396
2580
|
];
|
|
2397
2581
|
function mergeRules(modules) {
|
|
@@ -2444,7 +2628,18 @@ var commentsConfig = {
|
|
|
2444
2628
|
"@dloizides/doc-comment-max-lines": ["error", { max: DOC_COMMENT_MAX_LINES }]
|
|
2445
2629
|
}
|
|
2446
2630
|
};
|
|
2631
|
+
var ROW_ACTION_RULE_NAMES = ["single-row-action-source"];
|
|
2632
|
+
var rowActionsConfig = {
|
|
2633
|
+
plugins: commentsConfig.plugins,
|
|
2634
|
+
rules: {
|
|
2635
|
+
"@dloizides/single-row-action-source": "error"
|
|
2636
|
+
}
|
|
2637
|
+
};
|
|
2638
|
+
var recommendedConfig = {
|
|
2639
|
+
plugins: commentsConfig.plugins,
|
|
2640
|
+
rules: { ...commentsConfig.rules, ...rowActionsConfig.rules }
|
|
2641
|
+
};
|
|
2447
2642
|
|
|
2448
|
-
export { COMMENT_RULE_NAMES, commentsConfig, legacyPlugins, plugin, ruleNames, rules };
|
|
2643
|
+
export { COMMENT_RULE_NAMES, ROW_ACTION_RULE_NAMES, commentsConfig, legacyPlugins, plugin, recommendedConfig, rowActionsConfig, ruleNames, rules };
|
|
2449
2644
|
//# sourceMappingURL=index.mjs.map
|
|
2450
2645
|
//# sourceMappingURL=index.mjs.map
|