@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/README.md +6 -3
- package/dist/bin/comments.js +50 -7
- package/dist/bin/comments.js.map +1 -1
- package/dist/comments.cjs +46 -5
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.d.cts +6 -5
- package/dist/comments.d.ts +6 -5
- package/dist/comments.js +46 -5
- package/dist/comments.js.map +1 -1
- package/package.json +1 -1
package/dist/comments.d.cts
CHANGED
|
@@ -18,7 +18,7 @@ interface WrapOptions {
|
|
|
18
18
|
*/
|
|
19
19
|
readonly parentheticalOverflow?: number;
|
|
20
20
|
}
|
|
21
|
-
type LineIssueType = 'overflow' | 'underfill' | 'orphan' | 'widow' | 'unbalanced';
|
|
21
|
+
type LineIssueType = 'overflow' | 'underfill' | 'orphan' | 'widow' | 'unbalanced' | 'split-parenthetical';
|
|
22
22
|
/**
|
|
23
23
|
* JSDoc writes types and `{@link ...}` tags as `{...}` groups, so they stay intact like code spans.
|
|
24
24
|
*/
|
|
@@ -43,8 +43,8 @@ interface AnalyzeOptions extends WrapOptions {
|
|
|
43
43
|
readonly maxWidth?: number;
|
|
44
44
|
/**
|
|
45
45
|
* Sets the maximum length of the line that holds a comment whose whole text is one
|
|
46
|
-
* prose paragraph. Such a comment stays on one line up to this length
|
|
47
|
-
* `width`. It defaults to `width`.
|
|
46
|
+
* prose paragraph. Such a comment stays on one line up to this length plus `tolerance`,
|
|
47
|
+
* even past `width`, but never past `maxWidth`. It defaults to `width`.
|
|
48
48
|
*/
|
|
49
49
|
readonly singleLineWidth?: number;
|
|
50
50
|
readonly tabWidth: number;
|
|
@@ -206,8 +206,9 @@ interface CommentsConfig {
|
|
|
206
206
|
readonly maxWidth?: number;
|
|
207
207
|
/**
|
|
208
208
|
* Sets the maximum length of the line that holds a comment whose whole text is one prose
|
|
209
|
-
* paragraph. Such a comment stays on one line up to this length
|
|
210
|
-
* wrapped to `width` beyond it. Defaults to 120 and never exceeds
|
|
209
|
+
* paragraph. Such a comment stays on one line up to this length plus `tolerance`, even past
|
|
210
|
+
* `width`, and is wrapped to `width` beyond it. Defaults to 120, and the line never exceeds
|
|
211
|
+
* `maxWidth`.
|
|
211
212
|
*/
|
|
212
213
|
readonly singleLineWidth?: number;
|
|
213
214
|
/**
|
package/dist/comments.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ interface WrapOptions {
|
|
|
18
18
|
*/
|
|
19
19
|
readonly parentheticalOverflow?: number;
|
|
20
20
|
}
|
|
21
|
-
type LineIssueType = 'overflow' | 'underfill' | 'orphan' | 'widow' | 'unbalanced';
|
|
21
|
+
type LineIssueType = 'overflow' | 'underfill' | 'orphan' | 'widow' | 'unbalanced' | 'split-parenthetical';
|
|
22
22
|
/**
|
|
23
23
|
* JSDoc writes types and `{@link ...}` tags as `{...}` groups, so they stay intact like code spans.
|
|
24
24
|
*/
|
|
@@ -43,8 +43,8 @@ interface AnalyzeOptions extends WrapOptions {
|
|
|
43
43
|
readonly maxWidth?: number;
|
|
44
44
|
/**
|
|
45
45
|
* Sets the maximum length of the line that holds a comment whose whole text is one
|
|
46
|
-
* prose paragraph. Such a comment stays on one line up to this length
|
|
47
|
-
* `width`. It defaults to `width`.
|
|
46
|
+
* prose paragraph. Such a comment stays on one line up to this length plus `tolerance`,
|
|
47
|
+
* even past `width`, but never past `maxWidth`. It defaults to `width`.
|
|
48
48
|
*/
|
|
49
49
|
readonly singleLineWidth?: number;
|
|
50
50
|
readonly tabWidth: number;
|
|
@@ -206,8 +206,9 @@ interface CommentsConfig {
|
|
|
206
206
|
readonly maxWidth?: number;
|
|
207
207
|
/**
|
|
208
208
|
* Sets the maximum length of the line that holds a comment whose whole text is one prose
|
|
209
|
-
* paragraph. Such a comment stays on one line up to this length
|
|
210
|
-
* wrapped to `width` beyond it. Defaults to 120 and never exceeds
|
|
209
|
+
* paragraph. Such a comment stays on one line up to this length plus `tolerance`, even past
|
|
210
|
+
* `width`, and is wrapped to `width` beyond it. Defaults to 120, and the line never exceeds
|
|
211
|
+
* `maxWidth`.
|
|
211
212
|
*/
|
|
212
213
|
readonly singleLineWidth?: number;
|
|
213
214
|
/**
|
package/dist/comments.js
CHANGED
|
@@ -199,6 +199,9 @@ function parentheticalGroups(tokens, limit) {
|
|
|
199
199
|
}
|
|
200
200
|
return groups;
|
|
201
201
|
}
|
|
202
|
+
function parentheticalAround(tokens, at, limit) {
|
|
203
|
+
return parentheticalGroups(tokens, limit).find((group) => group.start < at && at < group.end);
|
|
204
|
+
}
|
|
202
205
|
function bindParentheticals(tokens, limit) {
|
|
203
206
|
const groups = new Map(parentheticalGroups(tokens, limit).map((group) => [group.start, group.end]));
|
|
204
207
|
const units = [];
|
|
@@ -603,6 +606,7 @@ var ISSUE_TIERS = {
|
|
|
603
606
|
widow: "verdict",
|
|
604
607
|
unbalanced: "verdict",
|
|
605
608
|
orphan: "hint",
|
|
609
|
+
"split-parenthetical": "hint",
|
|
606
610
|
banner: "hint",
|
|
607
611
|
"em-dash": "hint",
|
|
608
612
|
semicolon: "hint",
|
|
@@ -1098,9 +1102,44 @@ function analyzeParagraph(paragraph, options) {
|
|
|
1098
1102
|
if (hasWidow(currentLines) && !hasWidow(wrapped)) {
|
|
1099
1103
|
lineIssues.push({ type: "widow", line: currentLines.length - 1 });
|
|
1100
1104
|
}
|
|
1101
|
-
|
|
1102
|
-
const
|
|
1103
|
-
|
|
1105
|
+
const keepsOnlyOrphans = () => {
|
|
1106
|
+
const free = settle({ ...layoutOptions, avoidSentenceOrphans: false });
|
|
1107
|
+
return !("wrapped" in free) || sameLayout(free.wrapped, currentLines);
|
|
1108
|
+
};
|
|
1109
|
+
const splitsOnlyParenthetical = (line) => {
|
|
1110
|
+
if (layoutOptions.parentheticalOverflow === void 0) {
|
|
1111
|
+
return false;
|
|
1112
|
+
}
|
|
1113
|
+
const tokenCount = (lines) => tokenize(lines.flat().join(" ")).length;
|
|
1114
|
+
const end = tokenCount(currentLines.slice(0, line + 1));
|
|
1115
|
+
const group = parentheticalAround(tokens, end, restLimit + layoutOptions.parentheticalOverflow);
|
|
1116
|
+
if (!group) {
|
|
1117
|
+
return false;
|
|
1118
|
+
}
|
|
1119
|
+
const keepsGroup = wrapped.every((_, position) => {
|
|
1120
|
+
const breakAt = tokenCount(wrapped.slice(0, position + 1));
|
|
1121
|
+
return breakAt <= group.start || breakAt >= group.end;
|
|
1122
|
+
});
|
|
1123
|
+
if (!keepsGroup) {
|
|
1124
|
+
return false;
|
|
1125
|
+
}
|
|
1126
|
+
const restOptions = { ...layoutOptions, keepFirstLine: false };
|
|
1127
|
+
const rest = bindLineStarts(tokens.slice(end), startsLine);
|
|
1128
|
+
const restLines = layoutTokens(rest, restLimit, restLimit, restOptions);
|
|
1129
|
+
return sameLayout(breakAfterSentence(restLines, restLimit, restLimit, restOptions), currentLines.slice(line + 1));
|
|
1130
|
+
};
|
|
1131
|
+
if (overflow.length === 0 && (currentLines.length === wrapped.length || options.maxWidth !== void 0)) {
|
|
1132
|
+
const line = Math.max(
|
|
1133
|
+
wrapped.findIndex((words, position) => words.join(" ") !== currentLines[position]?.join(" ")),
|
|
1134
|
+
0
|
|
1135
|
+
);
|
|
1136
|
+
if (lineIssues.length === 0 && sameLayout(even, currentLines)) {
|
|
1137
|
+
lineIssues.push({ type: "orphan", line });
|
|
1138
|
+
} else if (lineIssues.length === 0) {
|
|
1139
|
+
lineIssues.push({ type: splitsOnlyParenthetical(line) ? "split-parenthetical" : "unbalanced", line });
|
|
1140
|
+
} else if (lineIssues.every((issue) => issue.type === "orphan") && !sameLayout(even, currentLines) && !keepsOnlyOrphans()) {
|
|
1141
|
+
lineIssues.push({ type: "unbalanced", line });
|
|
1142
|
+
}
|
|
1104
1143
|
}
|
|
1105
1144
|
}
|
|
1106
1145
|
const suggestion = wrapped.map(
|
|
@@ -1233,7 +1272,9 @@ function inspectSource(source, filename, options) {
|
|
|
1233
1272
|
options.width,
|
|
1234
1273
|
Math.min(options.singleLineWidth ?? options.width, options.maxWidth ?? Infinity)
|
|
1235
1274
|
);
|
|
1236
|
-
const
|
|
1275
|
+
const singleLineLimit = Math.min(singleLineWidth + options.tolerance, options.maxWidth ?? Infinity);
|
|
1276
|
+
const singleLine = shape.paragraphs.length === 1 ? singleLineLength(shape.paragraphs[0], options) : Infinity;
|
|
1277
|
+
const paragraphOptions = singleLine <= singleLineLimit ? { ...options, width: Math.max(singleLineWidth, singleLine) } : options;
|
|
1237
1278
|
const lines = sourceLines.slice(shape.startLine, shape.endLine + 1);
|
|
1238
1279
|
reports.push({
|
|
1239
1280
|
file: filename,
|
|
@@ -1296,7 +1337,7 @@ When rules pull in different directions, the earlier one wins.
|
|
|
1296
1337
|
## Layout
|
|
1297
1338
|
|
|
1298
1339
|
- 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.
|
|
1299
|
-
- 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.
|
|
1340
|
+
- 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.
|
|
1300
1341
|
- 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.
|
|
1301
1342
|
- 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.
|
|
1302
1343
|
- Separate paragraphs with an empty comment line.
|