@sarj/eslint-plugin 2.5.0 → 2.6.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/dist/index.cjs CHANGED
@@ -247,6 +247,8 @@ var no_client_side_data_fetching_default = import_utils2.ESLintUtils.RuleCreator
247
247
  // src/rules/no-comment-cruft.ts
248
248
  var import_utils3 = require("@typescript-eslint/utils");
249
249
  var LEADING_PREAMBLE_MIN = 4;
250
+ var STEP_NARRATION_RE = /^(?:first(?:ly)?|second(?:ly)?|third(?:ly)?|then|next|after(?:wards| that)?|finally|lastly|now)\s*[,:]\s*\S|^step\s+\d+\b/i;
251
+ var META_COMMENTARY_RE = /\b(?:for now|keeping (?:it|this) simple|could be (?:refactored|improved|cleaned up|simplified)|refactor(?:ed|ing)? (?:later|this)|not sure (?:if|whether|why|how)|quick[- ](?:and[- ]dirty|fix)|(?:a |bit of a )?hacky|is a hack|temporary (?:solution|workaround|fix|hack)|revisit (?:this|later|below)|clean (?:this|it) up|not ideal|placeholder for now)\b/i;
250
252
  var DIRECTIVE_RE = /^(eslint\b|eslint-|@ts-|prettier-ignore|prettier\b|biome-|c8\b|v8\b|istanbul\b|@type\b|@vite|webpack|<reference|<amd|global\b|noinspection|todo\b|fixme\b|hack\b|xxx\b)/i;
251
253
  var LICENSE_RE = /copyright|licen[cs]ed?|spdx|permission is hereby granted|all rights reserved/i;
252
254
  var BANNER_FULL_RE = /^[\s\-=*#~_+.]{4,}$/;
@@ -285,6 +287,13 @@ function isProse(text) {
285
287
  }
286
288
  return false;
287
289
  }
290
+ function isRedundantNarration(body) {
291
+ const t = body.trim();
292
+ if (!t || looksLikeCode(t) || hasPseudocode(t)) return false;
293
+ if (STEP_NARRATION_RE.test(t)) return true;
294
+ if (META_COMMENTARY_RE.test(t)) return true;
295
+ return false;
296
+ }
288
297
  function hasCommentedOutCode(texts, precedingProse) {
289
298
  for (let i = 0; i < texts.length; i++) {
290
299
  const line = texts[i];
@@ -310,7 +319,8 @@ var no_comment_cruft_default = import_utils3.ESLintUtils.RuleCreator(
310
319
  messages: {
311
320
  commentedOutCode: "Commented-out code \u2014 delete it; git history remembers.",
312
321
  sectionBanner: "Section-banner / region comment \u2014 structure code with functions, not ASCII rules.",
313
- fileHeaderPreamble: "File-header comment preamble \u2014 use a brief doc comment for the why, not a block of `//` lines."
322
+ fileHeaderPreamble: "File-header comment preamble \u2014 use a brief doc comment for the why, not a block of `//` lines.",
323
+ redundantNarration: "Comment narrates the code \u2014 delete it or say *why*, not *what*. Code is self-documenting."
314
324
  }
315
325
  },
316
326
  defaultOptions: [],
@@ -365,6 +375,13 @@ var no_comment_cruft_default = import_utils3.ESLintUtils.RuleCreator(
365
375
  const precedingProse = prev !== void 0 && prev.type === "Line" && prev.loc.end.line === comment.loc.start.line - 1 && isProse(stripCommentMarker(prev.value));
366
376
  if (hasCommentedOutCode(texts, precedingProse)) {
367
377
  context.report({ node: comment, messageId: "commentedOutCode" });
378
+ continue;
379
+ }
380
+ if (comment.type === "Line" && texts.length === 1) {
381
+ const body = texts[0];
382
+ if (body !== void 0 && isRedundantNarration(body)) {
383
+ context.report({ node: comment, messageId: "redundantNarration" });
384
+ }
368
385
  }
369
386
  }
370
387
  reportLeadingPreamble(comments, firstCodeLine);
@@ -3779,7 +3796,7 @@ var rules = {
3779
3796
  var plugin = {
3780
3797
  meta: {
3781
3798
  name: "@sarj/eslint-plugin",
3782
- version: "2.5.0"
3799
+ version: "2.6.0"
3783
3800
  },
3784
3801
  rules,
3785
3802
  configs: {