@d3lm/lint-preset 1.4.5 → 1.5.0
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 +166 -0
- package/dist/bin/comments.js +3162 -0
- package/dist/bin/comments.js.map +1 -0
- package/dist/{chunk-6LUTQQJB.cjs → chunk-M3BAUCCR.cjs} +20 -27
- package/dist/chunk-M3BAUCCR.cjs.map +1 -0
- package/dist/{chunk-QEMNOAEQ.js → chunk-SMTCD6GW.js} +20 -27
- package/dist/chunk-SMTCD6GW.js.map +1 -0
- package/dist/comments.cjs +1409 -0
- package/dist/comments.cjs.map +1 -0
- package/dist/comments.d.cts +257 -0
- package/dist/comments.d.ts +257 -0
- package/dist/comments.js +1407 -0
- package/dist/comments.js.map +1 -0
- package/dist/eslint.cjs +9 -9
- package/dist/eslint.js +1 -1
- package/dist/oxlint.cjs +10 -12
- package/dist/oxlint.cjs.map +1 -1
- package/dist/oxlint.js +6 -8
- package/dist/oxlint.js.map +1 -1
- package/dist/rules.cjs +50 -11
- package/dist/rules.cjs.map +1 -1
- package/dist/rules.js +50 -11
- package/dist/rules.js.map +1 -1
- package/package.json +13 -1
- package/dist/chunk-6LUTQQJB.cjs.map +0 -1
- package/dist/chunk-QEMNOAEQ.js.map +0 -1
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
type StyleIssueType = 'semicolon' | 'em-dash' | 'dash' | 'label-colon' | 'emphasis' | 'banner';
|
|
2
|
+
|
|
3
|
+
interface WrapOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Sets whether a line may not end with the first word of a sentence, clause, or parenthetical,
|
|
6
|
+
* like `This`, `the` after a comma, or `(the`. Such a word moves to the next line instead.
|
|
7
|
+
* It also sets whether the first of two lines ends with a sentence instead of the start of the
|
|
8
|
+
* next one, as long as the second line is then no longer than the first.
|
|
9
|
+
*/
|
|
10
|
+
readonly avoidSentenceOrphans: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Sets how many columns a line may exceed its limit before it counts as overflowing.
|
|
13
|
+
*/
|
|
14
|
+
readonly tolerance: number;
|
|
15
|
+
/**
|
|
16
|
+
* Sets how many extra columns a complete parenthetical may use beyond the preferred line limit.
|
|
17
|
+
*/
|
|
18
|
+
readonly parentheticalOverflow?: number;
|
|
19
|
+
}
|
|
20
|
+
type LineIssueType = 'overflow' | 'underfill' | 'orphan' | 'widow' | 'unbalanced';
|
|
21
|
+
/**
|
|
22
|
+
* JSDoc writes types and `{@link ...}` tags as `{...}` groups, so they stay intact like code spans.
|
|
23
|
+
*/
|
|
24
|
+
declare function tokenize(text: string): string[];
|
|
25
|
+
/**
|
|
26
|
+
* The first line can have a different limit than the rest, e.g. when a list marker takes up space
|
|
27
|
+
* only on the first line.
|
|
28
|
+
*/
|
|
29
|
+
declare function wrapTokens(tokens: readonly string[], firstLimit: number, restLimit: number, options: WrapOptions): string[][];
|
|
30
|
+
|
|
31
|
+
type CommentKind = 'jsdoc' | 'block';
|
|
32
|
+
type ParagraphKind = 'prose' | 'list' | 'tag' | 'code' | 'other';
|
|
33
|
+
interface AnalyzeOptions extends WrapOptions {
|
|
34
|
+
/**
|
|
35
|
+
* Sets the preferred line length, including indentation and the comment prefix.
|
|
36
|
+
*/
|
|
37
|
+
readonly width: number;
|
|
38
|
+
/**
|
|
39
|
+
* Sets the hard limit for measured prose. Parentheticals may exceed `width` up to this limit.
|
|
40
|
+
* When omitted, the existing width and tolerance behavior is retained.
|
|
41
|
+
*/
|
|
42
|
+
readonly maxWidth?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Sets the maximum length of the line that holds a comment whose whole text is one
|
|
45
|
+
* prose paragraph. Such a comment stays on one line up to this length, even past
|
|
46
|
+
* `width`. It defaults to `width`.
|
|
47
|
+
*/
|
|
48
|
+
readonly singleLineWidth?: number;
|
|
49
|
+
readonly tabWidth: number;
|
|
50
|
+
/**
|
|
51
|
+
* Whether to report prose style issues like semicolons, em-dashes, and section banners.
|
|
52
|
+
*/
|
|
53
|
+
readonly style: boolean;
|
|
54
|
+
}
|
|
55
|
+
type IssueType = LineIssueType | StyleIssueType;
|
|
56
|
+
type IssueTier = 'verdict' | 'hint';
|
|
57
|
+
interface IssueReport {
|
|
58
|
+
readonly type: IssueType;
|
|
59
|
+
readonly tier: IssueTier;
|
|
60
|
+
readonly line: number;
|
|
61
|
+
readonly length: number;
|
|
62
|
+
}
|
|
63
|
+
interface ParagraphReport {
|
|
64
|
+
readonly kind: ParagraphKind;
|
|
65
|
+
readonly startLine: number;
|
|
66
|
+
readonly endLine: number;
|
|
67
|
+
/**
|
|
68
|
+
* Whether the paragraph is prose that can be rewrapped. When `false`, `reason` says why.
|
|
69
|
+
*/
|
|
70
|
+
readonly reflowable: boolean;
|
|
71
|
+
readonly reason?: string;
|
|
72
|
+
readonly issues: readonly IssueReport[];
|
|
73
|
+
/**
|
|
74
|
+
* Holds the exact source lines for `startLine` through `endLine` when the paragraph is
|
|
75
|
+
* greedily wrapped to the width, or `null` when the paragraph isn't prose, e.g. code,
|
|
76
|
+
* a table, a diagram, or `@example`.
|
|
77
|
+
*/
|
|
78
|
+
readonly suggestion: readonly string[] | null;
|
|
79
|
+
}
|
|
80
|
+
interface CommentReport {
|
|
81
|
+
readonly file: string;
|
|
82
|
+
readonly kind: CommentKind;
|
|
83
|
+
readonly startLine: number;
|
|
84
|
+
readonly endLine: number;
|
|
85
|
+
readonly indent: string;
|
|
86
|
+
readonly width: number;
|
|
87
|
+
readonly maxWidth?: number;
|
|
88
|
+
/**
|
|
89
|
+
* Holds the length of each source line from `startLine` through `endLine`, with tabs expanded.
|
|
90
|
+
*/
|
|
91
|
+
readonly lengths: readonly number[];
|
|
92
|
+
readonly text: string;
|
|
93
|
+
readonly paragraphs: readonly ParagraphReport[];
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Finds all own-line block and JSDoc comments in a JavaScript or TypeScript source file and reports
|
|
97
|
+
* how each paragraph deviates from a greedy wrap at `options.width`. Line comments (`//`) are never
|
|
98
|
+
* analyzed. A source with a syntax error that stops the parser has no reports.
|
|
99
|
+
*/
|
|
100
|
+
declare function analyzeSource(source: string, filename: string, options: AnalyzeOptions): CommentReport[];
|
|
101
|
+
/**
|
|
102
|
+
* Whether the comment has any issue, including hints, which makes it worth handing to the agent.
|
|
103
|
+
*/
|
|
104
|
+
declare function isSuspicious(report: CommentReport): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Whether the comment has an issue that isn't a hint, so it breaks the rules no matter what
|
|
107
|
+
* the agent decided.
|
|
108
|
+
*/
|
|
109
|
+
declare function hasVerdictIssues(report: CommentReport): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Returns the comment's source text with every prose paragraph replaced by its suggestion.
|
|
112
|
+
* Code, tables, diagrams, and similar paragraphs are kept as they are.
|
|
113
|
+
*/
|
|
114
|
+
declare function rewrapComment(report: CommentReport): string;
|
|
115
|
+
/**
|
|
116
|
+
* Returns the syntax tree of the source as JSON, without positions or comments, used to verify
|
|
117
|
+
* that only comments changed. Moving or rewording a comment keeps it the same, while any change
|
|
118
|
+
* to a string, template, regex, JSX text, or where a statement ends changes it. A source that
|
|
119
|
+
* doesn't parse has no tree to compare, so all of its text counts.
|
|
120
|
+
*/
|
|
121
|
+
declare function codeFingerprint(source: string, filename: string): string;
|
|
122
|
+
|
|
123
|
+
type AgentRunner = 'claude' | 'codex' | 'cursor';
|
|
124
|
+
type HookMode = 'agent' | 'report' | 'off';
|
|
125
|
+
type AgentScope = 'suspicious' | 'all';
|
|
126
|
+
interface AgentConfig {
|
|
127
|
+
/**
|
|
128
|
+
* Names the agent CLI to spawn. Defaults to the host that triggered the hook, or `claude`
|
|
129
|
+
* when run standalone.
|
|
130
|
+
*/
|
|
131
|
+
readonly runner?: AgentRunner;
|
|
132
|
+
/**
|
|
133
|
+
* Names the model passed to the runner. Defaults to `haiku` for Claude Code and to the
|
|
134
|
+
* CLI's default otherwise.
|
|
135
|
+
*/
|
|
136
|
+
readonly model?: string;
|
|
137
|
+
/**
|
|
138
|
+
* Lists extra arguments appended to the runner's command line.
|
|
139
|
+
*/
|
|
140
|
+
readonly args?: readonly string[];
|
|
141
|
+
/**
|
|
142
|
+
* Sets a fully custom command, e.g. `['my-agent', '--prompt', '{prompt}']`. Without a `{prompt}`
|
|
143
|
+
* placeholder, the prompt is written to stdin. Overrides `runner`, `model`, and `args`.
|
|
144
|
+
*/
|
|
145
|
+
readonly command?: readonly string[];
|
|
146
|
+
/**
|
|
147
|
+
* Sets how many seconds to wait for each agent before giving up. Defaults to 300.
|
|
148
|
+
*/
|
|
149
|
+
readonly timeout?: number;
|
|
150
|
+
/**
|
|
151
|
+
* Sets the most comments to hand to one agent. More comments are split across several agents.
|
|
152
|
+
* A file's comments always go to the same agent, since parallel agents editing one file would
|
|
153
|
+
* overwrite each other's edits, so a file with more comments than this gets an agent of its
|
|
154
|
+
* own. Defaults to 20.
|
|
155
|
+
*/
|
|
156
|
+
readonly batchSize?: number;
|
|
157
|
+
/**
|
|
158
|
+
* Sets the most files to hand to one agent, since an agent editing many files is slower and less
|
|
159
|
+
* careful. More files are split across several agents. Defaults to 10.
|
|
160
|
+
*/
|
|
161
|
+
readonly maxFiles?: number;
|
|
162
|
+
/**
|
|
163
|
+
* Caps how many agents run at once. The other agents wait, and each one starts when a running
|
|
164
|
+
* agent finishes. Defaults to 6.
|
|
165
|
+
*/
|
|
166
|
+
readonly maxAgents?: number;
|
|
167
|
+
/**
|
|
168
|
+
* Points to a Markdown file with formatting rules, relative to the config file.
|
|
169
|
+
* Replaces the built-in rules.
|
|
170
|
+
*/
|
|
171
|
+
readonly rules?: string;
|
|
172
|
+
/**
|
|
173
|
+
* Holds extra instructions appended to the rules.
|
|
174
|
+
*/
|
|
175
|
+
readonly instructions?: string;
|
|
176
|
+
/**
|
|
177
|
+
* Selects which comments the agent sees. `suspicious` (default) is a triage, not a full review.
|
|
178
|
+
* It only sends comments with hints, like a possible semicolon or a line that may end with the
|
|
179
|
+
* first word of a sentence, and comments with issues in parts the tool never rewraps, so most
|
|
180
|
+
* runs never call the agent. The tool fixes the layout of prose itself. `all` sends every comment
|
|
181
|
+
* in changed lines, so that the agent reviews the wording of each against its rules.
|
|
182
|
+
*/
|
|
183
|
+
readonly scope?: AgentScope;
|
|
184
|
+
}
|
|
185
|
+
interface HookConfig {
|
|
186
|
+
/**
|
|
187
|
+
* Sets what the stop hook does with comments in changed lines.
|
|
188
|
+
*
|
|
189
|
+
* - `agent` (default): hand them to an agent and report any that still don't fit afterwards.
|
|
190
|
+
* - `report`: only report suspicious comments.
|
|
191
|
+
* - `off`: do nothing.
|
|
192
|
+
*/
|
|
193
|
+
readonly mode?: HookMode;
|
|
194
|
+
}
|
|
195
|
+
interface CommentsConfig {
|
|
196
|
+
/**
|
|
197
|
+
* Sets the preferred line length for comments, including indentation and the comment prefix.
|
|
198
|
+
* Defaults to prettier's `printWidth`, or 80.
|
|
199
|
+
*/
|
|
200
|
+
readonly width?: number;
|
|
201
|
+
/**
|
|
202
|
+
* Sets the hard limit for measured prose. Defaults to 120, or `width` when it is larger.
|
|
203
|
+
* Parentheticals may use the space between `width` and this limit to stay together.
|
|
204
|
+
*/
|
|
205
|
+
readonly maxWidth?: number;
|
|
206
|
+
/**
|
|
207
|
+
* Sets the maximum length of the line that holds a comment whose whole text is one prose
|
|
208
|
+
* paragraph. Such a comment stays on one line up to this length, even past `width`, and is
|
|
209
|
+
* wrapped to `width` beyond it. Defaults to 120 and never exceeds `maxWidth`.
|
|
210
|
+
*/
|
|
211
|
+
readonly singleLineWidth?: number;
|
|
212
|
+
/**
|
|
213
|
+
* Sets a legacy hard limit of `width + tolerance` when `maxWidth` is omitted.
|
|
214
|
+
* An explicit `maxWidth` takes precedence.
|
|
215
|
+
*/
|
|
216
|
+
readonly tolerance?: number;
|
|
217
|
+
/**
|
|
218
|
+
* Keep the first word of a new sentence or parenthetical off the end of a line, e.g.
|
|
219
|
+
* `...the module. This` or `...reflows (the` followed by the rest on the next line.
|
|
220
|
+
* A paragraph of two lines also ends its first line with a sentence when the rest fits
|
|
221
|
+
* on the second line and is no longer than the first, instead of with the start of the
|
|
222
|
+
* next sentence, like `...the module. This one`. Defaults to `true`.
|
|
223
|
+
*/
|
|
224
|
+
readonly avoidSentenceOrphans?: boolean;
|
|
225
|
+
/**
|
|
226
|
+
* Looks for possible style issues (semicolons, em-dashes and dashes, `label: explanation` colons,
|
|
227
|
+
* asterisk emphasis, and section banners) and reports them as hints, so that the `suspicious` scope
|
|
228
|
+
* hands those comments to the agent too. It only controls this search, and the agent's rules apply
|
|
229
|
+
* to every comment the agent sees either way. Defaults to `true`.
|
|
230
|
+
*/
|
|
231
|
+
readonly style?: boolean;
|
|
232
|
+
/**
|
|
233
|
+
* Lists the file extensions to process. Defaults to JavaScript and TypeScript extensions.
|
|
234
|
+
*/
|
|
235
|
+
readonly extensions?: readonly string[];
|
|
236
|
+
/**
|
|
237
|
+
* Lists glob patterns, relative to the repository root, of files to skip.
|
|
238
|
+
*/
|
|
239
|
+
readonly ignore?: readonly string[];
|
|
240
|
+
readonly agent?: AgentConfig;
|
|
241
|
+
readonly hook?: HookConfig;
|
|
242
|
+
}
|
|
243
|
+
declare function defineConfig(config: CommentsConfig): CommentsConfig;
|
|
244
|
+
declare function loadConfig(cwd: string, options?: {
|
|
245
|
+
explicitPath?: string;
|
|
246
|
+
stopDir?: string;
|
|
247
|
+
}): Promise<{
|
|
248
|
+
config: CommentsConfig;
|
|
249
|
+
filepath: string;
|
|
250
|
+
} | {
|
|
251
|
+
config: {};
|
|
252
|
+
filepath?: undefined;
|
|
253
|
+
}>;
|
|
254
|
+
|
|
255
|
+
declare const DEFAULT_RULES: string;
|
|
256
|
+
|
|
257
|
+
export { type AgentConfig, type AgentRunner, type AgentScope, type AnalyzeOptions, type CommentKind, type CommentReport, type CommentsConfig, DEFAULT_RULES, type HookConfig, type HookMode, type IssueReport, type IssueTier, type ParagraphKind, type ParagraphReport, analyzeSource, codeFingerprint, defineConfig, hasVerdictIssues, isSuspicious, loadConfig, rewrapComment, tokenize, wrapTokens };
|