@siim-m/config 0.2.0 → 0.3.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.
@@ -0,0 +1,376 @@
1
+ import { defineRule } from '@oxlint/plugins';
2
+ const DIRECTIVE = /^(?:(?:oxlint|eslint)-(?:disable|enable|env)\b|eslint\s+[\w@/-]+\s*:\s*(?:off|warn|error|[012]|\[)|@ts-(?:expect-error|ignore|nocheck|check)\b|@effect-diagnostics|(?:prettier|oxfmt)-ignore|biome-ignore|svelte-ignore|(?:c8|v8|istanbul)\s+ignore|@(?:vitest|jest)-environment|@vite-ignore|webpack[A-Z]\w*:|@jsx|[@#]__(?:PURE|NO_SIDE_EFFECTS|INLINE|NOINLINE)__|\/\s*<(?:reference|amd-module|amd-dependency)\s|#\s*source(?:Mapping)?URL=|#(?:end)?region\b|nosemgrep\b)/u;
3
+ const LICENSE = /@license\b|\bSPDX-License-Identifier\b/u;
4
+ const COPYRIGHT = /\bcopyright\b/iu;
5
+ const SUPPRESSION = /^\s*\*?\s*(?:(?:oxlint|eslint)-disable|@ts-(?:expect-error|ignore|nocheck))/u;
6
+ const URL = /\bhttps?:\/\/\S+/gu;
7
+ const CODE_SPAN = /`[^`]*`/gu;
8
+ const ISSUE = /(?<![\w&/])#\d+\b(?![a-f])/giu;
9
+ const DIVIDER = /^(?:[-=*#~_/+\u2500-\u257F]{3,}(?:\s.*)?|.*[-=*#~_\u2500-\u257F]{3,})$/u;
10
+ const STEP_LABEL = /^(?:arrange|act|assert|given|when|then)\s*[:.]?$/iu;
11
+ const TASK_MARKER = /\b(?:TODO|FIXME|HACK)\b|(?<!-)\bXXX\b(?!-)/u;
12
+ /** A markdown heading, which a doc comment may use: `### Example`. */
13
+ const HEADING = /^#{1,6}\s+\S/u;
14
+ const TASK_LINK = /#\d+|\b[A-Z][A-Z\d]*-\d+\b|https?:\/\//u;
15
+ const JSDOC_TYPE = /^@(?:param|returns?|type|typedef)\s+\{/u;
16
+ const EMPTY_JSDOC_TAG = /^@(?:param(?:\s+\[?[\w$.]+\]?)?|returns?)$/u;
17
+ const COMMENTED_CODE = /^(?:(?:(?:const|let|var)\s+[\w${}[\], ]+=.*|import\s.+\sfrom\s+["'].+["']|(?:await\s+|return\s+)?[\w$.]+\(.*\)|[\w$.[\]]+\s*=\s*.+);|(?:if|for|while|switch)\s*\(.*\)\s*\{|\}(?:\s*else\s*\{)?)$/u;
18
+ const TYPESCRIPT_FILE = /\.[cm]?tsx?$/u;
19
+ const FILLER = new Set('a an the of for to in on at by with from and or is are be this that it its as'.split(' '));
20
+ /** The words a comment or name carries once filler words go and plurals fold. */
21
+ const contentWords = (text) => (text.toLowerCase().match(/[a-z0-9]+/gu) ?? [])
22
+ .filter((word) => !FILLER.has(word))
23
+ .map((word) => (word.length > 3 ? word.replace(/([^s])s$/u, '$1') : word))
24
+ .filter((word) => !FILLER.has(word));
25
+ const nameWords = (name) => new Set(contentWords(name.replace(/([a-z0-9])([A-Z])/gu, '$1 $2').replace(/([A-Z]+)([A-Z][a-z])/gu, '$1 $2')));
26
+ const isDoc = (comment) => comment.type === 'Block' && comment.value.startsWith('*');
27
+ /** A comment's lines of prose: no doc-comment stars, blank lines or directives. */
28
+ const textLines = (comment) => {
29
+ const lines = comment.value
30
+ .split('\n')
31
+ .map((line) => line.replace(/^\s*\*?\s?/u, '').trim())
32
+ .filter((line) => line !== '' && line !== '*');
33
+ // A block that opens with a directive, such as a multi-line `oxlint-disable`, is all directive.
34
+ if (comment.type === 'Block' && DIRECTIVE.test(lines[0] ?? ''))
35
+ return [];
36
+ return lines.filter((line) => !DIRECTIVE.test(line));
37
+ };
38
+ /** A comment that holds only directives, such as `// oxlint-disable-next-line rule -- reason`. */
39
+ const isDirective = (comment) => comment.value.trim() !== '' && textLines(comment).length === 0;
40
+ /** Adjacent `//` lines at one indent read as one comment; a directive stands alone. */
41
+ function commentGroups(comments, text) {
42
+ const groups = [];
43
+ for (const comment of comments) {
44
+ if (comment.type === 'Shebang')
45
+ continue;
46
+ const group = groups.at(-1);
47
+ const previous = group?.at(-1);
48
+ const continues = group !== undefined &&
49
+ previous !== undefined &&
50
+ !isDirective(previous) &&
51
+ !isDirective(comment) &&
52
+ previous?.type === 'Line' &&
53
+ comment.type === 'Line' &&
54
+ previous.loc.start.column === comment.loc.start.column &&
55
+ /^[ \t]*\r?\n[ \t]*$/u.test(text.slice(previous.end, comment.start));
56
+ if (continues)
57
+ group.push(comment);
58
+ else
59
+ groups.push([comment]);
60
+ }
61
+ return groups;
62
+ }
63
+ /** The doc comment directly above a node, looking past directives such as `oxlint-disable-next-line`. */
64
+ function docBefore(node, sourceCode) {
65
+ const comments = sourceCode.getCommentsBefore(node);
66
+ let comment = comments.pop();
67
+ while (comment !== undefined && !isDoc(comment) && textLines(comment).length === 0)
68
+ comment = comments.pop();
69
+ return comment !== undefined && isDoc(comment) ? comment : undefined;
70
+ }
71
+ const isExport = (node) => node.type === 'ExportNamedDeclaration' ||
72
+ node.type === 'ExportDefaultDeclaration' ||
73
+ node.type === 'ExportAllDeclaration';
74
+ /** Top-level statements that export, and declarations of a binding that `export { name }` or `export default name` exports. */
75
+ function exportedStatements(program, sourceCode) {
76
+ const names = new Set();
77
+ for (const statement of program.body) {
78
+ if (statement.type === 'ExportNamedDeclaration' &&
79
+ statement.declaration === null &&
80
+ statement.source === null) {
81
+ for (const specifier of statement.specifiers) {
82
+ if (specifier.local.type === 'Identifier')
83
+ names.add(specifier.local.name);
84
+ }
85
+ }
86
+ else if (statement.type === 'ExportDefaultDeclaration' &&
87
+ statement.declaration.type === 'Identifier') {
88
+ names.add(statement.declaration.name);
89
+ }
90
+ }
91
+ const exported = new Set();
92
+ for (const statement of program.body) {
93
+ if (isExport(statement)) {
94
+ exported.add(statement);
95
+ }
96
+ else if (statement.type === 'VariableDeclaration') {
97
+ for (const declarator of statement.declarations) {
98
+ const declared = sourceCode.getDeclaredVariables(declarator);
99
+ if (declared.some((variable) => names.has(variable.name)))
100
+ exported.add(declarator);
101
+ }
102
+ }
103
+ else if ('id' in statement &&
104
+ statement.id?.type === 'Identifier' &&
105
+ names.has(statement.id.name)) {
106
+ exported.add(statement);
107
+ }
108
+ }
109
+ return exported;
110
+ }
111
+ /** The statement a doc comment for an exported node sits above. */
112
+ const docTarget = (node) => node.type === 'VariableDeclarator' && node.parent !== null ? node.parent : node;
113
+ /**
114
+ * Whether a suppression directive follows a comment group on the next lines, past other
115
+ * directives, so the group is its reason, as `require-suppression-reason` reads it.
116
+ */
117
+ function suppressionFollows(groups, index, ownLine) {
118
+ let line = groups[index]?.at(-1)?.loc.end.line ?? 0;
119
+ for (let next = index + 1; next < groups.length; next++) {
120
+ const comment = groups[next]?.[0];
121
+ if (comment === undefined || comment.loc.start.line !== line + 1)
122
+ return false;
123
+ // A reason may sit above a line that ends in `// oxlint-disable-line rule`.
124
+ if (!ownLine(comment))
125
+ return SUPPRESSION.test(comment.value);
126
+ if (SUPPRESSION.test(comment.value))
127
+ return true;
128
+ if (!isDirective(comment) && comment.value.replace(/[\s*]/gu, '') !== '')
129
+ return false;
130
+ line = comment.loc.end.line;
131
+ }
132
+ return false;
133
+ }
134
+ const FUNCTIONS = new Set([
135
+ 'ArrowFunctionExpression',
136
+ 'FunctionExpression',
137
+ 'FunctionDeclaration',
138
+ ]);
139
+ /** Whether a member belongs to an exported declaration and is public: not in a function body, not private. */
140
+ function isExposedMember(member, exported) {
141
+ let node = member;
142
+ for (;;) {
143
+ if (node.type === 'BlockStatement' || node.type === 'StaticBlock')
144
+ return false;
145
+ if ('accessibility' in node &&
146
+ (node.accessibility === 'private' || node.accessibility === 'protected')) {
147
+ return false;
148
+ }
149
+ if ('key' in node && node.key.type === 'PrivateIdentifier')
150
+ return false;
151
+ if (exported.has(node))
152
+ return true;
153
+ const parent = node.parent;
154
+ if (parent === null || parent.type === 'Program')
155
+ return false;
156
+ if (FUNCTIONS.has(parent.type) && 'body' in parent && parent.body === node)
157
+ return false;
158
+ node = parent;
159
+ }
160
+ }
161
+ /**
162
+ * Hold comments to a short why: a word budget, at most one cited issue, configured patterns, and
163
+ * no dividers, step labels, commented-out code, untracked TODOs, JSDoc types or comments that only
164
+ * repeat the name below them. `tagged-only` keeps just directives, licence headers, docs on exports
165
+ * and comments that start with an allowed prefix such as `SAFETY:`.
166
+ */
167
+ export const commentsRule = defineRule({
168
+ meta: {
169
+ type: 'suggestion',
170
+ docs: {
171
+ description: 'Hold comments to a short why, or with the tagged-only policy, to tagged comments and docs on exports.',
172
+ },
173
+ schema: [
174
+ {
175
+ type: 'object',
176
+ properties: {
177
+ policy: { enum: ['budget', 'tagged-only'] },
178
+ maxWords: { type: 'integer', minimum: 1 },
179
+ maxExportDocWords: { type: 'integer', minimum: 1 },
180
+ allow: { type: 'array', items: { type: 'string', minLength: 1 } },
181
+ forbidden: {
182
+ type: 'array',
183
+ items: {
184
+ type: 'object',
185
+ properties: { pattern: { type: 'string' }, message: { type: 'string' } },
186
+ required: ['pattern', 'message'],
187
+ additionalProperties: false,
188
+ },
189
+ },
190
+ },
191
+ additionalProperties: false,
192
+ },
193
+ ],
194
+ defaultOptions: [
195
+ {
196
+ policy: 'budget',
197
+ maxWords: 30,
198
+ maxExportDocWords: 45,
199
+ allow: ['SAFETY', 'SYNC', 'WARNING'],
200
+ forbidden: [],
201
+ },
202
+ ],
203
+ messages: {
204
+ tooLong: "This comment has {{words}} words; the limit is {{max}}. Keep the why the code can't say, and leave the history to git and the PR.",
205
+ issueChain: 'This comment cites {{count}} issues. Cite the one that decided the code; git has the rest.',
206
+ forbidden: 'This comment has `{{match}}` in it. {{message}}',
207
+ divider: "Drop the section divider. Split the file, or let the code's structure show the grouping.",
208
+ stepLabel: 'Drop the test step label.',
209
+ commentedOutCode: 'Delete the commented-out code; git keeps it.',
210
+ restatesName: 'This comment only repeats the name below it. Say why, or say nothing.',
211
+ untrackedTask: 'Link the issue that tracks this, or drop the marker.',
212
+ jsdocType: 'Drop the JSDoc type; TypeScript has it.',
213
+ emptyJsdocTag: 'Drop the JSDoc tag that has no description.',
214
+ untagged: 'Remove this comment: put the meaning in names and the rationale in the PR. Comments that start with {{prefixes}}, directives and docs on exports stay.',
215
+ },
216
+ },
217
+ create(context) {
218
+ // SAFETY: oxlint validates the options against the schema above and fills in defaultOptions.
219
+ const [options] = context.options;
220
+ const { sourceCode } = context;
221
+ const typescript = TYPESCRIPT_FILE.test(context.filename);
222
+ const forbidden = options.forbidden.map(({ pattern, message }) => ({
223
+ pattern: new RegExp(pattern, 'u'),
224
+ message,
225
+ }));
226
+ const isTagged = (line) => options.allow.some((prefix) => line.startsWith(`${prefix}:`) && line.slice(prefix.length + 1).trim() !== '');
227
+ const prefixes = options.allow.map((prefix) => `\`${prefix}:\``).join(', ');
228
+ const members = [];
229
+ /** Declarations and members by where they start, for the name a comment sits above. */
230
+ const named = new Map();
231
+ const name = (node, id) => {
232
+ if (id?.type === 'Identifier')
233
+ named.set(node.start, id.name);
234
+ else if (id?.type === 'Literal' && typeof id.value === 'string')
235
+ named.set(node.start, id.value);
236
+ };
237
+ const collect = (node) => {
238
+ members.push(node);
239
+ if ('key' in node)
240
+ name(node, node.key);
241
+ else if ('id' in node)
242
+ name(node, node.id);
243
+ };
244
+ const declaration = (node) => {
245
+ if (node.type === 'VariableDeclaration')
246
+ name(node, node.declarations[0]?.id);
247
+ else if ('id' in node)
248
+ name(node, node.id);
249
+ };
250
+ const exported = (node) => {
251
+ const inner = node.declaration;
252
+ if (inner === null)
253
+ return;
254
+ if (inner.type === 'VariableDeclaration')
255
+ name(node, inner.declarations[0]?.id);
256
+ else if ('id' in inner)
257
+ name(node, inner.id);
258
+ };
259
+ const restatesName = (last, lines) => {
260
+ if (lines.some((line) => line.startsWith('@')))
261
+ return false;
262
+ // A trailing comment belongs to the code before it on its line.
263
+ const before = (sourceCode.lines[last.loc.start.line - 1] ?? '').slice(0, last.loc.start.column);
264
+ if (before.trim() !== '')
265
+ return false;
266
+ const next = sourceCode.getTokenAfter(last);
267
+ const name = next === null ? undefined : named.get(next.start);
268
+ if (name === undefined)
269
+ return false;
270
+ const words = contentWords(lines.join(' '));
271
+ const fromName = nameWords(name);
272
+ return words.length > 0 && words.length <= 6 && words.every((word) => fromName.has(word));
273
+ };
274
+ /** The first problem with a comment, as a message id and its data. */
275
+ const problem = (group, lines, exportDoc, explainsSuppression) => {
276
+ const isLine = group[0]?.type === 'Line';
277
+ const body = lines.join('\n');
278
+ const prose = body.replace(URL, '');
279
+ if (options.policy === 'tagged-only' &&
280
+ !exportDoc &&
281
+ !explainsSuppression &&
282
+ !isTagged(lines[0] ?? '')) {
283
+ return ['untagged', { prefixes }];
284
+ }
285
+ const isDoc = group[0]?.type === 'Block' && group[0].value.startsWith('*');
286
+ if (lines.some((line) => DIVIDER.test(line) && !(isDoc && HEADING.test(line))))
287
+ return ['divider'];
288
+ if (isLine && lines.length === 1 && STEP_LABEL.test(body))
289
+ return ['stepLabel'];
290
+ if (isLine && lines.every((line) => COMMENTED_CODE.test(line)))
291
+ return ['commentedOutCode'];
292
+ if (TASK_MARKER.test(body) && !TASK_LINK.test(body))
293
+ return ['untrackedTask'];
294
+ const issues = new Set(prose.replace(CODE_SPAN, '').match(ISSUE) ?? []);
295
+ if (issues.size > 1)
296
+ return ['issueChain', { count: issues.size }];
297
+ if (typescript && lines.some((line) => JSDOC_TYPE.test(line)))
298
+ return ['jsdocType'];
299
+ const describedLater = (index) => (lines[index + 1] ?? '@').startsWith('@') === false;
300
+ if (lines.some((line, index) => EMPTY_JSDOC_TAG.test(line) && !describedLater(index)))
301
+ return ['emptyJsdocTag'];
302
+ const last = group.at(-1);
303
+ if (last !== undefined && restatesName(last, lines))
304
+ return ['restatesName'];
305
+ const words = body.split(/\s+/u).filter((word) => word !== '').length;
306
+ const max = exportDoc ? options.maxExportDocWords : options.maxWords;
307
+ if (words > max)
308
+ return ['tooLong', { words, max }];
309
+ for (const { pattern, message } of forbidden) {
310
+ const match = pattern.exec(prose)?.[0];
311
+ if (match !== undefined)
312
+ return ['forbidden', { match, message }];
313
+ }
314
+ return undefined;
315
+ };
316
+ return {
317
+ TSPropertySignature: collect,
318
+ TSMethodSignature: collect,
319
+ TSIndexSignature: collect,
320
+ TSCallSignatureDeclaration: collect,
321
+ TSConstructSignatureDeclaration: collect,
322
+ TSEnumMember: collect,
323
+ PropertyDefinition: collect,
324
+ MethodDefinition: collect,
325
+ Property: collect,
326
+ VariableDeclaration: declaration,
327
+ FunctionDeclaration: declaration,
328
+ ClassDeclaration: declaration,
329
+ TSDeclareFunction: declaration,
330
+ TSInterfaceDeclaration: declaration,
331
+ TSTypeAliasDeclaration: declaration,
332
+ TSEnumDeclaration: declaration,
333
+ ExportNamedDeclaration: exported,
334
+ ExportDefaultDeclaration: exported,
335
+ 'Program:exit'(program) {
336
+ const exportedNodes = exportedStatements(program, sourceCode);
337
+ const exportDocs = new Set();
338
+ const addDoc = (node) => {
339
+ const doc = docBefore(node, sourceCode);
340
+ if (doc !== undefined)
341
+ exportDocs.add(doc.start);
342
+ };
343
+ for (const node of exportedNodes)
344
+ addDoc(docTarget(node));
345
+ for (const member of members)
346
+ if (isExposedMember(member, exportedNodes))
347
+ addDoc(member);
348
+ const codeStart = program.body[0]?.start ?? sourceCode.text.length;
349
+ const groups = commentGroups(sourceCode.getAllComments(), sourceCode.text);
350
+ const ownLine = (comment) => (sourceCode.lines[comment.loc.start.line - 1] ?? '')
351
+ .slice(0, comment.loc.start.column)
352
+ .trim() === '';
353
+ for (const [index, group] of groups.entries()) {
354
+ const first = group[0];
355
+ const last = group.at(-1);
356
+ if (first === undefined || last === undefined)
357
+ continue;
358
+ const licence = first.value.startsWith('!') ||
359
+ group.some((comment) => LICENSE.test(comment.value)) ||
360
+ (last.end <= codeStart && group.some((comment) => COPYRIGHT.test(comment.value)));
361
+ const lines = group.flatMap(textLines);
362
+ if (licence || lines.length === 0)
363
+ continue;
364
+ const explainsSuppression = options.policy === 'tagged-only' &&
365
+ ownLine(first) &&
366
+ suppressionFollows(groups, index, ownLine);
367
+ const found = problem(group, lines, group.length === 1 && exportDocs.has(first.start), explainsSuppression);
368
+ if (found === undefined)
369
+ continue;
370
+ const [messageId, data] = found;
371
+ context.report({ loc: { start: first.loc.start, end: last.loc.end }, messageId, data });
372
+ }
373
+ },
374
+ };
375
+ },
376
+ });
@@ -0,0 +1,2 @@
1
+ /** Disallow inline disables of the type-assertion rules, and disables that name no rule at all. */
2
+ export declare const noDisabledTypeAssertionRulesRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,94 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ /** The rules that keep type assertions out. An inline disable of any of them lets a cast through. */
3
+ const defaultTypeAssertionRules = [
4
+ "anti-slop/no-chained-type-assertions",
5
+ "anti-slop/no-widen-then-assert",
6
+ "anti-slop/require-safety-comment-for-type-assertion",
7
+ "effecttsgo/unsafe-effect-type-assertion",
8
+ "typescript/consistent-type-assertions",
9
+ "typescript/no-unsafe-type-assertion",
10
+ ];
11
+ const directivePattern = /^\s*(?:oxlint|eslint)-disable(?:-next-line|-line)?(?=\s|$)(.*)$/su;
12
+ /** Rule names are compared with `@typescript-eslint/` read as `typescript/`. */
13
+ function normalizeRuleName(rule) {
14
+ return rule.trim().replace(/^@?typescript-eslint\//u, "typescript/");
15
+ }
16
+ /** The rule names a disable directive lists, or null when the comment is not a disable directive. */
17
+ function directiveRules(value) {
18
+ const match = directivePattern.exec(value);
19
+ if (match === null)
20
+ return null;
21
+ // Oxlint ends the rule list at ` --`, with or without a space before the reason.
22
+ const list = (match[1] ?? "").split(/\s--/u)[0] ?? "";
23
+ // Commas, spaces and newlines all separate rule names.
24
+ return list
25
+ .split(/[\s,]+/u)
26
+ .map(normalizeRuleName)
27
+ .filter((rule) => rule.length > 0);
28
+ }
29
+ /**
30
+ * Oxlint applies a disable to a built-in rule by the name after the slash, whatever the prefix, and
31
+ * a disable with no prefix to that built-in rule too. A bare name doesn't reach a JS plugin rule, so
32
+ * reporting one only flags a disable that does nothing.
33
+ */
34
+ function isTypeAssertionRule(typeAssertionRules, rule) {
35
+ if (typeAssertionRules.has(rule))
36
+ return true;
37
+ const name = rule.slice(rule.lastIndexOf("/") + 1);
38
+ return [...typeAssertionRules].some((known) => known === `typescript/${name}` || (!rule.includes("/") && known.endsWith(`/${name}`)));
39
+ }
40
+ function configuredAdditionalRules(option) {
41
+ if (typeof option !== "object" || option === null || !("additionalRules" in option))
42
+ return [];
43
+ const { additionalRules } = option;
44
+ if (!Array.isArray(additionalRules))
45
+ return [];
46
+ return additionalRules.filter((rule) => typeof rule === "string").map(normalizeRuleName);
47
+ }
48
+ /** Disallow inline disables of the type-assertion rules, and disables that name no rule at all. */
49
+ export const noDisabledTypeAssertionRulesRule = defineRule({
50
+ meta: {
51
+ type: "problem",
52
+ docs: {
53
+ description: "Disallow inline disable comments for the type-assertion rules, and disable comments that name no rule.",
54
+ },
55
+ messages: {
56
+ disabledRule: "Don't disable `{{rule}}` inline. Remove the cast, or add a file override with its reason in the lint config.",
57
+ disabledEverything: "This disable comment names no rule, so it turns off the type-assertion rules too. Name the rules it disables.",
58
+ },
59
+ schema: [
60
+ {
61
+ type: "object",
62
+ properties: {
63
+ additionalRules: { type: "array", items: { type: "string", minLength: 1 }, uniqueItems: true },
64
+ },
65
+ additionalProperties: false,
66
+ },
67
+ ],
68
+ defaultOptions: [{ additionalRules: [] }],
69
+ },
70
+ createOnce(context) {
71
+ return {
72
+ Program() {
73
+ const typeAssertionRules = new Set([
74
+ ...defaultTypeAssertionRules,
75
+ ...configuredAdditionalRules(context.options?.[0]),
76
+ ]);
77
+ for (const comment of context.sourceCode.getAllComments()) {
78
+ const rules = directiveRules(comment.value);
79
+ if (rules === null)
80
+ continue;
81
+ if (rules.length === 0) {
82
+ context.report({ node: comment, messageId: "disabledEverything" });
83
+ continue;
84
+ }
85
+ for (const rule of rules) {
86
+ if (!isTypeAssertionRule(typeAssertionRules, rule))
87
+ continue;
88
+ context.report({ node: comment, messageId: "disabledRule", data: { rule } });
89
+ }
90
+ }
91
+ },
92
+ };
93
+ },
94
+ });
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Require every lint or type-checker suppression to say why: after ` -- ` (or after the
3
+ * `@ts-` directive), or in a comment on the line above. Adapted from T3 Code's
4
+ * `require-suppression-reason` (MIT, T3 Tools Inc.).
5
+ */
6
+ export declare const requireSuppressionReasonRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,61 @@
1
+ import { defineRule } from '@oxlint/plugins';
2
+ const DIRECTIVE = /^\s*\*?\s*(?:(?:oxlint|eslint)-(?:disable|enable)|@ts-(?:expect-error|ignore|nocheck|check)|@effect-diagnostics|(?:prettier|oxfmt)-ignore|biome-ignore|svelte-ignore|(?:c8|v8|istanbul)\s+ignore|@(?:vitest|jest)-environment|@vite-ignore|@jsx|nosemgrep\b)/u;
3
+ const TYPESCRIPT_DIRECTIVE = /^\s*\*?\s*@ts-(?:expect-error|ignore|nocheck)(?![\w-])(.*)$/su;
4
+ const EMPTY = /^[\s*]*$/u;
5
+ /**
6
+ * Require every lint or type-checker suppression to say why: after ` -- ` (or after the
7
+ * `@ts-` directive), or in a comment on the line above. Adapted from T3 Code's
8
+ * `require-suppression-reason` (MIT, T3 Tools Inc.).
9
+ */
10
+ export const requireSuppressionReasonRule = defineRule({
11
+ meta: {
12
+ type: 'suggestion',
13
+ docs: { description: 'Require every lint or type-checker suppression to say why.' },
14
+ messages: {
15
+ lintDirective: 'Say why: end the directive with `-- reason`, or put a comment on the line above.',
16
+ typescriptDirective: 'Say why: write the reason after the directive, or in a comment on the line above.',
17
+ },
18
+ },
19
+ createOnce(context) {
20
+ return {
21
+ Program() {
22
+ const { sourceCode } = context;
23
+ const comments = sourceCode.getAllComments();
24
+ const ownLineByEndLine = new Map();
25
+ for (const comment of comments) {
26
+ if (comment.type === 'Shebang')
27
+ continue;
28
+ const { line, column } = comment.loc.start;
29
+ if ((sourceCode.lines[line - 1] ?? '').slice(0, column).trim() === '') {
30
+ ownLineByEndLine.set(comment.loc.end.line, comment);
31
+ }
32
+ }
33
+ /** Whether a prose comment sits directly above, past other directives and empty comments. */
34
+ const explainedAbove = (directive) => {
35
+ let above = ownLineByEndLine.get(directive.loc.start.line - 1);
36
+ while (above !== undefined && (DIRECTIVE.test(above.value) || EMPTY.test(above.value))) {
37
+ above = ownLineByEndLine.get(above.loc.start.line - 1);
38
+ }
39
+ return above !== undefined;
40
+ };
41
+ for (const directive of sourceCode.getDisableDirectives().directives) {
42
+ if (directive.type === 'enable' || directive.justification?.trim())
43
+ continue;
44
+ if (explainedAbove(directive.node))
45
+ continue;
46
+ context.report({ loc: directive.node.loc, messageId: 'lintDirective' });
47
+ }
48
+ for (const comment of comments) {
49
+ if (comment.type === 'Shebang')
50
+ continue;
51
+ const after = TYPESCRIPT_DIRECTIVE.exec(comment.value)?.[1];
52
+ if (after === undefined || after.replace(/^[\s:-]+/u, '').trim() !== '')
53
+ continue;
54
+ if (explainedAbove(comment))
55
+ continue;
56
+ context.report({ loc: comment.loc, messageId: 'typescriptDirective' });
57
+ }
58
+ },
59
+ };
60
+ },
61
+ });
@@ -0,0 +1,5 @@
1
+ /**
2
+ * landmines' test-honesty rules, re-exported so the preset can load them by this package's name.
3
+ * The preset turns on four of them; `no-test-doubles` stays off.
4
+ */
5
+ export { default } from '@interfere/landmines/testing';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * landmines' test-honesty rules, re-exported so the preset can load them by this package's name.
3
+ * The preset turns on four of them; `no-test-doubles` stays off.
4
+ */
5
+ export { default } from '@interfere/landmines/testing';
package/dist/oxlint.d.ts CHANGED
@@ -15,8 +15,10 @@ declare const preset: {
15
15
  correctness: "error";
16
16
  };
17
17
  rules: {
18
+ 'anti-slop/comments': "error";
18
19
  'anti-slop/no-chained-type-assertions': "error";
19
20
  'anti-slop/no-conditional-empty-object-spread': "error";
21
+ 'anti-slop/no-disabled-type-assertion-rules': "error";
20
22
  'anti-slop/no-known-value-widening': "error";
21
23
  'anti-slop/no-module-mocking': "error";
22
24
  'anti-slop/no-object-parameters': "error";
@@ -32,13 +34,52 @@ declare const preset: {
32
34
  'anti-slop/require-pascal-case-namespace-imports': "error";
33
35
  'anti-slop/require-readable-spacing': "error";
34
36
  'anti-slop/require-safety-comment-for-type-assertion': "error";
37
+ 'anti-slop/require-suppression-reason': "error";
35
38
  'anti-slop-effect/no-manual-effect-error-tag': "error";
39
+ 'anti-slop-effect/no-ordie-in-service-construction': "error";
36
40
  'anti-slop-effect/no-service-constructor-imports': "error";
37
41
  'anti-slop-effect/no-service-parameters': "error";
42
+ 'anti-slop-effect/no-unbounded-retry': "error";
38
43
  'anti-slop-effect/prefer-effect-match': "error";
44
+ 'anti-slop-effect/require-cause-when-narrowing': "error";
45
+ 'anti-slop-effect/throw-in-effect-gen': "error";
46
+ 'ai-guard/no-assertionless-test': "error";
47
+ 'ai-guard/no-placeholder-implementation': "error";
48
+ 'ai-guard/no-silent-fallback': "error";
49
+ 'ai-guard/no-tautological-assertion': "error";
50
+ 'ai-guard/no-test-env-branch': "error";
51
+ 'ai-guard/no-undeclared-import': "error";
52
+ 'landmines/no-fixed-sleep': "error";
53
+ 'landmines/no-flake-masking': "error";
54
+ 'landmines/no-unsignaled-poll': "error";
55
+ 'landmines/strict-msw': "error";
39
56
  'oxc/no-accumulating-spread': "error";
57
+ eqeqeq: "error";
58
+ 'typescript/consistent-type-imports': "error";
59
+ 'typescript/no-explicit-any': "error";
60
+ 'typescript/no-non-null-assertion': "error";
40
61
  'typescript/no-floating-promises': "error";
41
62
  'typescript/no-misused-promises': "error";
63
+ 'typescript/no-unnecessary-type-assertion': "error";
64
+ 'typescript/no-unnecessary-type-conversion': "error";
65
+ 'typescript/no-unsafe-argument': "error";
66
+ 'typescript/no-unsafe-assignment': "error";
67
+ 'typescript/no-unsafe-call': "error";
68
+ 'typescript/no-unsafe-member-access': "error";
69
+ 'typescript/no-unsafe-return': "error";
70
+ 'typescript/no-unsafe-type-assertion': "error";
71
+ 'typescript/only-throw-error': "error";
72
+ 'typescript/switch-exhaustiveness-check': ["error", {
73
+ allowDefaultCaseForExhaustiveSwitch: true;
74
+ considerDefaultExhaustiveForUnions: true;
75
+ }];
76
+ 'typescript/use-unknown-in-catch-callback-variable': "error";
42
77
  };
78
+ overrides: {
79
+ files: string[];
80
+ rules: {
81
+ 'anti-slop-effect/throw-in-effect-gen': "off";
82
+ };
83
+ }[];
43
84
  };
44
85
  export default preset;