@d3lm/lint-preset 1.6.2 → 1.6.3

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.
@@ -20,7 +20,7 @@ interface WrapOptions {
20
20
  */
21
21
  readonly parentheticalOverflow?: number;
22
22
  }
23
- type LineIssueType = 'overflow' | 'underfill' | 'orphan' | 'widow' | 'unbalanced' | 'split-parenthetical';
23
+ type LineIssueType = 'overflow' | 'underfill' | 'orphan' | 'widow' | 'unbalanced' | 'wide' | 'split-parenthetical';
24
24
  /**
25
25
  * Splits text into words. JSDoc writes types and `{@link ...}` tags as `{...}` groups, so they stay
26
26
  * intact like code spans.
@@ -234,11 +234,12 @@ interface CommentsConfig {
234
234
  readonly singleLineWidth?: number;
235
235
  /**
236
236
  * Sets how many columns prose lines may go past `width` when that saves a line in a paragraph
237
- * of three or more lines. A paragraph that already has the layout for a wider `width`, up to
238
- * `width` plus this many columns, also passes as it is. So does a paragraph with as many lines
239
- * as the rewrap whose lines are each at most this many columns shorter or longer than in the
240
- * rewrap. It never goes past `maxWidth`. When `maxWidth` is omitted, it also sets a legacy hard
241
- * limit of `width + tolerance`.
237
+ * of three or more lines. A paragraph that already has the layout for a wider `width`, up
238
+ * to `width` plus this many columns, also passes as it is. So does a paragraph with as many
239
+ * lines as the rewrap whose lines, the last aside, are at most this many columns shorter
240
+ * than the shortest of them in the rewrap, and end at most this many columns past `width`.
241
+ * It never goes past `maxWidth`. When `maxWidth` is omitted, it also sets a legacy hard limit
242
+ * of `width + tolerance` columns.
242
243
  */
243
244
  readonly tolerance?: number;
244
245
  /**
@@ -20,7 +20,7 @@ interface WrapOptions {
20
20
  */
21
21
  readonly parentheticalOverflow?: number;
22
22
  }
23
- type LineIssueType = 'overflow' | 'underfill' | 'orphan' | 'widow' | 'unbalanced' | 'split-parenthetical';
23
+ type LineIssueType = 'overflow' | 'underfill' | 'orphan' | 'widow' | 'unbalanced' | 'wide' | 'split-parenthetical';
24
24
  /**
25
25
  * Splits text into words. JSDoc writes types and `{@link ...}` tags as `{...}` groups, so they stay
26
26
  * intact like code spans.
@@ -234,11 +234,12 @@ interface CommentsConfig {
234
234
  readonly singleLineWidth?: number;
235
235
  /**
236
236
  * Sets how many columns prose lines may go past `width` when that saves a line in a paragraph
237
- * of three or more lines. A paragraph that already has the layout for a wider `width`, up to
238
- * `width` plus this many columns, also passes as it is. So does a paragraph with as many lines
239
- * as the rewrap whose lines are each at most this many columns shorter or longer than in the
240
- * rewrap. It never goes past `maxWidth`. When `maxWidth` is omitted, it also sets a legacy hard
241
- * limit of `width + tolerance`.
237
+ * of three or more lines. A paragraph that already has the layout for a wider `width`, up
238
+ * to `width` plus this many columns, also passes as it is. So does a paragraph with as many
239
+ * lines as the rewrap whose lines, the last aside, are at most this many columns shorter
240
+ * than the shortest of them in the rewrap, and end at most this many columns past `width`.
241
+ * It never goes past `maxWidth`. When `maxWidth` is omitted, it also sets a legacy hard limit
242
+ * of `width + tolerance` columns.
242
243
  */
243
244
  readonly tolerance?: number;
244
245
  /**
package/dist/comments.js CHANGED
@@ -771,6 +771,7 @@ var ISSUE_TIERS = {
771
771
  underfill: "verdict",
772
772
  widow: "verdict",
773
773
  unbalanced: "verdict",
774
+ wide: "verdict",
774
775
  orphan: "hint",
775
776
  "split-parenthetical": "hint",
776
777
  banner: "hint",
@@ -1357,6 +1358,14 @@ function analyzeParagraph(paragraph, options, language) {
1357
1358
  const restLines = layoutTokens(rest, restLimit, restLimit, restOptions);
1358
1359
  return sameLayout(breakAfterSentence(restLines, restLimit, restLimit, restOptions), currentLines.slice(line + 1));
1359
1360
  };
1361
+ const differenceAt = (line) => {
1362
+ const longest = Math.max(...wrapped.map((words) => words.join(" ").length));
1363
+ const wide = currentLines.flatMap((words, position) => {
1364
+ const limit = (position === 0 ? firstLimit : restLimit) + layoutOptions.tolerance;
1365
+ return words.join(" ").length > Math.max(limit, longest) ? [{ type: "wide", line: position }] : [];
1366
+ });
1367
+ return wide.length > 0 ? wide : [{ type: "unbalanced", line }];
1368
+ };
1360
1369
  if (overflow.length === 0 && (currentLines.length === wrapped.length || options.maxWidth !== void 0)) {
1361
1370
  const line = Math.max(
1362
1371
  wrapped.findIndex((words, position) => words.join(" ") !== currentLines[position]?.join(" ")),
@@ -1365,9 +1374,11 @@ function analyzeParagraph(paragraph, options, language) {
1365
1374
  if (lineIssues.length === 0 && (sameLayout(even, currentLines) || keepsOnlySentenceStarts())) {
1366
1375
  lineIssues.push({ type: "orphan", line });
1367
1376
  } else if (lineIssues.length === 0) {
1368
- lineIssues.push({ type: splitsOnlyParenthetical(line) ? "split-parenthetical" : "unbalanced", line });
1377
+ lineIssues.push(
1378
+ ...splitsOnlyParenthetical(line) ? [{ type: "split-parenthetical", line }] : differenceAt(line)
1379
+ );
1369
1380
  } else if (lineIssues.every((issue) => issue.type === "orphan") && !sameLayout(even, currentLines) && !keepsOnlyOrphans()) {
1370
- lineIssues.push({ type: "unbalanced", line });
1381
+ lineIssues.push(...differenceAt(line));
1371
1382
  }
1372
1383
  }
1373
1384
  const splitLine = splitTokenLine(currentLines, tokens);
@@ -1385,14 +1396,15 @@ function analyzeParagraph(paragraph, options, language) {
1385
1396
  return false;
1386
1397
  };
1387
1398
  const staysNearLayout = () => {
1388
- if (currentLines.length !== wrapped.length || splitTokenLine(currentLines, units) !== -1) {
1399
+ if (layoutOptions.tolerance === 0 || currentLines.length !== wrapped.length || splitTokenLine(currentLines, units) !== -1) {
1389
1400
  return false;
1390
1401
  }
1402
+ const shortest = Math.min(...wrapped.slice(0, -1).map((words) => words.join(" ").length));
1391
1403
  return currentLines.every((words, position) => {
1392
1404
  const length = words.join(" ").length;
1393
- const suggestedLength = wrapped[position].join(" ").length;
1394
1405
  const limit = (position === 0 ? firstLimit : restLimit) + layoutOptions.tolerance;
1395
- return Math.abs(length - suggestedLength) <= layoutOptions.tolerance && length <= Math.max(suggestedLength, limit);
1406
+ const isLast = position === currentLines.length - 1;
1407
+ return (isLast || length >= shortest - layoutOptions.tolerance) && length <= Math.max(wrapped[position].join(" ").length, limit);
1396
1408
  });
1397
1409
  };
1398
1410
  const hasVerdict = lineIssues.some((issue) => isVerdict(issue));