@dloizides/frontend-devtools 1.2.0 → 1.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.
- package/CHANGELOG.md +29 -0
- package/dist/eslint/index.d.mts +5 -1
- package/dist/eslint/index.d.ts +5 -1
- package/dist/eslint/index.js +346 -0
- package/dist/eslint/index.js.map +1 -1
- package/dist/eslint/index.mjs +345 -1
- package/dist/eslint/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/eslint/index.mjs
CHANGED
|
@@ -1,6 +1,292 @@
|
|
|
1
1
|
import fs, { existsSync, readdirSync } from 'fs';
|
|
2
2
|
import path, { basename, dirname, sep, posix, join } from 'path';
|
|
3
3
|
|
|
4
|
+
// src/rules/comment-utils.js
|
|
5
|
+
var DIRECTIVE_PATTERNS = [
|
|
6
|
+
/^\s*eslint(-disable|-enable|-env)?(-next-line|-line)?(\s|$)/,
|
|
7
|
+
/^\s*eslint\s/,
|
|
8
|
+
/^\s*globals?\s/,
|
|
9
|
+
/^\s*exported\s/,
|
|
10
|
+
/^\s*@ts-(expect-error|ignore|nocheck|check)\b/,
|
|
11
|
+
/^\s*prettier-ignore\b/,
|
|
12
|
+
/^\s*(istanbul|c8|v8)\s+ignore\b/,
|
|
13
|
+
/^\s*webpack[A-Z]\w*\s*:/,
|
|
14
|
+
/^\s*@vite-ignore\b/,
|
|
15
|
+
/^\s*[#@]__(PURE|NO_SIDE_EFFECTS)__\s*$/,
|
|
16
|
+
/^\s*@(jest|vitest)-environment\b/,
|
|
17
|
+
/^\s*jscpd:/,
|
|
18
|
+
/^\s*biome-ignore\b/,
|
|
19
|
+
/^\/\s*<(reference|amd-module)\b/
|
|
20
|
+
];
|
|
21
|
+
var JSDOC_TYPE_TAGS = /* @__PURE__ */ new Set([
|
|
22
|
+
"type",
|
|
23
|
+
"typedef",
|
|
24
|
+
"satisfies",
|
|
25
|
+
"import",
|
|
26
|
+
"callback",
|
|
27
|
+
"template",
|
|
28
|
+
"property",
|
|
29
|
+
"jsx",
|
|
30
|
+
"jsxImportSource",
|
|
31
|
+
"jsxFrag",
|
|
32
|
+
"jsxRuntime"
|
|
33
|
+
]);
|
|
34
|
+
var BLOCK_TAG = /^@([A-Za-z][\w-]*)/;
|
|
35
|
+
function isDocBlock(comment) {
|
|
36
|
+
return comment.type === "Block" && comment.value.startsWith("*") && comment.value !== "*";
|
|
37
|
+
}
|
|
38
|
+
function docBodyLines(comment) {
|
|
39
|
+
return comment.value.slice(1).split(/\r?\n/).map((line) => line.trim().replace(/^\*+\s?/, "").trim()).filter((line) => line.length > 0);
|
|
40
|
+
}
|
|
41
|
+
function blockTags(lines) {
|
|
42
|
+
const tags = [];
|
|
43
|
+
for (const line of lines) {
|
|
44
|
+
const match = BLOCK_TAG.exec(line);
|
|
45
|
+
if (match) tags.push(match[1]);
|
|
46
|
+
}
|
|
47
|
+
return tags;
|
|
48
|
+
}
|
|
49
|
+
function isTypeAnnotationDoc(comment) {
|
|
50
|
+
if (!isDocBlock(comment)) return false;
|
|
51
|
+
const lines = docBodyLines(comment);
|
|
52
|
+
if (lines.length === 0) return false;
|
|
53
|
+
const allTagged = lines.every((line) => BLOCK_TAG.test(line));
|
|
54
|
+
const tags = blockTags(lines);
|
|
55
|
+
return allTagged && tags.every((tag) => JSDOC_TYPE_TAGS.has(tag));
|
|
56
|
+
}
|
|
57
|
+
function compileAllow(allow) {
|
|
58
|
+
return (allow ?? []).map((source) => new RegExp(source));
|
|
59
|
+
}
|
|
60
|
+
function isDirective(comment, extraPatterns) {
|
|
61
|
+
if (comment.type === "Shebang") return true;
|
|
62
|
+
const patterns = extraPatterns ? DIRECTIVE_PATTERNS.concat(extraPatterns) : DIRECTIVE_PATTERNS;
|
|
63
|
+
return patterns.some((pattern) => pattern.test(comment.value));
|
|
64
|
+
}
|
|
65
|
+
function removalRange(sourceCode, comment) {
|
|
66
|
+
const text = sourceCode.text;
|
|
67
|
+
let start = comment.range[0];
|
|
68
|
+
let end = comment.range[1];
|
|
69
|
+
while (start > 0 && (text[start - 1] === " " || text[start - 1] === " ")) start--;
|
|
70
|
+
const ownLine = start === 0 || text[start - 1] === "\n";
|
|
71
|
+
if (ownLine) {
|
|
72
|
+
if (text[end] === "\r") end++;
|
|
73
|
+
if (text[end] === "\n") end++;
|
|
74
|
+
}
|
|
75
|
+
return [start, end];
|
|
76
|
+
}
|
|
77
|
+
function removeSuggestion(sourceCode, comment) {
|
|
78
|
+
return {
|
|
79
|
+
messageId: "removeComment",
|
|
80
|
+
fix: (fixer) => fixer.removeRange(removalRange(sourceCode, comment))
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// src/rules/doc-comment-max-lines.js
|
|
85
|
+
var DEFAULT_MAX = 3;
|
|
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
|
+
}
|
|
103
|
+
var docCommentMaxLinesRule = {
|
|
104
|
+
meta: {
|
|
105
|
+
type: "suggestion",
|
|
106
|
+
docs: {
|
|
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)"
|
|
108
|
+
},
|
|
109
|
+
schema: [
|
|
110
|
+
{
|
|
111
|
+
type: "object",
|
|
112
|
+
properties: {
|
|
113
|
+
max: { type: "integer", minimum: 1 },
|
|
114
|
+
allowedTags: { type: "array", items: { type: "string" } },
|
|
115
|
+
bannedTags: { type: "array", items: { type: "string" } },
|
|
116
|
+
summaryMaxLines: { type: "integer", minimum: 1 },
|
|
117
|
+
lineMaxChars: { type: "integer", minimum: 1 }
|
|
118
|
+
},
|
|
119
|
+
additionalProperties: false
|
|
120
|
+
}
|
|
121
|
+
],
|
|
122
|
+
messages: {
|
|
123
|
+
tooLong: "RV-1: doc comment is {{actual}} lines; the cap is {{max}}.",
|
|
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}}."
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
create(context) {
|
|
131
|
+
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
132
|
+
const options = context.options[0] ?? {};
|
|
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
|
+
};
|
|
138
|
+
const allowed = new Set(options.allowedTags ?? DEFAULT_ALLOWED_TAGS);
|
|
139
|
+
for (const tag of options.bannedTags ?? []) allowed.delete(tag);
|
|
140
|
+
const allowedText = [...allowed].map((tag) => `@${tag}`).join(", ") || "none";
|
|
141
|
+
return {
|
|
142
|
+
Program() {
|
|
143
|
+
for (const comment of sourceCode.getAllComments()) {
|
|
144
|
+
if (!isDocBlock(comment) || isTypeAnnotationDoc(comment)) continue;
|
|
145
|
+
const lines = docBodyLines(comment);
|
|
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 });
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
var doc_comment_max_lines_default = { rules: { "doc-comment-max-lines": docCommentMaxLinesRule } };
|
|
158
|
+
|
|
159
|
+
// src/rules/doc-comment-public-only.js
|
|
160
|
+
var EXPORT_TYPES = /* @__PURE__ */ new Set([
|
|
161
|
+
"ExportNamedDeclaration",
|
|
162
|
+
"ExportDefaultDeclaration",
|
|
163
|
+
"ExportAllDeclaration",
|
|
164
|
+
"TSExportAssignment"
|
|
165
|
+
]);
|
|
166
|
+
var PASS_THROUGH = /* @__PURE__ */ new Set([
|
|
167
|
+
"MethodDefinition",
|
|
168
|
+
"PropertyDefinition",
|
|
169
|
+
"AccessorProperty",
|
|
170
|
+
"TSAbstractMethodDefinition",
|
|
171
|
+
"TSAbstractPropertyDefinition",
|
|
172
|
+
"TSAbstractAccessorProperty",
|
|
173
|
+
"TSIndexSignature",
|
|
174
|
+
"ClassBody",
|
|
175
|
+
"ClassDeclaration",
|
|
176
|
+
"ClassExpression",
|
|
177
|
+
"TSInterfaceBody",
|
|
178
|
+
"TSInterfaceDeclaration",
|
|
179
|
+
"TSPropertySignature",
|
|
180
|
+
"TSMethodSignature",
|
|
181
|
+
"TSTypeLiteral",
|
|
182
|
+
"TSTypeAnnotation",
|
|
183
|
+
"TSTypeAliasDeclaration",
|
|
184
|
+
"TSIntersectionType",
|
|
185
|
+
"TSUnionType",
|
|
186
|
+
"TSEnumDeclaration",
|
|
187
|
+
"TSEnumBody",
|
|
188
|
+
"TSEnumMember",
|
|
189
|
+
"TSModuleBlock",
|
|
190
|
+
"TSModuleDeclaration",
|
|
191
|
+
"TSDeclareFunction",
|
|
192
|
+
"VariableDeclaration",
|
|
193
|
+
"VariableDeclarator",
|
|
194
|
+
"ObjectExpression",
|
|
195
|
+
"Property",
|
|
196
|
+
"TSAsExpression",
|
|
197
|
+
"TSSatisfiesExpression"
|
|
198
|
+
]);
|
|
199
|
+
var HIDDEN_ACCESSIBILITY = /* @__PURE__ */ new Set(["private", "protected"]);
|
|
200
|
+
function isHiddenMember(node) {
|
|
201
|
+
if (HIDDEN_ACCESSIBILITY.has(node.accessibility)) return true;
|
|
202
|
+
return node.key?.type === "PrivateIdentifier";
|
|
203
|
+
}
|
|
204
|
+
function isAmbientModule(node) {
|
|
205
|
+
return node.type === "TSModuleDeclaration" && (node.declare === true || node.global === true);
|
|
206
|
+
}
|
|
207
|
+
function isNamed(node, name) {
|
|
208
|
+
return node?.type === "Identifier" && node.name === name;
|
|
209
|
+
}
|
|
210
|
+
function isCommonJsExport(node) {
|
|
211
|
+
if (node.type !== "ExpressionStatement") return false;
|
|
212
|
+
const expr = node.expression;
|
|
213
|
+
if (expr.type !== "AssignmentExpression" || expr.left.type !== "MemberExpression") return false;
|
|
214
|
+
const target = expr.left.object;
|
|
215
|
+
const isModuleExports = isNamed(target, "module") && isNamed(expr.left.property, "exports");
|
|
216
|
+
const isModuleExportsMember = target.type === "MemberExpression" && isNamed(target.object, "module") && isNamed(target.property, "exports");
|
|
217
|
+
return isNamed(target, "exports") || isModuleExports || isModuleExportsMember;
|
|
218
|
+
}
|
|
219
|
+
function declaredNames(node) {
|
|
220
|
+
if (node.type === "VariableDeclaration")
|
|
221
|
+
return node.declarations.filter((d) => d.id.type === "Identifier").map((d) => d.id.name);
|
|
222
|
+
if (node.id?.type === "Identifier") return [node.id.name];
|
|
223
|
+
return [];
|
|
224
|
+
}
|
|
225
|
+
function collectExportedNames(program) {
|
|
226
|
+
const names = /* @__PURE__ */ new Set();
|
|
227
|
+
for (const statement of program.body) {
|
|
228
|
+
if (statement.type === "ExportNamedDeclaration" && !statement.source) {
|
|
229
|
+
for (const spec of statement.specifiers) if (spec.local.type === "Identifier") names.add(spec.local.name);
|
|
230
|
+
}
|
|
231
|
+
if (statement.type === "ExportDefaultDeclaration" && statement.declaration.type === "Identifier")
|
|
232
|
+
names.add(statement.declaration.name);
|
|
233
|
+
if (statement.type === "TSExportAssignment" && statement.expression.type === "Identifier")
|
|
234
|
+
names.add(statement.expression.name);
|
|
235
|
+
}
|
|
236
|
+
return names;
|
|
237
|
+
}
|
|
238
|
+
function isTopLevelPublic(node, exportedNames) {
|
|
239
|
+
if (EXPORT_TYPES.has(node.type) || isAmbientModule(node) || isCommonJsExport(node)) return true;
|
|
240
|
+
return declaredNames(node).some((name) => exportedNames.has(name));
|
|
241
|
+
}
|
|
242
|
+
function isPublic(start, exportedNames) {
|
|
243
|
+
let current = start;
|
|
244
|
+
while (current.parent && current.parent.type !== "Program") {
|
|
245
|
+
if (isHiddenMember(current)) return false;
|
|
246
|
+
const parent = current.parent;
|
|
247
|
+
if (EXPORT_TYPES.has(parent.type) || isAmbientModule(parent)) return true;
|
|
248
|
+
if (!PASS_THROUGH.has(parent.type)) return false;
|
|
249
|
+
current = parent;
|
|
250
|
+
}
|
|
251
|
+
if (isHiddenMember(current)) return false;
|
|
252
|
+
return isTopLevelPublic(current, exportedNames);
|
|
253
|
+
}
|
|
254
|
+
function documentedNode(sourceCode, comment) {
|
|
255
|
+
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
256
|
+
if (!token) return null;
|
|
257
|
+
let node = sourceCode.getNodeByRangeIndex(token.range[0]);
|
|
258
|
+
while (node?.parent && node.parent.type !== "Program" && node.parent.range[0] === node.range[0])
|
|
259
|
+
node = node.parent;
|
|
260
|
+
return node && node.type !== "Program" ? node : null;
|
|
261
|
+
}
|
|
262
|
+
var docCommentPublicOnlyRule = {
|
|
263
|
+
meta: {
|
|
264
|
+
type: "suggestion",
|
|
265
|
+
docs: {
|
|
266
|
+
description: "Allow a doc comment only on an exported declaration or a public member of one (RV-1)"
|
|
267
|
+
},
|
|
268
|
+
schema: [],
|
|
269
|
+
messages: {
|
|
270
|
+
notPublic: "RV-1: a doc comment is allowed only on an exported declaration or a public member of one. Move the intent into the name."
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
create(context) {
|
|
274
|
+
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
275
|
+
return {
|
|
276
|
+
Program(program) {
|
|
277
|
+
const exportedNames = collectExportedNames(program);
|
|
278
|
+
for (const comment of sourceCode.getAllComments()) {
|
|
279
|
+
if (!isDocBlock(comment) || isTypeAnnotationDoc(comment)) continue;
|
|
280
|
+
const node = documentedNode(sourceCode, comment);
|
|
281
|
+
if (node && isPublic(node, exportedNames)) continue;
|
|
282
|
+
context.report({ loc: comment.loc, messageId: "notPublic" });
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
var doc_comment_public_only_default = { rules: { "doc-comment-public-only": docCommentPublicOnlyRule } };
|
|
289
|
+
|
|
4
290
|
// src/rules/enforce-function-style.js
|
|
5
291
|
function isJSX(node) {
|
|
6
292
|
return node && (node.type === "JSXElement" || node.type === "JSXFragment");
|
|
@@ -854,6 +1140,45 @@ var i18n_param_names_default = {
|
|
|
854
1140
|
"i18n-param-names": rule2
|
|
855
1141
|
}
|
|
856
1142
|
};
|
|
1143
|
+
|
|
1144
|
+
// src/rules/no-comments.js
|
|
1145
|
+
var noCommentsRule = {
|
|
1146
|
+
meta: {
|
|
1147
|
+
type: "suggestion",
|
|
1148
|
+
hasSuggestions: true,
|
|
1149
|
+
docs: {
|
|
1150
|
+
description: "Disallow code comments: intent goes in names, rules in test names, context in the task doc and commit (RV-2)"
|
|
1151
|
+
},
|
|
1152
|
+
schema: [
|
|
1153
|
+
{
|
|
1154
|
+
type: "object",
|
|
1155
|
+
properties: { allow: { type: "array", items: { type: "string" } } },
|
|
1156
|
+
additionalProperties: false
|
|
1157
|
+
}
|
|
1158
|
+
],
|
|
1159
|
+
messages: {
|
|
1160
|
+
noComment: "RV-2: no code comments. Put intent in names, business rules in test names, context in the task doc or commit message.",
|
|
1161
|
+
removeComment: "Remove this comment."
|
|
1162
|
+
}
|
|
1163
|
+
},
|
|
1164
|
+
create(context) {
|
|
1165
|
+
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
1166
|
+
const extra = compileAllow(context.options[0]?.allow);
|
|
1167
|
+
return {
|
|
1168
|
+
Program() {
|
|
1169
|
+
for (const comment of sourceCode.getAllComments()) {
|
|
1170
|
+
if (isDocBlock(comment) || isDirective(comment, extra)) continue;
|
|
1171
|
+
context.report({
|
|
1172
|
+
loc: comment.loc,
|
|
1173
|
+
messageId: "noComment",
|
|
1174
|
+
suggest: [removeSuggestion(sourceCode, comment)]
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1180
|
+
};
|
|
1181
|
+
var no_comments_default = { rules: { "no-comments": noCommentsRule } };
|
|
857
1182
|
function isPureReExportFile(programNode) {
|
|
858
1183
|
const { body } = programNode;
|
|
859
1184
|
if (body.length === 0) return false;
|
|
@@ -2065,6 +2390,8 @@ var smart_max_lines_default = {
|
|
|
2065
2390
|
// src/eslint/plugin.ts
|
|
2066
2391
|
var PLUGIN_VERSION = "1.0.0";
|
|
2067
2392
|
var ruleModules = [
|
|
2393
|
+
doc_comment_max_lines_default,
|
|
2394
|
+
doc_comment_public_only_default,
|
|
2068
2395
|
enforce_function_style_default,
|
|
2069
2396
|
enforce_module_structure_default,
|
|
2070
2397
|
enforce_route_preload_default,
|
|
@@ -2073,6 +2400,7 @@ var ruleModules = [
|
|
|
2073
2400
|
i18n_interpolation_default,
|
|
2074
2401
|
i18n_param_names_default,
|
|
2075
2402
|
no_barrel_companion_file_default,
|
|
2403
|
+
no_comments_default,
|
|
2076
2404
|
no_duplicate_nav_prefix_default,
|
|
2077
2405
|
no_duplicate_shared_patterns_default,
|
|
2078
2406
|
no_generated_models_barrel_value_import_default,
|
|
@@ -2119,6 +2447,22 @@ function oneRulePlugin(name, rule3) {
|
|
|
2119
2447
|
};
|
|
2120
2448
|
}
|
|
2121
2449
|
|
|
2122
|
-
|
|
2450
|
+
// src/eslint/configs.ts
|
|
2451
|
+
var DOC_COMMENT_MAX_LINES = 3;
|
|
2452
|
+
var COMMENT_RULE_NAMES = [
|
|
2453
|
+
"no-comments",
|
|
2454
|
+
"doc-comment-public-only",
|
|
2455
|
+
"doc-comment-max-lines"
|
|
2456
|
+
];
|
|
2457
|
+
var commentsConfig = {
|
|
2458
|
+
plugins: { "@dloizides": plugin },
|
|
2459
|
+
rules: {
|
|
2460
|
+
"@dloizides/no-comments": "error",
|
|
2461
|
+
"@dloizides/doc-comment-public-only": "error",
|
|
2462
|
+
"@dloizides/doc-comment-max-lines": ["error", { max: DOC_COMMENT_MAX_LINES }]
|
|
2463
|
+
}
|
|
2464
|
+
};
|
|
2465
|
+
|
|
2466
|
+
export { COMMENT_RULE_NAMES, commentsConfig, legacyPlugins, plugin, ruleNames, rules };
|
|
2123
2467
|
//# sourceMappingURL=index.mjs.map
|
|
2124
2468
|
//# sourceMappingURL=index.mjs.map
|