@d3lm/lint-preset 1.5.2 → 1.5.4

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/comments.cjs CHANGED
@@ -201,6 +201,9 @@ function parentheticalGroups(tokens, limit) {
201
201
  }
202
202
  return groups;
203
203
  }
204
+ function parentheticalAround(tokens, at, limit) {
205
+ return parentheticalGroups(tokens, limit).find((group) => group.start < at && at < group.end);
206
+ }
204
207
  function bindParentheticals(tokens, limit) {
205
208
  const groups = new Map(parentheticalGroups(tokens, limit).map((group) => [group.start, group.end]));
206
209
  const units = [];
@@ -605,6 +608,7 @@ var ISSUE_TIERS = {
605
608
  widow: "verdict",
606
609
  unbalanced: "verdict",
607
610
  orphan: "hint",
611
+ "split-parenthetical": "hint",
608
612
  banner: "hint",
609
613
  "em-dash": "hint",
610
614
  semicolon: "hint",
@@ -1100,9 +1104,44 @@ function analyzeParagraph(paragraph, options) {
1100
1104
  if (hasWidow(currentLines) && !hasWidow(wrapped)) {
1101
1105
  lineIssues.push({ type: "widow", line: currentLines.length - 1 });
1102
1106
  }
1103
- if (lineIssues.length === 0 && overflow.length === 0 && (currentLines.length === wrapped.length || options.maxWidth !== void 0)) {
1104
- const line = wrapped.findIndex((words, position) => words.join(" ") !== _optionalChain([currentLines, 'access', _38 => _38[position], 'optionalAccess', _39 => _39.join, 'call', _40 => _40(" ")]));
1105
- lineIssues.push({ type: sameLayout(even, currentLines) ? "orphan" : "unbalanced", line: Math.max(line, 0) });
1107
+ const keepsOnlyOrphans = () => {
1108
+ const free = settle({ ...layoutOptions, avoidSentenceOrphans: false });
1109
+ return !("wrapped" in free) || sameLayout(free.wrapped, currentLines);
1110
+ };
1111
+ const splitsOnlyParenthetical = (line) => {
1112
+ if (layoutOptions.parentheticalOverflow === void 0) {
1113
+ return false;
1114
+ }
1115
+ const tokenCount = (lines) => tokenize(lines.flat().join(" ")).length;
1116
+ const end = tokenCount(currentLines.slice(0, line + 1));
1117
+ const group = parentheticalAround(tokens, end, restLimit + layoutOptions.parentheticalOverflow);
1118
+ if (!group) {
1119
+ return false;
1120
+ }
1121
+ const keepsGroup = wrapped.every((_, position) => {
1122
+ const breakAt = tokenCount(wrapped.slice(0, position + 1));
1123
+ return breakAt <= group.start || breakAt >= group.end;
1124
+ });
1125
+ if (!keepsGroup) {
1126
+ return false;
1127
+ }
1128
+ const restOptions = { ...layoutOptions, keepFirstLine: false };
1129
+ const rest = bindLineStarts(tokens.slice(end), startsLine);
1130
+ const restLines = layoutTokens(rest, restLimit, restLimit, restOptions);
1131
+ return sameLayout(breakAfterSentence(restLines, restLimit, restLimit, restOptions), currentLines.slice(line + 1));
1132
+ };
1133
+ if (overflow.length === 0 && (currentLines.length === wrapped.length || options.maxWidth !== void 0)) {
1134
+ const line = Math.max(
1135
+ wrapped.findIndex((words, position) => words.join(" ") !== _optionalChain([currentLines, 'access', _38 => _38[position], 'optionalAccess', _39 => _39.join, 'call', _40 => _40(" ")])),
1136
+ 0
1137
+ );
1138
+ if (lineIssues.length === 0 && sameLayout(even, currentLines)) {
1139
+ lineIssues.push({ type: "orphan", line });
1140
+ } else if (lineIssues.length === 0) {
1141
+ lineIssues.push({ type: splitsOnlyParenthetical(line) ? "split-parenthetical" : "unbalanced", line });
1142
+ } else if (lineIssues.every((issue) => issue.type === "orphan") && !sameLayout(even, currentLines) && !keepsOnlyOrphans()) {
1143
+ lineIssues.push({ type: "unbalanced", line });
1144
+ }
1106
1145
  }
1107
1146
  }
1108
1147
  const suggestion = wrapped.map(
@@ -1235,7 +1274,9 @@ function inspectSource(source, filename, options) {
1235
1274
  options.width,
1236
1275
  Math.min(_nullishCoalesce(options.singleLineWidth, () => ( options.width)), _nullishCoalesce(options.maxWidth, () => ( Infinity)))
1237
1276
  );
1238
- const paragraphOptions = shape.paragraphs.length === 1 && singleLineLength(shape.paragraphs[0], options) <= singleLineWidth ? { ...options, width: singleLineWidth } : options;
1277
+ const singleLineLimit = Math.min(singleLineWidth + options.tolerance, _nullishCoalesce(options.maxWidth, () => ( Infinity)));
1278
+ const singleLine = shape.paragraphs.length === 1 ? singleLineLength(shape.paragraphs[0], options) : Infinity;
1279
+ const paragraphOptions = singleLine <= singleLineLimit ? { ...options, width: Math.max(singleLineWidth, singleLine) } : options;
1239
1280
  const lines = sourceLines.slice(shape.startLine, shape.endLine + 1);
1240
1281
  reports.push({
1241
1282
  file: filename,
@@ -1298,7 +1339,7 @@ When rules pull in different directions, the earlier one wins.
1298
1339
  ## Layout
1299
1340
 
1300
1341
  - After you finish, the tool rewraps prose paragraphs, list items, and JSDoc tag descriptions. The width is a preferred target. A parenthetical may extend a line up to the configured maximum so it stays together, and lines may go up to the configured tolerance past the width when that saves a line. In longer paragraphs, balanced lines take priority over keeping every parenthetical on one line. The tool also avoids short last lines where possible. Leave these line breaks to the tool, except for the sentence-orphan case below.
1301
- - Don't end a line with the first word of a new sentence, clause, or parenthetical, like \`This\` after a period, \`the\` after a comma, or \`(the\`. Move it to the next line instead.
1342
+ - Don't end a line with the first word of a new sentence, clause, or parenthetical, like \`This\` after a period, \`the\` after a comma, or \`(the\`. Move it to the next line instead. A long word, like an identifier or a code span, may stay at the end of a line when moving it would leave that line far shorter than the lines around it. Then leave the line breaks as they are.
1302
1343
  - In a paragraph of two lines, the first line ends with a sentence whenever the rest fits on the second line and is no longer than the first. Don't end it with the start of the next sentence, like \`A wrap\` in \`...lay out differently. A wrap\`. Move those words to the second line instead.
1303
1344
  - A comment whose whole text is one paragraph stays on a single line when that line fits a separate, larger single-line width, even past the width. Only a longer comment wraps to the width.
1304
1345
  - Separate paragraphs with an empty comment line.