@d3lm/lint-preset 1.5.0 → 1.5.1
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 +1 -1
- package/dist/bin/comments.js +80 -27
- package/dist/bin/comments.js.map +1 -1
- package/dist/comments.cjs +80 -27
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js +80 -27
- package/dist/comments.js.map +1 -1
- package/package.json +1 -1
package/dist/comments.cjs
CHANGED
|
@@ -290,6 +290,8 @@ function hasWidow(lines) {
|
|
|
290
290
|
}
|
|
291
291
|
var FULLNESS_WEIGHT = 0.07;
|
|
292
292
|
var PARENTHETICAL_SPLIT_WEIGHT = 2;
|
|
293
|
+
var MAX_STEP = 15;
|
|
294
|
+
var EXTRA_LINES = 2;
|
|
293
295
|
function fewestLines(starts, target) {
|
|
294
296
|
const total = starts.length - 1;
|
|
295
297
|
const fewest = new Int32Array(total + 1);
|
|
@@ -422,7 +424,56 @@ function balanceTokens(tokens, firstLimit, restLimit, count, options, preferredL
|
|
|
422
424
|
const bounds = [0, ...best.breaks, total];
|
|
423
425
|
return bounds.slice(0, -1).map((start, index) => tokens.slice(start, bounds[index + 1]));
|
|
424
426
|
}
|
|
427
|
+
function hasStep(lines, offset = 0) {
|
|
428
|
+
return lines.some((line, index) => {
|
|
429
|
+
if (index === 0) {
|
|
430
|
+
return false;
|
|
431
|
+
}
|
|
432
|
+
const before = lineLength(lines[index - 1]) + (index === 1 ? offset : 0);
|
|
433
|
+
return lineLength(line) - before > MAX_STEP;
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
function splitCostsOf(tokens, limit) {
|
|
437
|
+
const splitCosts = /* @__PURE__ */ new Map();
|
|
438
|
+
for (const group of parentheticalGroups(tokens, limit)) {
|
|
439
|
+
const length = lineLength(tokens.slice(group.start, group.end));
|
|
440
|
+
for (let at = group.start + 1; at < group.end; at += 1) {
|
|
441
|
+
splitCosts.set(at, length * PARENTHETICAL_SPLIT_WEIGHT);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
return splitCosts;
|
|
445
|
+
}
|
|
446
|
+
function hasParentheticals(tokens, restLimit, options) {
|
|
447
|
+
if (options.parentheticalOverflow === void 0) {
|
|
448
|
+
return false;
|
|
449
|
+
}
|
|
450
|
+
return bindParentheticals(tokens, restLimit + options.parentheticalOverflow).some((token) => isParenthetical(token));
|
|
451
|
+
}
|
|
425
452
|
function layoutTokens(tokens, firstLimit, restLimit, options) {
|
|
453
|
+
const lines = layoutLines(tokens, firstLimit, restLimit, options);
|
|
454
|
+
const offset = restLimit - firstLimit;
|
|
455
|
+
if (options.keepFirstLine || options.keepSteps || !hasStep(lines, offset)) {
|
|
456
|
+
return lines;
|
|
457
|
+
}
|
|
458
|
+
const overflow = hasParentheticals(tokens, restLimit, options) ? _nullishCoalesce(options.parentheticalOverflow, () => ( 0)) : 0;
|
|
459
|
+
const splitCosts = overflow > 0 ? splitCostsOf(tokens, restLimit + overflow) : /* @__PURE__ */ new Map();
|
|
460
|
+
for (let count = lines.length + 1; count <= lines.length + EXTRA_LINES; count += 1) {
|
|
461
|
+
const even = balanceTokens(
|
|
462
|
+
tokens,
|
|
463
|
+
firstLimit + overflow,
|
|
464
|
+
restLimit + overflow,
|
|
465
|
+
count,
|
|
466
|
+
options,
|
|
467
|
+
restLimit,
|
|
468
|
+
splitCosts
|
|
469
|
+
);
|
|
470
|
+
if (even && !hasStep(even, offset)) {
|
|
471
|
+
return even;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
return lines;
|
|
475
|
+
}
|
|
476
|
+
function layoutLines(tokens, firstLimit, restLimit, options) {
|
|
426
477
|
if (options.parentheticalOverflow !== void 0) {
|
|
427
478
|
const grouped = bindParentheticals(tokens, restLimit + options.parentheticalOverflow);
|
|
428
479
|
if (grouped.some((token) => isParenthetical(token))) {
|
|
@@ -456,14 +507,7 @@ function layoutTokens(tokens, firstLimit, restLimit, options) {
|
|
|
456
507
|
return expanded;
|
|
457
508
|
});
|
|
458
509
|
}
|
|
459
|
-
const splitCosts =
|
|
460
|
-
const groups = parentheticalGroups(tokens, restLimit + options.parentheticalOverflow);
|
|
461
|
-
for (const group of groups) {
|
|
462
|
-
const length = lineLength(tokens.slice(group.start, group.end));
|
|
463
|
-
for (let at = group.start + 1; at < group.end; at += 1) {
|
|
464
|
-
splitCosts.set(at, length * PARENTHETICAL_SPLIT_WEIGHT);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
510
|
+
const splitCosts = splitCostsOf(tokens, restLimit + options.parentheticalOverflow);
|
|
467
511
|
const preferred = wrapTokens(tokens, firstLimit, restLimit, { ...options, parentheticalOverflow: void 0 });
|
|
468
512
|
for (let count = minimumLines; count <= Math.max(preferred.length + 1, preserved.length); count += 1) {
|
|
469
513
|
const balanced2 = balanceTokens(
|
|
@@ -982,11 +1026,11 @@ function analyzeParagraph(paragraph, options) {
|
|
|
982
1026
|
parentheticalOverflow: options.maxWidth === void 0 ? void 0 : options.maxWidth - options.width,
|
|
983
1027
|
keepFirstLine: paragraph.kind === "tag"
|
|
984
1028
|
};
|
|
985
|
-
const layOut = (from) => {
|
|
986
|
-
const even2 = layoutTokens(from, firstLimit, restLimit,
|
|
987
|
-
return { even: even2, wrapped: breakAfterSentence(even2, firstLimit, restLimit,
|
|
1029
|
+
const layOut = (from, settings) => {
|
|
1030
|
+
const even2 = layoutTokens(from, firstLimit, restLimit, settings);
|
|
1031
|
+
return { even: even2, wrapped: breakAfterSentence(even2, firstLimit, restLimit, settings) };
|
|
988
1032
|
};
|
|
989
|
-
|
|
1033
|
+
const units = bindLineStarts(paragraph.kind === "tag" ? bindTagHead(tokens) : tokens, startsLine);
|
|
990
1034
|
const hardLimit = restLimit + (options.maxWidth === void 0 ? options.tolerance : options.maxWidth - options.width);
|
|
991
1035
|
const written = currentLines.map((words) => ` ${words.join(" ")} `);
|
|
992
1036
|
const staysInLimit = (unit) => {
|
|
@@ -995,29 +1039,38 @@ function analyzeParagraph(paragraph, options) {
|
|
|
995
1039
|
if (!units.every((unit) => staysInLimit(unit))) {
|
|
996
1040
|
return keep({ tier: "manual", reason: "unbreakable text across lines" });
|
|
997
1041
|
}
|
|
998
|
-
let { even, wrapped } = layOut(units);
|
|
999
1042
|
const bodyOf = (lines) => {
|
|
1000
1043
|
return lines.map((words, position) => {
|
|
1001
1044
|
const text = `${position === 0 ? paragraph.marker : hang}${words.join(" ")}`;
|
|
1002
1045
|
return { ...first, text, verbatim: false, hardBreak: HARD_BREAK.test(text) };
|
|
1003
1046
|
});
|
|
1004
1047
|
};
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
const
|
|
1016
|
-
|
|
1048
|
+
const settle = (settings) => {
|
|
1049
|
+
let current = units;
|
|
1050
|
+
let { even: even2, wrapped: wrapped2 } = layOut(current, settings);
|
|
1051
|
+
for (; ; ) {
|
|
1052
|
+
const body = bodyOf(wrapped2);
|
|
1053
|
+
const rewrap = structureOf(body);
|
|
1054
|
+
if (!rewrap) {
|
|
1055
|
+
return { even: even2, wrapped: wrapped2 };
|
|
1056
|
+
}
|
|
1057
|
+
const tipping = body.findIndex((_, position) => structureOf(body.slice(0, position + 1)) !== void 0);
|
|
1058
|
+
const start = wrapped2.slice(0, Math.max(tipping, 1)).flat().length;
|
|
1059
|
+
const pair = `${current[start - 1]} ${current[start]}`;
|
|
1060
|
+
if (body.length < 2 || !staysInLimit(pair)) {
|
|
1061
|
+
const reading = rewrap.tier === "code-like" ? "code" : rewrap.reason;
|
|
1062
|
+
return { tier: "manual", reason: `rewrap would read as ${reading}` };
|
|
1063
|
+
}
|
|
1064
|
+
current = current.toSpliced(start - 1, 2, pair);
|
|
1065
|
+
({ even: even2, wrapped: wrapped2 } = layOut(current, settings));
|
|
1017
1066
|
}
|
|
1018
|
-
|
|
1019
|
-
|
|
1067
|
+
};
|
|
1068
|
+
const settled = settle(layoutOptions);
|
|
1069
|
+
const layout = "wrapped" in settled ? settled : settle({ ...layoutOptions, keepSteps: true });
|
|
1070
|
+
if (!("wrapped" in layout)) {
|
|
1071
|
+
return keep(layout);
|
|
1020
1072
|
}
|
|
1073
|
+
const { even, wrapped } = layout;
|
|
1021
1074
|
const matchesLayout = sameLayout(wrapped, currentLines);
|
|
1022
1075
|
const lineIssues = [];
|
|
1023
1076
|
const overflow = options.maxWidth === void 0 ? [] : overflowIssues(paragraph.lines, options);
|