@d3lm/lint-preset 1.5.5 → 1.5.6
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 +3 -1
- package/dist/bin/comments.js +32 -11
- package/dist/bin/comments.js.map +1 -1
- package/dist/comments.cjs +30 -10
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.d.cts +5 -3
- package/dist/comments.d.ts +5 -3
- package/dist/comments.js +30 -10
- package/dist/comments.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -273,6 +273,8 @@ A paragraph with an `orphan` hint is not reported as `unbalanced` when that word
|
|
|
273
273
|
|
|
274
274
|
In the same way, a paragraph that splits a parenthetical is not reported as `unbalanced` when the split is all that sets it apart from the suggested rewrap, because the split can read as well and keep the line closer to `width`. This holds when the lines before the split match the rewrap and the lines after it match the rewrap of the text after the split. Otherwise the paragraph is still `unbalanced`.
|
|
275
275
|
|
|
276
|
+
With a `tolerance`, a paragraph has no `underfill`, `widow`, or `unbalanced` verdict when it already has the layout that the tool produces for a wider `width`, up to `width` plus `tolerance`. Its suggestion then keeps the lines as they are. With `width: 100` and `tolerance: 5`, a paragraph that is laid out the way the tool lays it out for a width of 105 passes. A paragraph that only has hints keeps them, and a line past `maxWidth` is still an `overflow`.
|
|
277
|
+
|
|
276
278
|
Hints are only checked in prose, never in code spans, code blocks, `@example`, or URLs. Rules that can't be measured, like writing complete sentences, are part of the agent's prompt (see `DEFAULT_RULES` in `src/comments/agent.ts`). The prompt treats the style rules as preferences, so the agent keeps punctuation that carries meaning or reads clearly, and never changes code, code spans, literals, patterns, or quotations.
|
|
277
279
|
|
|
278
280
|
### Text Kept as Written
|
|
@@ -287,7 +289,7 @@ To keep a drawing that is wider than the width, put it in a code fence or add `c
|
|
|
287
289
|
|
|
288
290
|
### Configuration
|
|
289
291
|
|
|
290
|
-
`width` is the preferred line length, and `maxWidth` is the hard maximum, including indentation and the comment prefix. The CLI defaults `maxWidth` to 120, or to `width` if that is larger. The wrapper may go past `width`, up to `maxWidth`, to keep a parenthetical on one line. `tolerance` (default 0) lets lines in paragraphs of three or more lines go that many columns past `width` when that saves a line. A comment that is one paragraph stays on one line up to `singleLineWidth` plus `tolerance`, capped by `maxWidth`. A word or code span longer than `maxWidth` is never split and is reported as `overflow`.
|
|
292
|
+
`width` is the preferred line length, and `maxWidth` is the hard maximum, including indentation and the comment prefix. The CLI defaults `maxWidth` to 120, or to `width` if that is larger. The wrapper may go past `width`, up to `maxWidth`, to keep a parenthetical on one line. `tolerance` (default 0) lets lines in paragraphs of three or more lines go that many columns past `width` when that saves a line. `check` also accepts a paragraph that already has the layout for a wider `width`, up to `width` plus `tolerance`, while the tool itself still wraps to `width`. A comment that is one paragraph stays on one line up to `singleLineWidth` plus `tolerance`, capped by `maxWidth`. A word or code span longer than `maxWidth` is never split and is reported as `overflow`.
|
|
291
293
|
|
|
292
294
|
Like prettier, `comments` looks for a config file in the current directory and its parents, up to the repository root. The config can be a `comments.config.{ts,mts,js,mjs,cjs}`, `.commentsrc`, or `.commentsrc.json` file, or a `comments` key in `package.json`. All options are optional.
|
|
293
295
|
|
package/dist/bin/comments.js
CHANGED
|
@@ -1351,9 +1351,9 @@ function analyzeParagraph(paragraph, options) {
|
|
|
1351
1351
|
parentheticalOverflow: options.maxWidth === void 0 ? void 0 : options.maxWidth - options.width,
|
|
1352
1352
|
keepFirstLine: paragraph.kind === "tag"
|
|
1353
1353
|
};
|
|
1354
|
-
const layOut = (from, settings) => {
|
|
1355
|
-
const even2 = layoutTokens(from, firstLimit, restLimit, settings);
|
|
1356
|
-
return { even: even2, wrapped: breakAfterSentence(even2, firstLimit, restLimit, settings) };
|
|
1354
|
+
const layOut = (from, settings, extra) => {
|
|
1355
|
+
const even2 = layoutTokens(from, firstLimit + extra, restLimit + extra, settings);
|
|
1356
|
+
return { even: even2, wrapped: breakAfterSentence(even2, firstLimit + extra, restLimit + extra, settings) };
|
|
1357
1357
|
};
|
|
1358
1358
|
const units = bindLineStarts(paragraph.kind === "tag" ? bindTagHead(tokens) : tokens, startsLine);
|
|
1359
1359
|
const hardLimit = restLimit + (options.maxWidth === void 0 ? options.tolerance : options.maxWidth - options.width);
|
|
@@ -1370,9 +1370,9 @@ function analyzeParagraph(paragraph, options) {
|
|
|
1370
1370
|
return { ...first, text, verbatim: false, hardBreak: HARD_BREAK.test(text) };
|
|
1371
1371
|
});
|
|
1372
1372
|
};
|
|
1373
|
-
const settle = (settings) => {
|
|
1373
|
+
const settle = (settings, extra = 0) => {
|
|
1374
1374
|
let current = units;
|
|
1375
|
-
let { even: even2, wrapped: wrapped2 } = layOut(current, settings);
|
|
1375
|
+
let { even: even2, wrapped: wrapped2 } = layOut(current, settings, extra);
|
|
1376
1376
|
for (; ; ) {
|
|
1377
1377
|
const body = bodyOf(wrapped2);
|
|
1378
1378
|
const rewrap = structureOf(body);
|
|
@@ -1387,11 +1387,19 @@ function analyzeParagraph(paragraph, options) {
|
|
|
1387
1387
|
return { tier: "manual", reason: `rewrap would read as ${reading}` };
|
|
1388
1388
|
}
|
|
1389
1389
|
current = current.toSpliced(start - 1, 2, pair);
|
|
1390
|
-
({ even: even2, wrapped: wrapped2 } = layOut(current, settings));
|
|
1390
|
+
({ even: even2, wrapped: wrapped2 } = layOut(current, settings, extra));
|
|
1391
1391
|
}
|
|
1392
1392
|
};
|
|
1393
|
-
const
|
|
1394
|
-
|
|
1393
|
+
const layoutAt = (extra) => {
|
|
1394
|
+
const settings = {
|
|
1395
|
+
...layoutOptions,
|
|
1396
|
+
tolerance: layoutOptions.tolerance - extra,
|
|
1397
|
+
parentheticalOverflow: layoutOptions.parentheticalOverflow === void 0 ? void 0 : layoutOptions.parentheticalOverflow - extra
|
|
1398
|
+
};
|
|
1399
|
+
const settled = settle(settings, extra);
|
|
1400
|
+
return "wrapped" in settled ? settled : settle({ ...settings, keepSteps: true }, extra);
|
|
1401
|
+
};
|
|
1402
|
+
const layout = layoutAt(0);
|
|
1395
1403
|
if (!("wrapped" in layout)) {
|
|
1396
1404
|
return keep(layout);
|
|
1397
1405
|
}
|
|
@@ -1456,10 +1464,22 @@ function analyzeParagraph(paragraph, options) {
|
|
|
1456
1464
|
}
|
|
1457
1465
|
}
|
|
1458
1466
|
}
|
|
1459
|
-
const
|
|
1467
|
+
const isVerdict = (issue) => ISSUE_TIERS[issue.type] === "verdict";
|
|
1468
|
+
const matchesWiderLayout = () => {
|
|
1469
|
+
for (let extra = 1; extra <= layoutOptions.tolerance; extra += 1) {
|
|
1470
|
+
const wider = layoutAt(extra);
|
|
1471
|
+
if ("wrapped" in wider && sameLayout(wider.wrapped, currentLines)) {
|
|
1472
|
+
return true;
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
return false;
|
|
1476
|
+
};
|
|
1477
|
+
const accepted = lineIssues.some((issue) => isVerdict(issue)) && matchesWiderLayout();
|
|
1478
|
+
const suggested = accepted ? currentLines : wrapped;
|
|
1479
|
+
const suggestion = suggested.map(
|
|
1460
1480
|
(words, position) => `${prefix}${position === 0 ? paragraph.marker : hang}${words.join(" ")}`
|
|
1461
1481
|
);
|
|
1462
|
-
const wrapIssues = lineIssues.map((issue) => lineIssue(issue.type, paragraph.lines[issue.line], options));
|
|
1482
|
+
const wrapIssues = lineIssues.filter((issue) => !accepted || !isVerdict(issue)).map((issue) => lineIssue(issue.type, paragraph.lines[issue.line], options));
|
|
1463
1483
|
const issues = byLine([...overflow, ...wrapIssues, ...styleIssues(paragraph, options)]);
|
|
1464
1484
|
return { ...base, reflowable: true, issues, suggestion };
|
|
1465
1485
|
}
|
|
@@ -2897,7 +2917,8 @@ Config overrides (take precedence over the config file):
|
|
|
2897
2917
|
--width <n> Preferred comment line length
|
|
2898
2918
|
--max-width <n> Hard limit for prose (default: 120, never below width)
|
|
2899
2919
|
--single-line-width <n> Longest line a one-paragraph comment may stay on (default: 120)
|
|
2900
|
-
--tolerance <n> Columns prose may go past width to save a line, within max-width (default: 0)
|
|
2920
|
+
--tolerance <n> Columns prose may go past width to save a line, within max-width (default: 0).
|
|
2921
|
+
A paragraph that has the layout for a width up to that much wider also passes
|
|
2901
2922
|
--[no-]orphans Keep a sentence's first word off the end of a line, and end the first of two lines
|
|
2902
2923
|
with a sentence when the second is no longer than the first (default: on)
|
|
2903
2924
|
--[no-]style Look for possible semicolons, em-dashes, dashes, label colons, emphasis, and banners
|