@dloizides/frontend-devtools 1.2.0 → 1.3.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 CHANGED
@@ -5,6 +5,24 @@ All notable changes to `@dloizides/frontend-devtools` are documented here.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.3.0] - 2026-10-06
9
+
10
+ COMMENTS-1 "No code comments; only short doc comments on public members" (decisions D-CMT-1, D-CMT-3).
11
+
12
+ ### Added
13
+
14
+ - `no-comments`: reports every comment that is not a `/**` doc block and not a tool directive
15
+ (`eslint-*`, `@ts-*`, `prettier-ignore`, `istanbul`/`c8`, `/// <reference>`, `#__PURE__`,
16
+ `webpackChunkName`, shebang). `allow: string[]` adds directive regexes. Suggestion only, no autofix.
17
+ - `doc-comment-public-only`: a doc block must sit on an exported declaration (incl. `export { x }`,
18
+ `export default x`, `module.exports`, ambient `declare module`) or a public member of one;
19
+ `private` / `protected` / `#` members and local declarations are reported.
20
+ - `doc-comment-max-lines`: doc body capped at `max` (default 3) content lines; block tags other than
21
+ `allowedTags` (default `@param`, `@returns`) are reported. JSDoc type-annotation blocks
22
+ (`@type`, `@typedef`, ...) are exempt from both doc rules.
23
+ - `commentsConfig` flat-config block (the three rules at `error`) and `COMMENT_RULE_NAMES`, exported
24
+ from `/eslint`. Not adopted by any app yet: each repo opts in as step 1 of its COMMENTS-CLEAN sweep.
25
+
8
26
  ## [1.1.0] - 2026-07-13
9
27
 
10
28
  Both changes come out of the ES-04 (agora-web) build, which surfaced two ways the
@@ -74,4 +74,8 @@ declare const ruleNames: readonly string[];
74
74
  */
75
75
  declare const legacyPlugins: Record<string, FlatConfigPlugin>;
76
76
 
77
- export { type CustomRule, type FlatConfig, type FlatConfigPlugin, type SingleRulePlugin, legacyPlugins, plugin, ruleNames, rules };
77
+ declare const COMMENT_RULE_NAMES: readonly string[];
78
+ /** Flat-config block for COMMENTS-1: no code comments, short doc comments on public members only. */
79
+ declare const commentsConfig: FlatConfig;
80
+
81
+ export { COMMENT_RULE_NAMES, type CustomRule, type FlatConfig, type FlatConfigPlugin, type SingleRulePlugin, commentsConfig, legacyPlugins, plugin, ruleNames, rules };
@@ -74,4 +74,8 @@ declare const ruleNames: readonly string[];
74
74
  */
75
75
  declare const legacyPlugins: Record<string, FlatConfigPlugin>;
76
76
 
77
- export { type CustomRule, type FlatConfig, type FlatConfigPlugin, type SingleRulePlugin, legacyPlugins, plugin, ruleNames, rules };
77
+ declare const COMMENT_RULE_NAMES: readonly string[];
78
+ /** Flat-config block for COMMENTS-1: no code comments, short doc comments on public members only. */
79
+ declare const commentsConfig: FlatConfig;
80
+
81
+ export { COMMENT_RULE_NAMES, type CustomRule, type FlatConfig, type FlatConfigPlugin, type SingleRulePlugin, commentsConfig, legacyPlugins, plugin, ruleNames, rules };
@@ -8,6 +8,274 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
8
  var fs__default = /*#__PURE__*/_interopDefault(fs);
9
9
  var path__default = /*#__PURE__*/_interopDefault(path);
10
10
 
11
+ // src/rules/comment-utils.js
12
+ var DIRECTIVE_PATTERNS = [
13
+ /^\s*eslint(-disable|-enable|-env)?(-next-line|-line)?(\s|$)/,
14
+ /^\s*eslint\s/,
15
+ /^\s*globals?\s/,
16
+ /^\s*exported\s/,
17
+ /^\s*@ts-(expect-error|ignore|nocheck|check)\b/,
18
+ /^\s*prettier-ignore\b/,
19
+ /^\s*(istanbul|c8|v8)\s+ignore\b/,
20
+ /^\s*webpack[A-Z]\w*\s*:/,
21
+ /^\s*@vite-ignore\b/,
22
+ /^\s*[#@]__(PURE|NO_SIDE_EFFECTS)__\s*$/,
23
+ /^\s*@(jest|vitest)-environment\b/,
24
+ /^\s*jscpd:/,
25
+ /^\s*biome-ignore\b/,
26
+ /^\/\s*<(reference|amd-module)\b/
27
+ ];
28
+ var JSDOC_TYPE_TAGS = /* @__PURE__ */ new Set([
29
+ "type",
30
+ "typedef",
31
+ "satisfies",
32
+ "import",
33
+ "callback",
34
+ "template",
35
+ "property",
36
+ "jsx",
37
+ "jsxImportSource",
38
+ "jsxFrag",
39
+ "jsxRuntime"
40
+ ]);
41
+ var BLOCK_TAG = /^@([A-Za-z][\w-]*)/;
42
+ function isDocBlock(comment) {
43
+ return comment.type === "Block" && comment.value.startsWith("*") && comment.value !== "*";
44
+ }
45
+ function docBodyLines(comment) {
46
+ return comment.value.slice(1).split(/\r?\n/).map((line) => line.trim().replace(/^\*+\s?/, "").trim()).filter((line) => line.length > 0);
47
+ }
48
+ function blockTags(lines) {
49
+ const tags = [];
50
+ for (const line of lines) {
51
+ const match = BLOCK_TAG.exec(line);
52
+ if (match) tags.push(match[1]);
53
+ }
54
+ return tags;
55
+ }
56
+ function isTypeAnnotationDoc(comment) {
57
+ if (!isDocBlock(comment)) return false;
58
+ const lines = docBodyLines(comment);
59
+ if (lines.length === 0) return false;
60
+ const allTagged = lines.every((line) => BLOCK_TAG.test(line));
61
+ const tags = blockTags(lines);
62
+ return allTagged && tags.every((tag) => JSDOC_TYPE_TAGS.has(tag));
63
+ }
64
+ function compileAllow(allow) {
65
+ return (allow ?? []).map((source) => new RegExp(source));
66
+ }
67
+ function isDirective(comment, extraPatterns) {
68
+ if (comment.type === "Shebang") return true;
69
+ const patterns = extraPatterns ? DIRECTIVE_PATTERNS.concat(extraPatterns) : DIRECTIVE_PATTERNS;
70
+ return patterns.some((pattern) => pattern.test(comment.value));
71
+ }
72
+ function removalRange(sourceCode, comment) {
73
+ const text = sourceCode.text;
74
+ let start = comment.range[0];
75
+ let end = comment.range[1];
76
+ while (start > 0 && (text[start - 1] === " " || text[start - 1] === " ")) start--;
77
+ const ownLine = start === 0 || text[start - 1] === "\n";
78
+ if (ownLine) {
79
+ if (text[end] === "\r") end++;
80
+ if (text[end] === "\n") end++;
81
+ }
82
+ return [start, end];
83
+ }
84
+ function removeSuggestion(sourceCode, comment) {
85
+ return {
86
+ messageId: "removeComment",
87
+ fix: (fixer) => fixer.removeRange(removalRange(sourceCode, comment))
88
+ };
89
+ }
90
+
91
+ // src/rules/doc-comment-max-lines.js
92
+ var DEFAULT_MAX = 3;
93
+ var DEFAULT_ALLOWED_TAGS = ["param", "returns"];
94
+ var docCommentMaxLinesRule = {
95
+ meta: {
96
+ type: "suggestion",
97
+ docs: {
98
+ description: "Cap a doc comment at a few lines and allow only @param / @returns block tags (RV-1, D-CMT-3)"
99
+ },
100
+ schema: [
101
+ {
102
+ type: "object",
103
+ properties: {
104
+ max: { type: "integer", minimum: 1 },
105
+ allowedTags: { type: "array", items: { type: "string" } },
106
+ bannedTags: { type: "array", items: { type: "string" } }
107
+ },
108
+ additionalProperties: false
109
+ }
110
+ ],
111
+ messages: {
112
+ tooLong: "RV-1: doc comment is {{actual}} lines; the cap is {{max}}.",
113
+ bannedTag: "RV-1: @{{tag}} is not allowed in a doc comment (allowed: {{allowed}})."
114
+ }
115
+ },
116
+ create(context) {
117
+ const sourceCode = context.sourceCode ?? context.getSourceCode();
118
+ const options = context.options[0] ?? {};
119
+ const max = options.max ?? DEFAULT_MAX;
120
+ const allowed = new Set(options.allowedTags ?? DEFAULT_ALLOWED_TAGS);
121
+ for (const tag of options.bannedTags ?? []) allowed.delete(tag);
122
+ const allowedText = [...allowed].map((tag) => `@${tag}`).join(", ") || "none";
123
+ return {
124
+ Program() {
125
+ for (const comment of sourceCode.getAllComments()) {
126
+ if (!isDocBlock(comment) || isTypeAnnotationDoc(comment)) continue;
127
+ const lines = docBodyLines(comment);
128
+ if (lines.length > max)
129
+ context.report({
130
+ loc: comment.loc,
131
+ messageId: "tooLong",
132
+ data: { actual: String(lines.length), max: String(max) }
133
+ });
134
+ for (const tag of blockTags(lines))
135
+ if (!allowed.has(tag))
136
+ context.report({
137
+ loc: comment.loc,
138
+ messageId: "bannedTag",
139
+ data: { tag, allowed: allowedText }
140
+ });
141
+ }
142
+ }
143
+ };
144
+ }
145
+ };
146
+ var doc_comment_max_lines_default = { rules: { "doc-comment-max-lines": docCommentMaxLinesRule } };
147
+
148
+ // src/rules/doc-comment-public-only.js
149
+ var EXPORT_TYPES = /* @__PURE__ */ new Set([
150
+ "ExportNamedDeclaration",
151
+ "ExportDefaultDeclaration",
152
+ "ExportAllDeclaration",
153
+ "TSExportAssignment"
154
+ ]);
155
+ var PASS_THROUGH = /* @__PURE__ */ new Set([
156
+ "MethodDefinition",
157
+ "PropertyDefinition",
158
+ "AccessorProperty",
159
+ "TSAbstractMethodDefinition",
160
+ "TSAbstractPropertyDefinition",
161
+ "TSAbstractAccessorProperty",
162
+ "TSIndexSignature",
163
+ "ClassBody",
164
+ "ClassDeclaration",
165
+ "ClassExpression",
166
+ "TSInterfaceBody",
167
+ "TSInterfaceDeclaration",
168
+ "TSPropertySignature",
169
+ "TSMethodSignature",
170
+ "TSTypeLiteral",
171
+ "TSTypeAnnotation",
172
+ "TSTypeAliasDeclaration",
173
+ "TSIntersectionType",
174
+ "TSUnionType",
175
+ "TSEnumDeclaration",
176
+ "TSEnumBody",
177
+ "TSEnumMember",
178
+ "TSModuleBlock",
179
+ "TSModuleDeclaration",
180
+ "TSDeclareFunction",
181
+ "VariableDeclaration",
182
+ "VariableDeclarator",
183
+ "ObjectExpression",
184
+ "Property",
185
+ "TSAsExpression",
186
+ "TSSatisfiesExpression"
187
+ ]);
188
+ var HIDDEN_ACCESSIBILITY = /* @__PURE__ */ new Set(["private", "protected"]);
189
+ function isHiddenMember(node) {
190
+ if (HIDDEN_ACCESSIBILITY.has(node.accessibility)) return true;
191
+ return node.key?.type === "PrivateIdentifier";
192
+ }
193
+ function isAmbientModule(node) {
194
+ return node.type === "TSModuleDeclaration" && (node.declare === true || node.global === true);
195
+ }
196
+ function isNamed(node, name) {
197
+ return node?.type === "Identifier" && node.name === name;
198
+ }
199
+ function isCommonJsExport(node) {
200
+ if (node.type !== "ExpressionStatement") return false;
201
+ const expr = node.expression;
202
+ if (expr.type !== "AssignmentExpression" || expr.left.type !== "MemberExpression") return false;
203
+ const target = expr.left.object;
204
+ const isModuleExports = isNamed(target, "module") && isNamed(expr.left.property, "exports");
205
+ const isModuleExportsMember = target.type === "MemberExpression" && isNamed(target.object, "module") && isNamed(target.property, "exports");
206
+ return isNamed(target, "exports") || isModuleExports || isModuleExportsMember;
207
+ }
208
+ function declaredNames(node) {
209
+ if (node.type === "VariableDeclaration")
210
+ return node.declarations.filter((d) => d.id.type === "Identifier").map((d) => d.id.name);
211
+ if (node.id?.type === "Identifier") return [node.id.name];
212
+ return [];
213
+ }
214
+ function collectExportedNames(program) {
215
+ const names = /* @__PURE__ */ new Set();
216
+ for (const statement of program.body) {
217
+ if (statement.type === "ExportNamedDeclaration" && !statement.source) {
218
+ for (const spec of statement.specifiers) if (spec.local.type === "Identifier") names.add(spec.local.name);
219
+ }
220
+ if (statement.type === "ExportDefaultDeclaration" && statement.declaration.type === "Identifier")
221
+ names.add(statement.declaration.name);
222
+ if (statement.type === "TSExportAssignment" && statement.expression.type === "Identifier")
223
+ names.add(statement.expression.name);
224
+ }
225
+ return names;
226
+ }
227
+ function isTopLevelPublic(node, exportedNames) {
228
+ if (EXPORT_TYPES.has(node.type) || isAmbientModule(node) || isCommonJsExport(node)) return true;
229
+ return declaredNames(node).some((name) => exportedNames.has(name));
230
+ }
231
+ function isPublic(start, exportedNames) {
232
+ let current = start;
233
+ while (current.parent && current.parent.type !== "Program") {
234
+ if (isHiddenMember(current)) return false;
235
+ const parent = current.parent;
236
+ if (EXPORT_TYPES.has(parent.type) || isAmbientModule(parent)) return true;
237
+ if (!PASS_THROUGH.has(parent.type)) return false;
238
+ current = parent;
239
+ }
240
+ if (isHiddenMember(current)) return false;
241
+ return isTopLevelPublic(current, exportedNames);
242
+ }
243
+ function documentedNode(sourceCode, comment) {
244
+ const token = sourceCode.getTokenAfter(comment, { includeComments: false });
245
+ if (!token) return null;
246
+ let node = sourceCode.getNodeByRangeIndex(token.range[0]);
247
+ while (node?.parent && node.parent.type !== "Program" && node.parent.range[0] === node.range[0])
248
+ node = node.parent;
249
+ return node && node.type !== "Program" ? node : null;
250
+ }
251
+ var docCommentPublicOnlyRule = {
252
+ meta: {
253
+ type: "suggestion",
254
+ docs: {
255
+ description: "Allow a doc comment only on an exported declaration or a public member of one (RV-1)"
256
+ },
257
+ schema: [],
258
+ messages: {
259
+ 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."
260
+ }
261
+ },
262
+ create(context) {
263
+ const sourceCode = context.sourceCode ?? context.getSourceCode();
264
+ return {
265
+ Program(program) {
266
+ const exportedNames = collectExportedNames(program);
267
+ for (const comment of sourceCode.getAllComments()) {
268
+ if (!isDocBlock(comment) || isTypeAnnotationDoc(comment)) continue;
269
+ const node = documentedNode(sourceCode, comment);
270
+ if (node && isPublic(node, exportedNames)) continue;
271
+ context.report({ loc: comment.loc, messageId: "notPublic" });
272
+ }
273
+ }
274
+ };
275
+ }
276
+ };
277
+ var doc_comment_public_only_default = { rules: { "doc-comment-public-only": docCommentPublicOnlyRule } };
278
+
11
279
  // src/rules/enforce-function-style.js
12
280
  function isJSX(node) {
13
281
  return node && (node.type === "JSXElement" || node.type === "JSXFragment");
@@ -861,6 +1129,45 @@ var i18n_param_names_default = {
861
1129
  "i18n-param-names": rule2
862
1130
  }
863
1131
  };
1132
+
1133
+ // src/rules/no-comments.js
1134
+ var noCommentsRule = {
1135
+ meta: {
1136
+ type: "suggestion",
1137
+ hasSuggestions: true,
1138
+ docs: {
1139
+ description: "Disallow code comments: intent goes in names, rules in test names, context in the task doc and commit (RV-2)"
1140
+ },
1141
+ schema: [
1142
+ {
1143
+ type: "object",
1144
+ properties: { allow: { type: "array", items: { type: "string" } } },
1145
+ additionalProperties: false
1146
+ }
1147
+ ],
1148
+ messages: {
1149
+ noComment: "RV-2: no code comments. Put intent in names, business rules in test names, context in the task doc or commit message.",
1150
+ removeComment: "Remove this comment."
1151
+ }
1152
+ },
1153
+ create(context) {
1154
+ const sourceCode = context.sourceCode ?? context.getSourceCode();
1155
+ const extra = compileAllow(context.options[0]?.allow);
1156
+ return {
1157
+ Program() {
1158
+ for (const comment of sourceCode.getAllComments()) {
1159
+ if (isDocBlock(comment) || isDirective(comment, extra)) continue;
1160
+ context.report({
1161
+ loc: comment.loc,
1162
+ messageId: "noComment",
1163
+ suggest: [removeSuggestion(sourceCode, comment)]
1164
+ });
1165
+ }
1166
+ }
1167
+ };
1168
+ }
1169
+ };
1170
+ var no_comments_default = { rules: { "no-comments": noCommentsRule } };
864
1171
  function isPureReExportFile(programNode) {
865
1172
  const { body } = programNode;
866
1173
  if (body.length === 0) return false;
@@ -2072,6 +2379,8 @@ var smart_max_lines_default = {
2072
2379
  // src/eslint/plugin.ts
2073
2380
  var PLUGIN_VERSION = "1.0.0";
2074
2381
  var ruleModules = [
2382
+ doc_comment_max_lines_default,
2383
+ doc_comment_public_only_default,
2075
2384
  enforce_function_style_default,
2076
2385
  enforce_module_structure_default,
2077
2386
  enforce_route_preload_default,
@@ -2080,6 +2389,7 @@ var ruleModules = [
2080
2389
  i18n_interpolation_default,
2081
2390
  i18n_param_names_default,
2082
2391
  no_barrel_companion_file_default,
2392
+ no_comments_default,
2083
2393
  no_duplicate_nav_prefix_default,
2084
2394
  no_duplicate_shared_patterns_default,
2085
2395
  no_generated_models_barrel_value_import_default,
@@ -2126,6 +2436,24 @@ function oneRulePlugin(name, rule3) {
2126
2436
  };
2127
2437
  }
2128
2438
 
2439
+ // src/eslint/configs.ts
2440
+ var DOC_COMMENT_MAX_LINES = 3;
2441
+ var COMMENT_RULE_NAMES = [
2442
+ "no-comments",
2443
+ "doc-comment-public-only",
2444
+ "doc-comment-max-lines"
2445
+ ];
2446
+ var commentsConfig = {
2447
+ plugins: { "@dloizides": plugin },
2448
+ rules: {
2449
+ "@dloizides/no-comments": "error",
2450
+ "@dloizides/doc-comment-public-only": "error",
2451
+ "@dloizides/doc-comment-max-lines": ["error", { max: DOC_COMMENT_MAX_LINES }]
2452
+ }
2453
+ };
2454
+
2455
+ exports.COMMENT_RULE_NAMES = COMMENT_RULE_NAMES;
2456
+ exports.commentsConfig = commentsConfig;
2129
2457
  exports.legacyPlugins = legacyPlugins;
2130
2458
  exports.plugin = plugin;
2131
2459
  exports.ruleNames = ruleNames;