@sarj/eslint-plugin 9.17.1 → 10.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 +1 -1
- package/dist/index.cjs +53 -34
- package/dist/index.d.cts +1 -9
- package/dist/index.d.ts +1 -9
- package/dist/index.js +53 -34
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ import sarj from "@sarj/eslint-plugin";
|
|
|
26
26
|
export default [sarj.configs.recommended];
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
66 rules. Each source under `src/rules/` states one concise claim and links to
|
|
30
30
|
its paired tests. The definition and named test cases are the complete rule
|
|
31
31
|
specification, and `meta.docs.url` points directly to those executable examples.
|
|
32
32
|
|
package/dist/index.cjs
CHANGED
|
@@ -928,6 +928,8 @@ var CODE_TAIL_RE = /[;{}()]\s*$|=>\s*$|,\s*$/;
|
|
|
928
928
|
var ASSIGN_RE = /^[A-Za-z_$][\w.$[\]]*\s*(?:=(?![=>])|\+=|-=|\*=)\s*\S.*[;)}\]]\s*$/;
|
|
929
929
|
var CALL_RE = /^[A-Za-z_$][\w.$]*\([^)]*\)\s*;?\s*$/;
|
|
930
930
|
var ASSERTION_CODE_RE = /^(?:await\s+)?(?:expect(?:TypeOf)?|assert(?:\.\w+)?)\s*\(/;
|
|
931
|
+
var HTTP_CONTRACT_RE = /\b(?:GET|HEAD|OPTIONS|PATCH|POST|PUT|DELETE)\s+(?:https?:\/\/|\/|\{[A-Za-z_$])/;
|
|
932
|
+
var PROSE_ASSIGNMENT_RE = /^[A-Za-z_$][\w.$[\]]*\s*=\s*[A-Za-z][A-Za-z '-]{2,}\s+\((?:how|what|when|where|which|who|why)\b[^)]*\)[.!]?$/i;
|
|
931
933
|
var PSEUDOCODE_RE = /%\w+%|\[opt\]|(?:^|\s)<[A-Za-z]\w*>|…|\.\.\./;
|
|
932
934
|
function isBanner(text) {
|
|
933
935
|
const t = text.trim();
|
|
@@ -946,6 +948,7 @@ function isRegionMarker(text) {
|
|
|
946
948
|
function looksLikeCode(text, allowCall = true) {
|
|
947
949
|
const t = text.trim();
|
|
948
950
|
if (!t) return false;
|
|
951
|
+
if (PROSE_ASSIGNMENT_RE.test(t)) return false;
|
|
949
952
|
if (CODE_KEYWORD_RE.test(t) && CODE_TAIL_RE.test(t)) return true;
|
|
950
953
|
if (ASSIGN_RE.test(t)) return true;
|
|
951
954
|
if (ASSERTION_CODE_RE.test(t)) return true;
|
|
@@ -1084,6 +1087,21 @@ function runCitesAReference(comments, index) {
|
|
|
1084
1087
|
function areAdjacentLineComments(a, b) {
|
|
1085
1088
|
return a !== void 0 && b !== void 0 && a.type === "Line" && b.type === "Line" && b.loc.start.line === a.loc.end.line + 1;
|
|
1086
1089
|
}
|
|
1090
|
+
function lineRunStart(comments, index) {
|
|
1091
|
+
let start = index;
|
|
1092
|
+
while (start > 0 && areAdjacentLineComments(comments[start - 1], comments[start])) {
|
|
1093
|
+
start -= 1;
|
|
1094
|
+
}
|
|
1095
|
+
return start;
|
|
1096
|
+
}
|
|
1097
|
+
function runDocumentsHttpContract(comments, index) {
|
|
1098
|
+
const start = lineRunStart(comments, index);
|
|
1099
|
+
for (let i = start; i < comments.length; i++) {
|
|
1100
|
+
if (i > start && !areAdjacentLineComments(comments[i - 1], comments[i])) break;
|
|
1101
|
+
if (HTTP_CONTRACT_RE.test(stripCommentMarker(comments[i]?.value ?? ""))) return true;
|
|
1102
|
+
}
|
|
1103
|
+
return false;
|
|
1104
|
+
}
|
|
1087
1105
|
function isInsideCommentRun(comments, index) {
|
|
1088
1106
|
const comment = comments[index];
|
|
1089
1107
|
return areAdjacentLineComments(comments[index - 1], comment) || areAdjacentLineComments(comment, comments[index + 1]);
|
|
@@ -1119,7 +1137,7 @@ var no_comment_cruft_default = createRule({
|
|
|
1119
1137
|
schema: [],
|
|
1120
1138
|
messages: {
|
|
1121
1139
|
commentedOutCode: "Commented-out code \u2014 delete it; git history remembers.",
|
|
1122
|
-
sectionBanner: "Section-banner / region comment \u2014
|
|
1140
|
+
sectionBanner: "Section-banner / region comment \u2014 remove the decoration or replace it with a named code boundary.",
|
|
1123
1141
|
fileHeaderPreamble: "File-header comment preamble \u2014 use a brief doc comment for the why, not a block of `//` lines.",
|
|
1124
1142
|
commentWall: "Statement comment wall ({{count}} narrated steps) \u2014 delete the walkthrough and name the operations in code; keep only constraints or rationale.",
|
|
1125
1143
|
redundantNarration: "Comment narrates the code \u2014 delete it or say *why*, not *what*. Code is self-documenting.",
|
|
@@ -1142,6 +1160,17 @@ var no_comment_cruft_default = createRule({
|
|
|
1142
1160
|
function isJsDoc(comment) {
|
|
1143
1161
|
return comment.type === "Block" && /^\*/.test(comment.value);
|
|
1144
1162
|
}
|
|
1163
|
+
function isJsxOnlyComment(comment) {
|
|
1164
|
+
for (let node = sourceCode.getNodeByRangeIndex(
|
|
1165
|
+
comment.range[0]
|
|
1166
|
+
); node != null; node = node.parent) {
|
|
1167
|
+
if (node.type === import_utils7.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
1168
|
+
return node.expression.type === import_utils7.AST_NODE_TYPES.JSXEmptyExpression;
|
|
1169
|
+
}
|
|
1170
|
+
if (node.type === import_utils7.AST_NODE_TYPES.Program) return false;
|
|
1171
|
+
}
|
|
1172
|
+
return false;
|
|
1173
|
+
}
|
|
1145
1174
|
function findCommentWalls(comments) {
|
|
1146
1175
|
const attached = /* @__PURE__ */ new Map();
|
|
1147
1176
|
for (const comment of comments) {
|
|
@@ -1223,6 +1252,8 @@ var no_comment_cruft_default = createRule({
|
|
|
1223
1252
|
const enumerated = comments.filter(
|
|
1224
1253
|
(c) => c.type === "Line" && ENUMERATION_RE.test(stripCommentMarker(c.value))
|
|
1225
1254
|
);
|
|
1255
|
+
const reportedBannerRuns = /* @__PURE__ */ new Set();
|
|
1256
|
+
const reportedCodeRuns = /* @__PURE__ */ new Set();
|
|
1226
1257
|
for (let i = 0; i < comments.length; i++) {
|
|
1227
1258
|
const comment = comments[i];
|
|
1228
1259
|
if (comment === void 0) continue;
|
|
@@ -1242,9 +1273,14 @@ var no_comment_cruft_default = createRule({
|
|
|
1242
1273
|
}
|
|
1243
1274
|
continue;
|
|
1244
1275
|
}
|
|
1245
|
-
if (!isStandalone(comment)) continue;
|
|
1246
1276
|
if (LICENSE_RE.test(comment.value)) continue;
|
|
1247
1277
|
const texts = comment.value.split("\n").map(stripCommentMarker).filter((l) => l.length > 0 && !isDirective(l));
|
|
1278
|
+
if (!isStandalone(comment)) {
|
|
1279
|
+
if (isJsxOnlyComment(comment) && texts.some(isBanner)) {
|
|
1280
|
+
context.report({ node: comment, messageId: "sectionBanner" });
|
|
1281
|
+
}
|
|
1282
|
+
continue;
|
|
1283
|
+
}
|
|
1248
1284
|
const firstText = texts[0];
|
|
1249
1285
|
if (firstText !== void 0 && /^(?:todo|fixme)\b/i.test(firstText)) {
|
|
1250
1286
|
if (!runCitesAReference(comments, i)) {
|
|
@@ -1259,16 +1295,23 @@ var no_comment_cruft_default = createRule({
|
|
|
1259
1295
|
context.report({ node: comment, messageId: "placeholderImplementation" });
|
|
1260
1296
|
continue;
|
|
1261
1297
|
}
|
|
1298
|
+
const runStart = lineRunStart(comments, i);
|
|
1262
1299
|
if (texts.some(isBanner)) {
|
|
1263
|
-
|
|
1300
|
+
if (!reportedBannerRuns.has(runStart)) {
|
|
1301
|
+
context.report({ node: comment, messageId: "sectionBanner" });
|
|
1302
|
+
reportedBannerRuns.add(runStart);
|
|
1303
|
+
}
|
|
1264
1304
|
continue;
|
|
1265
1305
|
}
|
|
1266
1306
|
const prev = comments[i - 1];
|
|
1267
1307
|
const precedingProse = prev !== void 0 && prev.type === "Line" && prev.loc.end.line === comment.loc.start.line - 1 && isProse(stripCommentMarker(prev.value));
|
|
1268
1308
|
const container = sourceCode.getNodeByRangeIndex(comment.range[0]);
|
|
1269
1309
|
const inTypeMembers = container !== null && TYPE_MEMBER_CONTAINERS.has(container.type);
|
|
1270
|
-
if (hasCommentedOutCode(texts, precedingProse, !inTypeMembers) && !hasIllustrationLeadInAbove(comments, i)) {
|
|
1271
|
-
|
|
1310
|
+
if (hasCommentedOutCode(texts, precedingProse, !inTypeMembers) && !hasIllustrationLeadInAbove(comments, i) && !runDocumentsHttpContract(comments, i)) {
|
|
1311
|
+
if (!reportedCodeRuns.has(runStart)) {
|
|
1312
|
+
context.report({ node: comment, messageId: "commentedOutCode" });
|
|
1313
|
+
reportedCodeRuns.add(runStart);
|
|
1314
|
+
}
|
|
1272
1315
|
continue;
|
|
1273
1316
|
}
|
|
1274
1317
|
if (comment.type === "Line" && texts.length === 1) {
|
|
@@ -9759,31 +9802,6 @@ var prefer_server_actions_default = createRule({
|
|
|
9759
9802
|
}
|
|
9760
9803
|
});
|
|
9761
9804
|
|
|
9762
|
-
// src/rules/prefer-single-sentence-comment.ts
|
|
9763
|
-
var prefer_single_sentence_comment_default = createRule({
|
|
9764
|
-
name: "prefer-single-sentence-comment",
|
|
9765
|
-
meta: {
|
|
9766
|
-
type: "suggestion",
|
|
9767
|
-
docs: { description: "Prefer one sentence and self-documenting code over a two-sentence comment." },
|
|
9768
|
-
schema: [],
|
|
9769
|
-
messages: {
|
|
9770
|
-
preferOneSentence: "Two-sentence comment \u2014 prefer one sentence and self-documenting code."
|
|
9771
|
-
}
|
|
9772
|
-
},
|
|
9773
|
-
defaultOptions: [],
|
|
9774
|
-
create(context) {
|
|
9775
|
-
return {
|
|
9776
|
-
Program() {
|
|
9777
|
-
for (const group of proseGroups(context.filename, context.sourceCode)) {
|
|
9778
|
-
if (!group.hasTypedTags && sentenceUnits(group.text) === 2) {
|
|
9779
|
-
context.report({ node: group.comment, messageId: "preferOneSentence" });
|
|
9780
|
-
}
|
|
9781
|
-
}
|
|
9782
|
-
}
|
|
9783
|
-
};
|
|
9784
|
-
}
|
|
9785
|
-
});
|
|
9786
|
-
|
|
9787
9805
|
// src/rules/prefer-string-literal-union.ts
|
|
9788
9806
|
var import_utils62 = require("@typescript-eslint/utils");
|
|
9789
9807
|
var ts2 = __toESM(require("typescript"), 1);
|
|
@@ -12271,6 +12289,10 @@ var retiredRules = {
|
|
|
12271
12289
|
removedIn: "3.0.0",
|
|
12272
12290
|
reason: "Delete the retired entry; application-profile consumers can separately adopt `@sarj/prefer-shadcn-primitives`."
|
|
12273
12291
|
},
|
|
12292
|
+
"prefer-single-sentence-comment": {
|
|
12293
|
+
removedIn: "10.0.0",
|
|
12294
|
+
reason: "Delete the config entry and suppressions; use the narrower no-comment-cruft, no-restated-comment, and no-long-comment rules."
|
|
12295
|
+
},
|
|
12274
12296
|
"primary-export-file-name": {
|
|
12275
12297
|
removedIn: "4.0.0",
|
|
12276
12298
|
reason: "Delete the config entry and suppressions; there is no replacement."
|
|
@@ -12345,7 +12367,6 @@ var rules = {
|
|
|
12345
12367
|
"prefer-schema-for-api-payload": prefer_schema_for_api_payload_default,
|
|
12346
12368
|
"prefer-semantic-colors": prefer_semantic_colors_default,
|
|
12347
12369
|
"prefer-server-actions": prefer_server_actions_default,
|
|
12348
|
-
"prefer-single-sentence-comment": prefer_single_sentence_comment_default,
|
|
12349
12370
|
"prefer-string-literal-union": prefer_string_literal_union_default,
|
|
12350
12371
|
"prefer-whole-object-assertion": prefer_whole_object_assertion_default,
|
|
12351
12372
|
"prefer-zod-enum": prefer_zod_enum_default,
|
|
@@ -12361,7 +12382,7 @@ var rules = {
|
|
|
12361
12382
|
};
|
|
12362
12383
|
var meta = {
|
|
12363
12384
|
name: "@sarj/eslint-plugin",
|
|
12364
|
-
version: "
|
|
12385
|
+
version: "10.0.0"
|
|
12365
12386
|
};
|
|
12366
12387
|
var applicationOnlyRules = [
|
|
12367
12388
|
"no-restricted-library-load",
|
|
@@ -12416,7 +12437,6 @@ var recommendedRules = {
|
|
|
12416
12437
|
"@sarj/prefer-schema-for-api-payload": "warn",
|
|
12417
12438
|
"@sarj/prefer-semantic-colors": ["warn", { requireSemanticTokens: true }],
|
|
12418
12439
|
"@sarj/prefer-server-actions": "warn",
|
|
12419
|
-
"@sarj/prefer-single-sentence-comment": "warn",
|
|
12420
12440
|
"@sarj/prefer-string-literal-union": "warn",
|
|
12421
12441
|
"@sarj/prefer-whole-object-assertion": "warn",
|
|
12422
12442
|
"@sarj/prefer-zod-enum": "warn",
|
|
@@ -12482,7 +12502,6 @@ var strictRules = {
|
|
|
12482
12502
|
"@sarj/prefer-schema-for-api-payload": "error",
|
|
12483
12503
|
"@sarj/prefer-semantic-colors": ["error", { requireSemanticTokens: true }],
|
|
12484
12504
|
"@sarj/prefer-server-actions": "error",
|
|
12485
|
-
"@sarj/prefer-single-sentence-comment": "warn",
|
|
12486
12505
|
"@sarj/prefer-string-literal-union": "error",
|
|
12487
12506
|
"@sarj/prefer-whole-object-assertion": "error",
|
|
12488
12507
|
"@sarj/prefer-zod-enum": "error",
|
package/dist/index.d.cts
CHANGED
|
@@ -267,9 +267,6 @@ declare const rules: {
|
|
|
267
267
|
readonly "prefer-server-actions": _typescript_eslint_utils_ts_eslint.RuleModule<"preferServerAction", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
268
268
|
name: string;
|
|
269
269
|
};
|
|
270
|
-
readonly "prefer-single-sentence-comment": _typescript_eslint_utils_ts_eslint.RuleModule<"preferOneSentence", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
271
|
-
name: string;
|
|
272
|
-
};
|
|
273
270
|
readonly "prefer-string-literal-union": _typescript_eslint_utils_ts_eslint.RuleModule<"bareChoiceField" | "comparisonCluster", readonly [{
|
|
274
271
|
ignoreFields?: readonly string[];
|
|
275
272
|
}?], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
@@ -368,7 +365,6 @@ declare const recommendedRules: {
|
|
|
368
365
|
readonly requireSemanticTokens: true;
|
|
369
366
|
}];
|
|
370
367
|
readonly "@sarj/prefer-server-actions": "warn";
|
|
371
|
-
readonly "@sarj/prefer-single-sentence-comment": "warn";
|
|
372
368
|
readonly "@sarj/prefer-string-literal-union": "warn";
|
|
373
369
|
readonly "@sarj/prefer-whole-object-assertion": "warn";
|
|
374
370
|
readonly "@sarj/prefer-zod-enum": "warn";
|
|
@@ -436,7 +432,6 @@ declare const strictRules: {
|
|
|
436
432
|
readonly requireSemanticTokens: true;
|
|
437
433
|
}];
|
|
438
434
|
readonly "@sarj/prefer-server-actions": "error";
|
|
439
|
-
readonly "@sarj/prefer-single-sentence-comment": "warn";
|
|
440
435
|
readonly "@sarj/prefer-string-literal-union": "error";
|
|
441
436
|
readonly "@sarj/prefer-whole-object-assertion": "error";
|
|
442
437
|
readonly "@sarj/prefer-zod-enum": "error";
|
|
@@ -458,7 +453,7 @@ type FlatPreset = {
|
|
|
458
453
|
declare const plugin: {
|
|
459
454
|
readonly meta: {
|
|
460
455
|
readonly name: "@sarj/eslint-plugin";
|
|
461
|
-
readonly version: "
|
|
456
|
+
readonly version: "10.0.0";
|
|
462
457
|
};
|
|
463
458
|
readonly rules: {
|
|
464
459
|
readonly "duplicate-test-body": _typescript_eslint_utils_ts_eslint.RuleModule<"duplicateTestBody", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
@@ -640,9 +635,6 @@ declare const plugin: {
|
|
|
640
635
|
readonly "prefer-server-actions": _typescript_eslint_utils_ts_eslint.RuleModule<"preferServerAction", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
641
636
|
name: string;
|
|
642
637
|
};
|
|
643
|
-
readonly "prefer-single-sentence-comment": _typescript_eslint_utils_ts_eslint.RuleModule<"preferOneSentence", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
644
|
-
name: string;
|
|
645
|
-
};
|
|
646
638
|
readonly "prefer-string-literal-union": _typescript_eslint_utils_ts_eslint.RuleModule<"bareChoiceField" | "comparisonCluster", readonly [{
|
|
647
639
|
ignoreFields?: readonly string[];
|
|
648
640
|
}?], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
package/dist/index.d.ts
CHANGED
|
@@ -267,9 +267,6 @@ declare const rules: {
|
|
|
267
267
|
readonly "prefer-server-actions": _typescript_eslint_utils_ts_eslint.RuleModule<"preferServerAction", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
268
268
|
name: string;
|
|
269
269
|
};
|
|
270
|
-
readonly "prefer-single-sentence-comment": _typescript_eslint_utils_ts_eslint.RuleModule<"preferOneSentence", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
271
|
-
name: string;
|
|
272
|
-
};
|
|
273
270
|
readonly "prefer-string-literal-union": _typescript_eslint_utils_ts_eslint.RuleModule<"bareChoiceField" | "comparisonCluster", readonly [{
|
|
274
271
|
ignoreFields?: readonly string[];
|
|
275
272
|
}?], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
@@ -368,7 +365,6 @@ declare const recommendedRules: {
|
|
|
368
365
|
readonly requireSemanticTokens: true;
|
|
369
366
|
}];
|
|
370
367
|
readonly "@sarj/prefer-server-actions": "warn";
|
|
371
|
-
readonly "@sarj/prefer-single-sentence-comment": "warn";
|
|
372
368
|
readonly "@sarj/prefer-string-literal-union": "warn";
|
|
373
369
|
readonly "@sarj/prefer-whole-object-assertion": "warn";
|
|
374
370
|
readonly "@sarj/prefer-zod-enum": "warn";
|
|
@@ -436,7 +432,6 @@ declare const strictRules: {
|
|
|
436
432
|
readonly requireSemanticTokens: true;
|
|
437
433
|
}];
|
|
438
434
|
readonly "@sarj/prefer-server-actions": "error";
|
|
439
|
-
readonly "@sarj/prefer-single-sentence-comment": "warn";
|
|
440
435
|
readonly "@sarj/prefer-string-literal-union": "error";
|
|
441
436
|
readonly "@sarj/prefer-whole-object-assertion": "error";
|
|
442
437
|
readonly "@sarj/prefer-zod-enum": "error";
|
|
@@ -458,7 +453,7 @@ type FlatPreset = {
|
|
|
458
453
|
declare const plugin: {
|
|
459
454
|
readonly meta: {
|
|
460
455
|
readonly name: "@sarj/eslint-plugin";
|
|
461
|
-
readonly version: "
|
|
456
|
+
readonly version: "10.0.0";
|
|
462
457
|
};
|
|
463
458
|
readonly rules: {
|
|
464
459
|
readonly "duplicate-test-body": _typescript_eslint_utils_ts_eslint.RuleModule<"duplicateTestBody", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
@@ -640,9 +635,6 @@ declare const plugin: {
|
|
|
640
635
|
readonly "prefer-server-actions": _typescript_eslint_utils_ts_eslint.RuleModule<"preferServerAction", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
641
636
|
name: string;
|
|
642
637
|
};
|
|
643
|
-
readonly "prefer-single-sentence-comment": _typescript_eslint_utils_ts_eslint.RuleModule<"preferOneSentence", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
644
|
-
name: string;
|
|
645
|
-
};
|
|
646
638
|
readonly "prefer-string-literal-union": _typescript_eslint_utils_ts_eslint.RuleModule<"bareChoiceField" | "comparisonCluster", readonly [{
|
|
647
639
|
ignoreFields?: readonly string[];
|
|
648
640
|
}?], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
package/dist/index.js
CHANGED
|
@@ -886,6 +886,8 @@ var CODE_TAIL_RE = /[;{}()]\s*$|=>\s*$|,\s*$/;
|
|
|
886
886
|
var ASSIGN_RE = /^[A-Za-z_$][\w.$[\]]*\s*(?:=(?![=>])|\+=|-=|\*=)\s*\S.*[;)}\]]\s*$/;
|
|
887
887
|
var CALL_RE = /^[A-Za-z_$][\w.$]*\([^)]*\)\s*;?\s*$/;
|
|
888
888
|
var ASSERTION_CODE_RE = /^(?:await\s+)?(?:expect(?:TypeOf)?|assert(?:\.\w+)?)\s*\(/;
|
|
889
|
+
var HTTP_CONTRACT_RE = /\b(?:GET|HEAD|OPTIONS|PATCH|POST|PUT|DELETE)\s+(?:https?:\/\/|\/|\{[A-Za-z_$])/;
|
|
890
|
+
var PROSE_ASSIGNMENT_RE = /^[A-Za-z_$][\w.$[\]]*\s*=\s*[A-Za-z][A-Za-z '-]{2,}\s+\((?:how|what|when|where|which|who|why)\b[^)]*\)[.!]?$/i;
|
|
889
891
|
var PSEUDOCODE_RE = /%\w+%|\[opt\]|(?:^|\s)<[A-Za-z]\w*>|…|\.\.\./;
|
|
890
892
|
function isBanner(text) {
|
|
891
893
|
const t = text.trim();
|
|
@@ -904,6 +906,7 @@ function isRegionMarker(text) {
|
|
|
904
906
|
function looksLikeCode(text, allowCall = true) {
|
|
905
907
|
const t = text.trim();
|
|
906
908
|
if (!t) return false;
|
|
909
|
+
if (PROSE_ASSIGNMENT_RE.test(t)) return false;
|
|
907
910
|
if (CODE_KEYWORD_RE.test(t) && CODE_TAIL_RE.test(t)) return true;
|
|
908
911
|
if (ASSIGN_RE.test(t)) return true;
|
|
909
912
|
if (ASSERTION_CODE_RE.test(t)) return true;
|
|
@@ -1042,6 +1045,21 @@ function runCitesAReference(comments, index) {
|
|
|
1042
1045
|
function areAdjacentLineComments(a, b) {
|
|
1043
1046
|
return a !== void 0 && b !== void 0 && a.type === "Line" && b.type === "Line" && b.loc.start.line === a.loc.end.line + 1;
|
|
1044
1047
|
}
|
|
1048
|
+
function lineRunStart(comments, index) {
|
|
1049
|
+
let start = index;
|
|
1050
|
+
while (start > 0 && areAdjacentLineComments(comments[start - 1], comments[start])) {
|
|
1051
|
+
start -= 1;
|
|
1052
|
+
}
|
|
1053
|
+
return start;
|
|
1054
|
+
}
|
|
1055
|
+
function runDocumentsHttpContract(comments, index) {
|
|
1056
|
+
const start = lineRunStart(comments, index);
|
|
1057
|
+
for (let i = start; i < comments.length; i++) {
|
|
1058
|
+
if (i > start && !areAdjacentLineComments(comments[i - 1], comments[i])) break;
|
|
1059
|
+
if (HTTP_CONTRACT_RE.test(stripCommentMarker(comments[i]?.value ?? ""))) return true;
|
|
1060
|
+
}
|
|
1061
|
+
return false;
|
|
1062
|
+
}
|
|
1045
1063
|
function isInsideCommentRun(comments, index) {
|
|
1046
1064
|
const comment = comments[index];
|
|
1047
1065
|
return areAdjacentLineComments(comments[index - 1], comment) || areAdjacentLineComments(comment, comments[index + 1]);
|
|
@@ -1077,7 +1095,7 @@ var no_comment_cruft_default = createRule({
|
|
|
1077
1095
|
schema: [],
|
|
1078
1096
|
messages: {
|
|
1079
1097
|
commentedOutCode: "Commented-out code \u2014 delete it; git history remembers.",
|
|
1080
|
-
sectionBanner: "Section-banner / region comment \u2014
|
|
1098
|
+
sectionBanner: "Section-banner / region comment \u2014 remove the decoration or replace it with a named code boundary.",
|
|
1081
1099
|
fileHeaderPreamble: "File-header comment preamble \u2014 use a brief doc comment for the why, not a block of `//` lines.",
|
|
1082
1100
|
commentWall: "Statement comment wall ({{count}} narrated steps) \u2014 delete the walkthrough and name the operations in code; keep only constraints or rationale.",
|
|
1083
1101
|
redundantNarration: "Comment narrates the code \u2014 delete it or say *why*, not *what*. Code is self-documenting.",
|
|
@@ -1100,6 +1118,17 @@ var no_comment_cruft_default = createRule({
|
|
|
1100
1118
|
function isJsDoc(comment) {
|
|
1101
1119
|
return comment.type === "Block" && /^\*/.test(comment.value);
|
|
1102
1120
|
}
|
|
1121
|
+
function isJsxOnlyComment(comment) {
|
|
1122
|
+
for (let node = sourceCode.getNodeByRangeIndex(
|
|
1123
|
+
comment.range[0]
|
|
1124
|
+
); node != null; node = node.parent) {
|
|
1125
|
+
if (node.type === AST_NODE_TYPES6.JSXExpressionContainer) {
|
|
1126
|
+
return node.expression.type === AST_NODE_TYPES6.JSXEmptyExpression;
|
|
1127
|
+
}
|
|
1128
|
+
if (node.type === AST_NODE_TYPES6.Program) return false;
|
|
1129
|
+
}
|
|
1130
|
+
return false;
|
|
1131
|
+
}
|
|
1103
1132
|
function findCommentWalls(comments) {
|
|
1104
1133
|
const attached = /* @__PURE__ */ new Map();
|
|
1105
1134
|
for (const comment of comments) {
|
|
@@ -1181,6 +1210,8 @@ var no_comment_cruft_default = createRule({
|
|
|
1181
1210
|
const enumerated = comments.filter(
|
|
1182
1211
|
(c) => c.type === "Line" && ENUMERATION_RE.test(stripCommentMarker(c.value))
|
|
1183
1212
|
);
|
|
1213
|
+
const reportedBannerRuns = /* @__PURE__ */ new Set();
|
|
1214
|
+
const reportedCodeRuns = /* @__PURE__ */ new Set();
|
|
1184
1215
|
for (let i = 0; i < comments.length; i++) {
|
|
1185
1216
|
const comment = comments[i];
|
|
1186
1217
|
if (comment === void 0) continue;
|
|
@@ -1200,9 +1231,14 @@ var no_comment_cruft_default = createRule({
|
|
|
1200
1231
|
}
|
|
1201
1232
|
continue;
|
|
1202
1233
|
}
|
|
1203
|
-
if (!isStandalone(comment)) continue;
|
|
1204
1234
|
if (LICENSE_RE.test(comment.value)) continue;
|
|
1205
1235
|
const texts = comment.value.split("\n").map(stripCommentMarker).filter((l) => l.length > 0 && !isDirective(l));
|
|
1236
|
+
if (!isStandalone(comment)) {
|
|
1237
|
+
if (isJsxOnlyComment(comment) && texts.some(isBanner)) {
|
|
1238
|
+
context.report({ node: comment, messageId: "sectionBanner" });
|
|
1239
|
+
}
|
|
1240
|
+
continue;
|
|
1241
|
+
}
|
|
1206
1242
|
const firstText = texts[0];
|
|
1207
1243
|
if (firstText !== void 0 && /^(?:todo|fixme)\b/i.test(firstText)) {
|
|
1208
1244
|
if (!runCitesAReference(comments, i)) {
|
|
@@ -1217,16 +1253,23 @@ var no_comment_cruft_default = createRule({
|
|
|
1217
1253
|
context.report({ node: comment, messageId: "placeholderImplementation" });
|
|
1218
1254
|
continue;
|
|
1219
1255
|
}
|
|
1256
|
+
const runStart = lineRunStart(comments, i);
|
|
1220
1257
|
if (texts.some(isBanner)) {
|
|
1221
|
-
|
|
1258
|
+
if (!reportedBannerRuns.has(runStart)) {
|
|
1259
|
+
context.report({ node: comment, messageId: "sectionBanner" });
|
|
1260
|
+
reportedBannerRuns.add(runStart);
|
|
1261
|
+
}
|
|
1222
1262
|
continue;
|
|
1223
1263
|
}
|
|
1224
1264
|
const prev = comments[i - 1];
|
|
1225
1265
|
const precedingProse = prev !== void 0 && prev.type === "Line" && prev.loc.end.line === comment.loc.start.line - 1 && isProse(stripCommentMarker(prev.value));
|
|
1226
1266
|
const container = sourceCode.getNodeByRangeIndex(comment.range[0]);
|
|
1227
1267
|
const inTypeMembers = container !== null && TYPE_MEMBER_CONTAINERS.has(container.type);
|
|
1228
|
-
if (hasCommentedOutCode(texts, precedingProse, !inTypeMembers) && !hasIllustrationLeadInAbove(comments, i)) {
|
|
1229
|
-
|
|
1268
|
+
if (hasCommentedOutCode(texts, precedingProse, !inTypeMembers) && !hasIllustrationLeadInAbove(comments, i) && !runDocumentsHttpContract(comments, i)) {
|
|
1269
|
+
if (!reportedCodeRuns.has(runStart)) {
|
|
1270
|
+
context.report({ node: comment, messageId: "commentedOutCode" });
|
|
1271
|
+
reportedCodeRuns.add(runStart);
|
|
1272
|
+
}
|
|
1230
1273
|
continue;
|
|
1231
1274
|
}
|
|
1232
1275
|
if (comment.type === "Line" && texts.length === 1) {
|
|
@@ -9720,31 +9763,6 @@ var prefer_server_actions_default = createRule({
|
|
|
9720
9763
|
}
|
|
9721
9764
|
});
|
|
9722
9765
|
|
|
9723
|
-
// src/rules/prefer-single-sentence-comment.ts
|
|
9724
|
-
var prefer_single_sentence_comment_default = createRule({
|
|
9725
|
-
name: "prefer-single-sentence-comment",
|
|
9726
|
-
meta: {
|
|
9727
|
-
type: "suggestion",
|
|
9728
|
-
docs: { description: "Prefer one sentence and self-documenting code over a two-sentence comment." },
|
|
9729
|
-
schema: [],
|
|
9730
|
-
messages: {
|
|
9731
|
-
preferOneSentence: "Two-sentence comment \u2014 prefer one sentence and self-documenting code."
|
|
9732
|
-
}
|
|
9733
|
-
},
|
|
9734
|
-
defaultOptions: [],
|
|
9735
|
-
create(context) {
|
|
9736
|
-
return {
|
|
9737
|
-
Program() {
|
|
9738
|
-
for (const group of proseGroups(context.filename, context.sourceCode)) {
|
|
9739
|
-
if (!group.hasTypedTags && sentenceUnits(group.text) === 2) {
|
|
9740
|
-
context.report({ node: group.comment, messageId: "preferOneSentence" });
|
|
9741
|
-
}
|
|
9742
|
-
}
|
|
9743
|
-
}
|
|
9744
|
-
};
|
|
9745
|
-
}
|
|
9746
|
-
});
|
|
9747
|
-
|
|
9748
9766
|
// src/rules/prefer-string-literal-union.ts
|
|
9749
9767
|
import {
|
|
9750
9768
|
ESLintUtils as ESLintUtils3,
|
|
@@ -12235,6 +12253,10 @@ var retiredRules = {
|
|
|
12235
12253
|
removedIn: "3.0.0",
|
|
12236
12254
|
reason: "Delete the retired entry; application-profile consumers can separately adopt `@sarj/prefer-shadcn-primitives`."
|
|
12237
12255
|
},
|
|
12256
|
+
"prefer-single-sentence-comment": {
|
|
12257
|
+
removedIn: "10.0.0",
|
|
12258
|
+
reason: "Delete the config entry and suppressions; use the narrower no-comment-cruft, no-restated-comment, and no-long-comment rules."
|
|
12259
|
+
},
|
|
12238
12260
|
"primary-export-file-name": {
|
|
12239
12261
|
removedIn: "4.0.0",
|
|
12240
12262
|
reason: "Delete the config entry and suppressions; there is no replacement."
|
|
@@ -12309,7 +12331,6 @@ var rules = {
|
|
|
12309
12331
|
"prefer-schema-for-api-payload": prefer_schema_for_api_payload_default,
|
|
12310
12332
|
"prefer-semantic-colors": prefer_semantic_colors_default,
|
|
12311
12333
|
"prefer-server-actions": prefer_server_actions_default,
|
|
12312
|
-
"prefer-single-sentence-comment": prefer_single_sentence_comment_default,
|
|
12313
12334
|
"prefer-string-literal-union": prefer_string_literal_union_default,
|
|
12314
12335
|
"prefer-whole-object-assertion": prefer_whole_object_assertion_default,
|
|
12315
12336
|
"prefer-zod-enum": prefer_zod_enum_default,
|
|
@@ -12325,7 +12346,7 @@ var rules = {
|
|
|
12325
12346
|
};
|
|
12326
12347
|
var meta = {
|
|
12327
12348
|
name: "@sarj/eslint-plugin",
|
|
12328
|
-
version: "
|
|
12349
|
+
version: "10.0.0"
|
|
12329
12350
|
};
|
|
12330
12351
|
var applicationOnlyRules = [
|
|
12331
12352
|
"no-restricted-library-load",
|
|
@@ -12380,7 +12401,6 @@ var recommendedRules = {
|
|
|
12380
12401
|
"@sarj/prefer-schema-for-api-payload": "warn",
|
|
12381
12402
|
"@sarj/prefer-semantic-colors": ["warn", { requireSemanticTokens: true }],
|
|
12382
12403
|
"@sarj/prefer-server-actions": "warn",
|
|
12383
|
-
"@sarj/prefer-single-sentence-comment": "warn",
|
|
12384
12404
|
"@sarj/prefer-string-literal-union": "warn",
|
|
12385
12405
|
"@sarj/prefer-whole-object-assertion": "warn",
|
|
12386
12406
|
"@sarj/prefer-zod-enum": "warn",
|
|
@@ -12446,7 +12466,6 @@ var strictRules = {
|
|
|
12446
12466
|
"@sarj/prefer-schema-for-api-payload": "error",
|
|
12447
12467
|
"@sarj/prefer-semantic-colors": ["error", { requireSemanticTokens: true }],
|
|
12448
12468
|
"@sarj/prefer-server-actions": "error",
|
|
12449
|
-
"@sarj/prefer-single-sentence-comment": "warn",
|
|
12450
12469
|
"@sarj/prefer-string-literal-union": "error",
|
|
12451
12470
|
"@sarj/prefer-whole-object-assertion": "error",
|
|
12452
12471
|
"@sarj/prefer-zod-enum": "error",
|