@d3lm/lint-preset 1.6.0 → 1.6.2
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 +15 -21
- package/dist/bin/comments.js +21 -7
- package/dist/bin/comments.js.map +1 -1
- package/dist/{chunk-SMTCD6GW.js → chunk-3H72UCKF.js} +1 -1
- package/dist/{chunk-SMTCD6GW.js.map → chunk-3H72UCKF.js.map} +1 -1
- package/dist/{chunk-M3BAUCCR.cjs → chunk-HEEMZMIV.cjs} +1 -1
- package/dist/{chunk-M3BAUCCR.cjs.map → chunk-HEEMZMIV.cjs.map} +1 -1
- package/dist/comments.cjs +19 -5
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.d.cts +27 -23
- package/dist/comments.d.ts +27 -23
- package/dist/comments.js +19 -5
- package/dist/comments.js.map +1 -1
- package/dist/eslint.cjs +9 -9
- package/dist/eslint.js +1 -1
- package/dist/oxlint.cjs +5 -5
- package/dist/oxlint.cjs.map +1 -1
- package/dist/oxlint.js +1 -1
- package/dist/oxlint.js.map +1 -1
- package/package.json +1 -1
package/dist/comments.d.cts
CHANGED
|
@@ -2,11 +2,12 @@ type StyleIssueType = 'semicolon' | 'em-dash' | 'dash' | 'label-colon' | 'emphas
|
|
|
2
2
|
|
|
3
3
|
interface WrapOptions {
|
|
4
4
|
/**
|
|
5
|
-
* Sets whether a line may not end with the first word of a sentence
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* the first
|
|
9
|
-
* the
|
|
5
|
+
* Sets whether a line may not end with the first word of a sentence or parenthetical, like
|
|
6
|
+
* `This` or `(the`, or with the first word after a semicolon or colon. Such a word moves to
|
|
7
|
+
* the next line instead. The word after a comma may end a line. It also sets whether a line
|
|
8
|
+
* avoids ending with the first two words of a sentence, and whether the first of two lines
|
|
9
|
+
* ends with a sentence instead of the start of the next one, as long as the second line is
|
|
10
|
+
* then no longer than the first.
|
|
10
11
|
*/
|
|
11
12
|
readonly avoidSentenceOrphans: boolean;
|
|
12
13
|
/**
|
|
@@ -54,9 +55,9 @@ interface AnalyzeOptions extends WrapOptions {
|
|
|
54
55
|
*/
|
|
55
56
|
readonly maxWidth?: number;
|
|
56
57
|
/**
|
|
57
|
-
* Sets the maximum length of the line that holds a comment whose whole text is one
|
|
58
|
-
*
|
|
59
|
-
*
|
|
58
|
+
* Sets the maximum length of the line that holds a comment whose whole text is one prose
|
|
59
|
+
* paragraph. Such a comment stays on one line up to this length plus `tolerance`, even past
|
|
60
|
+
* `width`, but never past `maxWidth`. It defaults to `width`.
|
|
60
61
|
*/
|
|
61
62
|
readonly singleLineWidth?: number;
|
|
62
63
|
readonly tabWidth: number;
|
|
@@ -84,10 +85,10 @@ interface ParagraphReport {
|
|
|
84
85
|
readonly reason?: string;
|
|
85
86
|
readonly issues: readonly IssueReport[];
|
|
86
87
|
/**
|
|
87
|
-
* Holds the exact source lines for `startLine` through `endLine` when the paragraph is
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
88
|
+
* Holds the exact source lines for `startLine` through `endLine` when the paragraph is greedily
|
|
89
|
+
* wrapped to the width, or `null` when the paragraph isn't prose, e.g. code, a table, a diagram,
|
|
90
|
+
* or `@example`. A paragraph that the tolerance accepts as it is, with the layout for a wider
|
|
91
|
+
* width or with lines close to this one, keeps its lines.
|
|
91
92
|
*/
|
|
92
93
|
readonly suggestion: readonly string[] | null;
|
|
93
94
|
}
|
|
@@ -228,24 +229,27 @@ interface CommentsConfig {
|
|
|
228
229
|
* Sets the maximum length of the line that holds a comment whose whole text is one prose
|
|
229
230
|
* paragraph. Such a comment stays on one line up to this length plus `tolerance`, even past
|
|
230
231
|
* `width`, and is wrapped to `width` beyond it. Defaults to 120, and the line never exceeds
|
|
231
|
-
* `maxWidth
|
|
232
|
+
* the `maxWidth` limit.
|
|
232
233
|
*/
|
|
233
234
|
readonly singleLineWidth?: number;
|
|
234
235
|
/**
|
|
235
|
-
* Sets how many columns prose lines may go past `width` when that saves a line in a paragraph
|
|
236
|
-
* three or more lines. A paragraph that already has the layout for a wider `width`, up to
|
|
237
|
-
* plus this many columns, also passes as it is.
|
|
238
|
-
*
|
|
236
|
+
* Sets how many columns prose lines may go past `width` when that saves a line in a paragraph
|
|
237
|
+
* of three or more lines. A paragraph that already has the layout for a wider `width`, up to
|
|
238
|
+
* `width` plus this many columns, also passes as it is. So does a paragraph with as many lines
|
|
239
|
+
* as the rewrap whose lines are each at most this many columns shorter or longer than in the
|
|
240
|
+
* rewrap. It never goes past `maxWidth`. When `maxWidth` is omitted, it also sets a legacy hard
|
|
241
|
+
* limit of `width + tolerance`.
|
|
239
242
|
*/
|
|
240
243
|
readonly tolerance?: number;
|
|
241
244
|
/**
|
|
242
245
|
* Keep the first word of a new sentence or parenthetical off the end of a line, e.g.
|
|
243
|
-
* `...the module. This` or `...reflows (the` followed by the rest on the next line.
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
* the
|
|
247
|
-
*
|
|
248
|
-
*
|
|
246
|
+
* `...the module. This` or `...reflows (the` followed by the rest on the next line. The same
|
|
247
|
+
* goes for the first word after a semicolon or colon, but not after a comma, so a line may
|
|
248
|
+
* end with `...the paths, and`. A paragraph of two lines also ends its first line with a
|
|
249
|
+
* sentence when the rest fits on the second line and is no longer than the first, instead
|
|
250
|
+
* of with the start of the next sentence, like `...the module. This one`. Other lines avoid
|
|
251
|
+
* ending with the first two words of a sentence, like `...opens. It allocates`, unless that
|
|
252
|
+
* makes them much less even. Defaults to `true`.
|
|
249
253
|
*/
|
|
250
254
|
readonly avoidSentenceOrphans?: boolean;
|
|
251
255
|
/**
|
package/dist/comments.d.ts
CHANGED
|
@@ -2,11 +2,12 @@ type StyleIssueType = 'semicolon' | 'em-dash' | 'dash' | 'label-colon' | 'emphas
|
|
|
2
2
|
|
|
3
3
|
interface WrapOptions {
|
|
4
4
|
/**
|
|
5
|
-
* Sets whether a line may not end with the first word of a sentence
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* the first
|
|
9
|
-
* the
|
|
5
|
+
* Sets whether a line may not end with the first word of a sentence or parenthetical, like
|
|
6
|
+
* `This` or `(the`, or with the first word after a semicolon or colon. Such a word moves to
|
|
7
|
+
* the next line instead. The word after a comma may end a line. It also sets whether a line
|
|
8
|
+
* avoids ending with the first two words of a sentence, and whether the first of two lines
|
|
9
|
+
* ends with a sentence instead of the start of the next one, as long as the second line is
|
|
10
|
+
* then no longer than the first.
|
|
10
11
|
*/
|
|
11
12
|
readonly avoidSentenceOrphans: boolean;
|
|
12
13
|
/**
|
|
@@ -54,9 +55,9 @@ interface AnalyzeOptions extends WrapOptions {
|
|
|
54
55
|
*/
|
|
55
56
|
readonly maxWidth?: number;
|
|
56
57
|
/**
|
|
57
|
-
* Sets the maximum length of the line that holds a comment whose whole text is one
|
|
58
|
-
*
|
|
59
|
-
*
|
|
58
|
+
* Sets the maximum length of the line that holds a comment whose whole text is one prose
|
|
59
|
+
* paragraph. Such a comment stays on one line up to this length plus `tolerance`, even past
|
|
60
|
+
* `width`, but never past `maxWidth`. It defaults to `width`.
|
|
60
61
|
*/
|
|
61
62
|
readonly singleLineWidth?: number;
|
|
62
63
|
readonly tabWidth: number;
|
|
@@ -84,10 +85,10 @@ interface ParagraphReport {
|
|
|
84
85
|
readonly reason?: string;
|
|
85
86
|
readonly issues: readonly IssueReport[];
|
|
86
87
|
/**
|
|
87
|
-
* Holds the exact source lines for `startLine` through `endLine` when the paragraph is
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
88
|
+
* Holds the exact source lines for `startLine` through `endLine` when the paragraph is greedily
|
|
89
|
+
* wrapped to the width, or `null` when the paragraph isn't prose, e.g. code, a table, a diagram,
|
|
90
|
+
* or `@example`. A paragraph that the tolerance accepts as it is, with the layout for a wider
|
|
91
|
+
* width or with lines close to this one, keeps its lines.
|
|
91
92
|
*/
|
|
92
93
|
readonly suggestion: readonly string[] | null;
|
|
93
94
|
}
|
|
@@ -228,24 +229,27 @@ interface CommentsConfig {
|
|
|
228
229
|
* Sets the maximum length of the line that holds a comment whose whole text is one prose
|
|
229
230
|
* paragraph. Such a comment stays on one line up to this length plus `tolerance`, even past
|
|
230
231
|
* `width`, and is wrapped to `width` beyond it. Defaults to 120, and the line never exceeds
|
|
231
|
-
* `maxWidth
|
|
232
|
+
* the `maxWidth` limit.
|
|
232
233
|
*/
|
|
233
234
|
readonly singleLineWidth?: number;
|
|
234
235
|
/**
|
|
235
|
-
* Sets how many columns prose lines may go past `width` when that saves a line in a paragraph
|
|
236
|
-
* three or more lines. A paragraph that already has the layout for a wider `width`, up to
|
|
237
|
-
* plus this many columns, also passes as it is.
|
|
238
|
-
*
|
|
236
|
+
* Sets how many columns prose lines may go past `width` when that saves a line in a paragraph
|
|
237
|
+
* of three or more lines. A paragraph that already has the layout for a wider `width`, up to
|
|
238
|
+
* `width` plus this many columns, also passes as it is. So does a paragraph with as many lines
|
|
239
|
+
* as the rewrap whose lines are each at most this many columns shorter or longer than in the
|
|
240
|
+
* rewrap. It never goes past `maxWidth`. When `maxWidth` is omitted, it also sets a legacy hard
|
|
241
|
+
* limit of `width + tolerance`.
|
|
239
242
|
*/
|
|
240
243
|
readonly tolerance?: number;
|
|
241
244
|
/**
|
|
242
245
|
* Keep the first word of a new sentence or parenthetical off the end of a line, e.g.
|
|
243
|
-
* `...the module. This` or `...reflows (the` followed by the rest on the next line.
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
* the
|
|
247
|
-
*
|
|
248
|
-
*
|
|
246
|
+
* `...the module. This` or `...reflows (the` followed by the rest on the next line. The same
|
|
247
|
+
* goes for the first word after a semicolon or colon, but not after a comma, so a line may
|
|
248
|
+
* end with `...the paths, and`. A paragraph of two lines also ends its first line with a
|
|
249
|
+
* sentence when the rest fits on the second line and is no longer than the first, instead
|
|
250
|
+
* of with the start of the next sentence, like `...the module. This one`. Other lines avoid
|
|
251
|
+
* ending with the first two words of a sentence, like `...opens. It allocates`, unless that
|
|
252
|
+
* makes them much less even. Defaults to `true`.
|
|
249
253
|
*/
|
|
250
254
|
readonly avoidSentenceOrphans?: boolean;
|
|
251
255
|
/**
|
package/dist/comments.js
CHANGED
|
@@ -128,6 +128,7 @@ function findStyleIssues(lines) {
|
|
|
128
128
|
// src/comments/wrap.ts
|
|
129
129
|
var CLAUSE_END = /[.!?,;:]["')\]*_]*$/;
|
|
130
130
|
var SENTENCE_END = /[.!?]["')\]*_]*$/;
|
|
131
|
+
var STATEMENT_END = /[.!?;:]["')\]*_]*$/;
|
|
131
132
|
var ABBREVIATIONS = /* @__PURE__ */ new Set([
|
|
132
133
|
"e.g.",
|
|
133
134
|
"i.e.",
|
|
@@ -359,8 +360,8 @@ function bindParentheticals(tokens, limit) {
|
|
|
359
360
|
}
|
|
360
361
|
return units;
|
|
361
362
|
}
|
|
362
|
-
function
|
|
363
|
-
return
|
|
363
|
+
function endsStatement(token) {
|
|
364
|
+
return STATEMENT_END.test(token) && !isAbbreviation(token);
|
|
364
365
|
}
|
|
365
366
|
function endsSentence(token) {
|
|
366
367
|
return SENTENCE_END.test(token) && !isAbbreviation(token);
|
|
@@ -369,7 +370,7 @@ function opensAside(token) {
|
|
|
369
370
|
return /^[([]/.test(token) && !/[)\]]["'`.,;:!?]*$/.test(token);
|
|
370
371
|
}
|
|
371
372
|
function isOrphan(previous, token) {
|
|
372
|
-
return opensAside(token) ||
|
|
373
|
+
return opensAside(token) || endsStatement(previous) && !CLAUSE_END.test(token);
|
|
373
374
|
}
|
|
374
375
|
function startsBlock(token) {
|
|
375
376
|
return /^(?:\+|-+|=+|\*+|_{3,}|\d+[.)]|#{1,6})$/.test(token) || /^(?:>|@[A-Za-z]|`{3}|~{3}|\||<(?:\/?[A-Za-z]|[!?]))/.test(token);
|
|
@@ -1383,7 +1384,20 @@ function analyzeParagraph(paragraph, options, language) {
|
|
|
1383
1384
|
}
|
|
1384
1385
|
return false;
|
|
1385
1386
|
};
|
|
1386
|
-
const
|
|
1387
|
+
const staysNearLayout = () => {
|
|
1388
|
+
if (currentLines.length !== wrapped.length || splitTokenLine(currentLines, units) !== -1) {
|
|
1389
|
+
return false;
|
|
1390
|
+
}
|
|
1391
|
+
return currentLines.every((words, position) => {
|
|
1392
|
+
const length = words.join(" ").length;
|
|
1393
|
+
const suggestedLength = wrapped[position].join(" ").length;
|
|
1394
|
+
const limit = (position === 0 ? firstLimit : restLimit) + layoutOptions.tolerance;
|
|
1395
|
+
return Math.abs(length - suggestedLength) <= layoutOptions.tolerance && length <= Math.max(suggestedLength, limit);
|
|
1396
|
+
});
|
|
1397
|
+
};
|
|
1398
|
+
const hasVerdict = lineIssues.some((issue) => isVerdict(issue));
|
|
1399
|
+
const onlyUnbalanced = lineIssues.every((issue) => issue.type === "unbalanced");
|
|
1400
|
+
const accepted = hasVerdict && (matchesWiderLayout() || onlyUnbalanced && staysNearLayout());
|
|
1387
1401
|
const suggested = accepted ? currentLines : wrapped;
|
|
1388
1402
|
const suggestion = suggested.map(
|
|
1389
1403
|
(words, position) => `${prefix}${position === 0 ? paragraph.marker : hang}${words.join(" ")}`
|
|
@@ -1730,7 +1744,7 @@ When rules pull in different directions, the earlier one wins.
|
|
|
1730
1744
|
## Layout
|
|
1731
1745
|
|
|
1732
1746
|
- 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.
|
|
1733
|
-
- Don't end a line with the first word of a new sentence
|
|
1747
|
+
- Don't end a line with the first word of a new sentence or parenthetical, like \`This\` after a period or \`(the\`, or with the first word after a semicolon or colon. 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. The word after a comma is no such word. A line may end with it, like \`and\` in \`...the teardown paths, and\`.
|
|
1734
1748
|
- 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.
|
|
1735
1749
|
- 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.
|
|
1736
1750
|
- Separate paragraphs with an empty comment line.
|