@d3lm/lint-preset 1.5.4 → 1.5.5

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
@@ -293,6 +293,8 @@ function hasWidow(lines) {
293
293
  }
294
294
  var FULLNESS_WEIGHT = 0.07;
295
295
  var PARENTHETICAL_SPLIT_WEIGHT = 2;
296
+ var SENTENCE_START_COST = 25;
297
+ var MAX_SENTENCE_START_WORDS = 2;
296
298
  var MAX_STEP = 15;
297
299
  var EXTRA_LINES = 2;
298
300
  function fewestLines(starts, target) {
@@ -380,7 +382,7 @@ function balanceTokens(tokens, firstLimit, restLimit, count, options, preferredL
380
382
  afterOrphan: tokens.map((_, index) => {
381
383
  return options.avoidSentenceOrphans && index >= 2 && isOrphan(tokens[index - 2], tokens[index - 1]);
382
384
  }),
383
- splitCosts
385
+ splitCosts: withSentenceStartCosts(tokens, splitCosts, options)
384
386
  };
385
387
  const targets = [];
386
388
  for (let target = restLimit; target >= Math.max(longest, Math.floor(restLimit / 2)); target -= 1) {
@@ -446,6 +448,22 @@ function splitCostsOf(tokens, limit) {
446
448
  }
447
449
  return splitCosts;
448
450
  }
451
+ function withSentenceStartCosts(tokens, splitCosts, options) {
452
+ if (!options.avoidSentenceOrphans || options.ignoreSentenceStarts) {
453
+ return splitCosts;
454
+ }
455
+ const costs = new Map(splitCosts);
456
+ for (const [index, token] of tokens.entries()) {
457
+ if (!endsSentence(token)) {
458
+ continue;
459
+ }
460
+ const last = Math.min(index + 1 + MAX_SENTENCE_START_WORDS, tokens.length - 1);
461
+ for (let end = index + 2; end <= last && !endsSentence(tokens[end - 1]); end += 1) {
462
+ costs.set(end, (_nullishCoalesce(costs.get(end), () => ( 0))) + SENTENCE_START_COST);
463
+ }
464
+ }
465
+ return costs;
466
+ }
449
467
  function hasParentheticals(tokens, restLimit, options) {
450
468
  if (options.parentheticalOverflow === void 0) {
451
469
  return false;
@@ -1108,6 +1126,10 @@ function analyzeParagraph(paragraph, options) {
1108
1126
  const free = settle({ ...layoutOptions, avoidSentenceOrphans: false });
1109
1127
  return !("wrapped" in free) || sameLayout(free.wrapped, currentLines);
1110
1128
  };
1129
+ const keepsOnlySentenceStarts = () => {
1130
+ const free = settle({ ...layoutOptions, ignoreSentenceStarts: true });
1131
+ return "wrapped" in free && (sameLayout(free.even, currentLines) || sameLayout(free.wrapped, currentLines));
1132
+ };
1111
1133
  const splitsOnlyParenthetical = (line) => {
1112
1134
  if (layoutOptions.parentheticalOverflow === void 0) {
1113
1135
  return false;
@@ -1135,7 +1157,7 @@ function analyzeParagraph(paragraph, options) {
1135
1157
  wrapped.findIndex((words, position) => words.join(" ") !== _optionalChain([currentLines, 'access', _38 => _38[position], 'optionalAccess', _39 => _39.join, 'call', _40 => _40(" ")])),
1136
1158
  0
1137
1159
  );
1138
- if (lineIssues.length === 0 && sameLayout(even, currentLines)) {
1160
+ if (lineIssues.length === 0 && (sameLayout(even, currentLines) || keepsOnlySentenceStarts())) {
1139
1161
  lineIssues.push({ type: "orphan", line });
1140
1162
  } else if (lineIssues.length === 0) {
1141
1163
  lineIssues.push({ type: splitsOnlyParenthetical(line) ? "split-parenthetical" : "unbalanced", line });
@@ -1339,7 +1361,7 @@ When rules pull in different directions, the earlier one wins.
1339
1361
  ## Layout
1340
1362
 
1341
1363
  - 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.
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.
1364
+ - 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. The same goes for the first two words of a sentence, like \`It allocates\` after a period, when the note points at them. 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.
1343
1365
  - 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.
1344
1366
  - 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.
1345
1367
  - Separate paragraphs with an empty comment line.