@zgeoff/oxlint-config 0.6.3 → 0.7.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 +41 -310
- package/build-lane-limits.js +31 -0
- package/build-module-order-fix.js +3 -22
- package/collect-module-entries.js +2 -15
- package/collect-refusing-edges.js +0 -2
- package/collect-type-kinds.js +0 -5
- package/collect-zone-names.js +0 -1
- package/find-function-name.js +0 -3
- package/function-verb.js +0 -4
- package/get-zone-options.js +0 -1
- package/import-zones-schema.js +0 -1
- package/import-zones.js +2 -10
- package/is-edge-refusing.js +0 -4
- package/is-entry-applying.js +0 -1
- package/is-static-value.js +0 -4
- package/is-verb-match.js +2 -2
- package/load-workspace-manifests.js +0 -4
- package/make-glob-matcher.js +0 -2
- package/max-consecutive-line-comments.js +0 -5
- package/max-test-timeout.js +191 -0
- package/module-order.js +2 -21
- package/no-abbreviated-names.js +1 -22
- package/no-class.js +1 -2
- package/no-comment-rule-override.js +4 -8
- package/no-file-snapshot.js +0 -2
- package/no-hidden-cast.js +0 -2
- package/no-restricted-words.js +0 -2
- package/no-test-sleep.js +138 -0
- package/oxlintrc.json +3 -0
- package/package.json +6 -1
- package/plugin.js +7 -4
- package/resolve-import-target.js +0 -5
- package/resolve-repo-root.js +1 -2
- package/resolve-suite-directory.js +31 -0
- package/setup-test-only.js +3 -17
- package/test-beside-module.js +15 -21
- package/test-timeout-exception-ticket.js +49 -0
- package/verb-contract.js +1 -22
package/import-zones.js
CHANGED
|
@@ -81,9 +81,6 @@ const importZones = {
|
|
|
81
81
|
|
|
82
82
|
export default importZones;
|
|
83
83
|
|
|
84
|
-
// Judges each import against named zones: path globs relative to the repo
|
|
85
|
-
// root, which may overlap. A file belongs to every zone its path matches.
|
|
86
|
-
|
|
87
84
|
function loadFileState(context) {
|
|
88
85
|
const options = getZoneOptions(context.options[0] ?? {});
|
|
89
86
|
const filename = context.physicalFilename;
|
|
@@ -108,8 +105,8 @@ function toRootPath(root, path) {
|
|
|
108
105
|
}
|
|
109
106
|
|
|
110
107
|
function checkUnzoned(file, program) {
|
|
111
|
-
// anchor on the first statement,
|
|
112
|
-
//
|
|
108
|
+
// anchor on the first statement, not offset 0, so a disable comment at the
|
|
109
|
+
// top of the file covers the report
|
|
113
110
|
const start = program.body[0]?.loc.start ?? { line: 1, column: 0 };
|
|
114
111
|
|
|
115
112
|
for (const entry of collectEntries(file, file.options.unzoned)) {
|
|
@@ -127,7 +124,6 @@ function collectEntries(file, entries) {
|
|
|
127
124
|
return entries.filter((entry) => isEntryApplying(entry, file.path, file.zones));
|
|
128
125
|
}
|
|
129
126
|
|
|
130
|
-
// `at` is `{ node }` or `{ loc }`
|
|
131
127
|
function emitReport(file, entry, report) {
|
|
132
128
|
const reason = entry.reason === undefined ? '' : ` — ${entry.reason}`;
|
|
133
129
|
|
|
@@ -142,7 +138,6 @@ function formatZones(names) {
|
|
|
142
138
|
return names.length === 0 ? 'no zone' : names.join(', ');
|
|
143
139
|
}
|
|
144
140
|
|
|
145
|
-
// `imported` is `{ node, source, typeOnly }`, one per import of any form
|
|
146
141
|
function checkImport(file, imported) {
|
|
147
142
|
const specifier = findStaticSpecifier(imported.source);
|
|
148
143
|
|
|
@@ -172,7 +167,6 @@ function checkImport(file, imported) {
|
|
|
172
167
|
}
|
|
173
168
|
}
|
|
174
169
|
|
|
175
|
-
// a string literal, or a template literal with nothing interpolated
|
|
176
170
|
function findStaticSpecifier(node) {
|
|
177
171
|
if (node?.type === 'Literal' && typeof node.value === 'string') {
|
|
178
172
|
return node.value;
|
|
@@ -239,7 +233,6 @@ function isPrefixMatch(prefix, specifier) {
|
|
|
239
233
|
return prefix === 'node:' && isBuiltin(specifier);
|
|
240
234
|
}
|
|
241
235
|
|
|
242
|
-
// collectRefusingEdges judges an edge the same way, through isEdgeRefusing
|
|
243
236
|
function checkEdge(file, imported, target) {
|
|
244
237
|
const edgeImport = {
|
|
245
238
|
from: file.path,
|
|
@@ -294,7 +287,6 @@ function checkGlobalCall(file, node) {
|
|
|
294
287
|
|
|
295
288
|
const globalObjects = new Set(['globalThis', 'self', 'window']);
|
|
296
289
|
|
|
297
|
-
// a call of the global itself, so a local binding of the same name passes
|
|
298
290
|
function findGlobalCallName(file, node, names) {
|
|
299
291
|
const callee = node.callee;
|
|
300
292
|
let name = null;
|
package/is-edge-refusing.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import isEntryApplying from './is-entry-applying.js';
|
|
2
2
|
import isInAnyZone from './is-in-any-zone.js';
|
|
3
3
|
|
|
4
|
-
// `entry` is a compiled edge; `edgeImport` is `{ from, to, fromZones,
|
|
5
|
-
// toZones, typeOnly }`, both paths relative to the repo root
|
|
6
4
|
export default function isEdgeRefusing(entry, edgeImport) {
|
|
7
|
-
// `to` picks the targets judged, every target when absent; `allow` exempts
|
|
8
|
-
// some of them. The schema needs one of the two.
|
|
9
5
|
const isForbidden =
|
|
10
6
|
(entry.to === undefined || isInAnyZone(edgeImport.toZones, entry.to)) &&
|
|
11
7
|
(entry.allow === undefined || !isInAnyZone(edgeImport.toZones, entry.allow));
|
package/is-entry-applying.js
CHANGED
package/is-static-value.js
CHANGED
|
@@ -34,9 +34,6 @@ const checks = {
|
|
|
34
34
|
value.arguments.every((argument) => isStaticArgument(argument, names)),
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
// a value that runs no code and reads nothing that load-time code can change,
|
|
38
|
-
// so it is the same wherever it sits; an import stands only where its value
|
|
39
|
-
// is copied, such as an array element, and never where it is read through
|
|
40
37
|
export default function isStaticValue(node, names, canCopyImport = true) {
|
|
41
38
|
const value = unwrapExpression(node);
|
|
42
39
|
const check = checks[value.type];
|
|
@@ -52,7 +49,6 @@ const wrapperTypes = new Set([
|
|
|
52
49
|
'ParenthesizedExpression',
|
|
53
50
|
]);
|
|
54
51
|
|
|
55
|
-
// a type assertion or parentheses leave the value as it is
|
|
56
52
|
function unwrapExpression(node) {
|
|
57
53
|
let current = node;
|
|
58
54
|
|
package/is-verb-match.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// a
|
|
2
|
-
//
|
|
1
|
+
// a digit ends a verb too, since an acronym such as 2FA starts a camelCase
|
|
2
|
+
// segment
|
|
3
3
|
export default function isVerbMatch(name, verb) {
|
|
4
4
|
return name === verb || (name.startsWith(verb) && /[A-Z0-9]/u.test(name.charAt(verb.length)));
|
|
5
5
|
}
|
|
@@ -2,9 +2,6 @@ import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import makeGlobMatcher from './make-glob-matcher.js';
|
|
4
4
|
|
|
5
|
-
// The manifest of every package directory the globs match, relative to the
|
|
6
|
-
// root. Each glob segment matches one directory level, as a workspaces
|
|
7
|
-
// field's globs do.
|
|
8
5
|
export default function loadWorkspaceManifests(root, globs) {
|
|
9
6
|
return withManifestCache(JSON.stringify([root, globs]), () =>
|
|
10
7
|
globs
|
|
@@ -48,7 +45,6 @@ function splitGlob(glob) {
|
|
|
48
45
|
return glob.split('/').filter((segment) => segment !== '' && segment !== '.');
|
|
49
46
|
}
|
|
50
47
|
|
|
51
|
-
// `directory` is the field the resolver reads from every manifest it loads
|
|
52
48
|
function loadManifest(directory) {
|
|
53
49
|
const path = join(directory, 'package.json');
|
|
54
50
|
|
package/make-glob-matcher.js
CHANGED
|
@@ -39,9 +39,6 @@ const maxConsecutiveLineComments = {
|
|
|
39
39
|
|
|
40
40
|
export default maxConsecutiveLineComments;
|
|
41
41
|
|
|
42
|
-
// a run is prose line comments on consecutive lines; whatever else occupies
|
|
43
|
-
// a line between two of them (code, a blank, a directive, a block comment)
|
|
44
|
-
// breaks adjacency and so ends the run
|
|
45
42
|
function collectRuns(text, comments) {
|
|
46
43
|
const runs = [];
|
|
47
44
|
|
|
@@ -58,8 +55,6 @@ function collectRuns(text, comments) {
|
|
|
58
55
|
return runs;
|
|
59
56
|
}
|
|
60
57
|
|
|
61
|
-
// tool directives are not prose: they neither count toward a run nor join
|
|
62
|
-
// the prose on either side of them into one
|
|
63
58
|
const directivePattern =
|
|
64
59
|
/^\s*(?:oxlint-|eslint-|@ts-|prettier-|oxfmt-|biome-ignore|#region|#endregion|\/\s*<)/u;
|
|
65
60
|
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { basename } from 'node:path';
|
|
2
|
+
import buildLaneLimits from './build-lane-limits.js';
|
|
3
|
+
import resolveSuiteDirectory from './resolve-suite-directory.js';
|
|
4
|
+
|
|
5
|
+
const runnerNames = new Set(['test', 'it', 'describe']);
|
|
6
|
+
|
|
7
|
+
const unitLimitMs = 5000;
|
|
8
|
+
|
|
9
|
+
export default function buildMaxTestTimeout(resolveRoot) {
|
|
10
|
+
return {
|
|
11
|
+
meta: {
|
|
12
|
+
type: 'problem',
|
|
13
|
+
messages: {
|
|
14
|
+
timeout:
|
|
15
|
+
'This timeout of {{timeoutMs}} ms is above the {{limitMs}} ms limit of the {{lane}} lane. Find its cause in the "Slow tests" section of the testing skill and fix it; a raised timeout only hides the cost.',
|
|
16
|
+
},
|
|
17
|
+
schema: [
|
|
18
|
+
{
|
|
19
|
+
type: 'object',
|
|
20
|
+
properties: {
|
|
21
|
+
lanes: {
|
|
22
|
+
anyOf: [
|
|
23
|
+
{ type: 'array', items: { type: 'string' } },
|
|
24
|
+
{ type: 'object', additionalProperties: { type: 'integer', minimum: 0 } },
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
additionalProperties: false,
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
create(context) {
|
|
33
|
+
const limits = buildLaneLimits(context.options[0]?.lanes);
|
|
34
|
+
|
|
35
|
+
const filename = context.physicalFilename;
|
|
36
|
+
const lane = resolveLane(resolveRoot(filename) ?? context.cwd, filename, limits);
|
|
37
|
+
const limit = {
|
|
38
|
+
lane: lane ?? 'unit',
|
|
39
|
+
limitMs: lane === null ? unitLimitMs : limits.get(lane),
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
CallExpression(node) {
|
|
44
|
+
// the inner call of `test.each(rows)(…)` takes the rows, not a timeout
|
|
45
|
+
if (node.parent.type === 'CallExpression' && node.parent.callee === node) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const name = findRunnerName(context, node.callee);
|
|
50
|
+
|
|
51
|
+
if (name === 'setDefaultTimeout') {
|
|
52
|
+
emitTimeouts(context, node.arguments.slice(0, 1), limit);
|
|
53
|
+
} else if (name !== null && runnerNames.has(name)) {
|
|
54
|
+
emitTimeouts(context, node.arguments.slice(1), limit);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const laneTestPattern = /\.(?<lane>[^.]+)\.test\.tsx?$/u;
|
|
63
|
+
|
|
64
|
+
// a lane suffix wins over the directory, because the default run leaves a suffixed file out and its
|
|
65
|
+
// lane's script runs it; the directory is relative to the repo root, not oxlint's working
|
|
66
|
+
// directory, so a per-package lint script reads the same root `e2e/` as a run from the root
|
|
67
|
+
function resolveLane(root, filename, limits) {
|
|
68
|
+
const lane = laneTestPattern.exec(basename(filename))?.groups?.lane;
|
|
69
|
+
|
|
70
|
+
if (lane !== undefined && limits.has(lane)) {
|
|
71
|
+
return lane;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return resolveSuiteDirectory(root, filename) === 'e2e' ? 'e2e' : null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function findRunnerName(context, callee) {
|
|
78
|
+
let current = callee;
|
|
79
|
+
let member = null;
|
|
80
|
+
|
|
81
|
+
while (current.type !== 'Identifier') {
|
|
82
|
+
if (current.type === 'CallExpression') {
|
|
83
|
+
current = current.callee;
|
|
84
|
+
} else if (current.type === 'MemberExpression' && !current.computed) {
|
|
85
|
+
member = current;
|
|
86
|
+
current = current.object;
|
|
87
|
+
} else {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const variable = findVariable(context, current);
|
|
93
|
+
|
|
94
|
+
if (variable === null) {
|
|
95
|
+
return current.name;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const [definition] = variable.defs;
|
|
99
|
+
|
|
100
|
+
if (
|
|
101
|
+
variable.defs.length !== 1 ||
|
|
102
|
+
definition.type !== 'ImportBinding' ||
|
|
103
|
+
definition.parent.source.value !== 'bun:test'
|
|
104
|
+
) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (definition.node.type === 'ImportNamespaceSpecifier') {
|
|
109
|
+
return member?.property.name ?? null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return definition.node.type === 'ImportSpecifier' ? getImportedName(definition.node) : null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// a name with no declaration reads the global that `bun test` defines
|
|
116
|
+
function findVariable(context, identifier) {
|
|
117
|
+
for (let scope = context.sourceCode.getScope(identifier); scope !== null; scope = scope.upper) {
|
|
118
|
+
const variable = scope.set.get(identifier.name);
|
|
119
|
+
|
|
120
|
+
if (variable !== undefined && variable.defs.length > 0) {
|
|
121
|
+
return variable;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function getImportedName(specifier) {
|
|
129
|
+
return specifier.imported.type === 'Identifier'
|
|
130
|
+
? specifier.imported.name
|
|
131
|
+
: specifier.imported.value;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function emitTimeouts(context, args, limit) {
|
|
135
|
+
for (const argument of args) {
|
|
136
|
+
const value = argument.type === 'ObjectExpression' ? findTimeoutValue(argument) : argument;
|
|
137
|
+
const timeoutMs = value === undefined ? null : findNumber(context, value, new Set());
|
|
138
|
+
|
|
139
|
+
if (timeoutMs !== null && timeoutMs > limit.limitMs) {
|
|
140
|
+
context.report({ node: value, messageId: 'timeout', data: { timeoutMs, ...limit } });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function findTimeoutValue(options) {
|
|
146
|
+
const property = options.properties.find(
|
|
147
|
+
(candidate) =>
|
|
148
|
+
candidate.type === 'Property' &&
|
|
149
|
+
!candidate.computed &&
|
|
150
|
+
(candidate.key.name ?? candidate.key.value) === 'timeout',
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
return property?.value;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const arithmetic = {
|
|
157
|
+
'+': (left, right) => left + right,
|
|
158
|
+
'-': (left, right) => left - right,
|
|
159
|
+
'*': (left, right) => left * right,
|
|
160
|
+
'/': (left, right) => left / right,
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
function findNumber(context, node, seen) {
|
|
164
|
+
if (node.type === 'Literal') {
|
|
165
|
+
return typeof node.value === 'number' ? node.value : null;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (node.type === 'BinaryExpression' && Object.hasOwn(arithmetic, node.operator)) {
|
|
169
|
+
const left = findNumber(context, node.left, seen);
|
|
170
|
+
const right = findNumber(context, node.right, seen);
|
|
171
|
+
|
|
172
|
+
return left === null || right === null ? null : arithmetic[node.operator](left, right);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (node.type !== 'Identifier' || seen.has(node.name)) {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const definition = findVariable(context, node)?.defs[0];
|
|
180
|
+
|
|
181
|
+
if (
|
|
182
|
+
definition?.type !== 'Variable' ||
|
|
183
|
+
definition.parent.kind !== 'const' ||
|
|
184
|
+
definition.node.id.type !== 'Identifier' ||
|
|
185
|
+
definition.node.init === null
|
|
186
|
+
) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return findNumber(context, definition.node.init, new Set([...seen, node.name]));
|
|
191
|
+
}
|
package/module-order.js
CHANGED
|
@@ -2,8 +2,6 @@ import { basename } from 'node:path';
|
|
|
2
2
|
import buildModuleOrderFix from './build-module-order-fix.js';
|
|
3
3
|
import collectModuleEntries from './collect-module-entries.js';
|
|
4
4
|
|
|
5
|
-
// the code-style module order: the primary export, then its private helpers
|
|
6
|
-
// depth-first, with each const, type or enum directly above its first use
|
|
7
5
|
const moduleOrder = {
|
|
8
6
|
meta: {
|
|
9
7
|
type: 'suggestion',
|
|
@@ -73,9 +71,6 @@ function checkModule(context, program) {
|
|
|
73
71
|
}
|
|
74
72
|
}
|
|
75
73
|
|
|
76
|
-
// the default export, else the export the file is named for, else the only
|
|
77
|
-
// value the file exports; `export default name` names the declaration of
|
|
78
|
-
// `name`, and a default export of any other expression is the statement
|
|
79
74
|
function findPrimaryExport(entries, filename) {
|
|
80
75
|
const defaultEntry = entries.find((entry) => entry.exportKind === 'default') ?? null;
|
|
81
76
|
const defaultName =
|
|
@@ -98,7 +93,6 @@ function findPrimaryExport(entries, filename) {
|
|
|
98
93
|
return named ?? only;
|
|
99
94
|
}
|
|
100
95
|
|
|
101
|
-
// `parseCLIArgs` becomes `parse-cli-args`, as the code-style file names read
|
|
102
96
|
function toKebabCase(name) {
|
|
103
97
|
return name
|
|
104
98
|
.replaceAll(/(?<before>[a-z\d])(?<after>[A-Z])/gu, '$<before>-$<after>')
|
|
@@ -106,9 +100,6 @@ function toKebabCase(name) {
|
|
|
106
100
|
.toLowerCase();
|
|
107
101
|
}
|
|
108
102
|
|
|
109
|
-
// the primary export, then each private helper it reaches, depth-first in the
|
|
110
|
-
// order each one is first referenced; a const or type passes its references
|
|
111
|
-
// through, so a helper that only a const names still has a place
|
|
112
103
|
function collectMainOrder(primary) {
|
|
113
104
|
const order = [primary];
|
|
114
105
|
const seen = new Set([primary]);
|
|
@@ -139,8 +130,6 @@ function isHelper(entry) {
|
|
|
139
130
|
return entry.kind === 'function' && entry.exportKind === null;
|
|
140
131
|
}
|
|
141
132
|
|
|
142
|
-
// the main-order entry each const or type belongs above: the earliest one
|
|
143
|
-
// that uses it, directly or through another const or type
|
|
144
133
|
function buildHomes(entries, ranks) {
|
|
145
134
|
const homes = new Map();
|
|
146
135
|
const visiting = new Set();
|
|
@@ -179,17 +168,12 @@ function buildHomes(entries, ranks) {
|
|
|
179
168
|
return homes;
|
|
180
169
|
}
|
|
181
170
|
|
|
182
|
-
// the users of `entry` in its home's block: the home itself and each const
|
|
183
|
-
// or type with the same home
|
|
184
171
|
function collectBlockUsers(entry, homes) {
|
|
185
172
|
const home = homes.get(entry);
|
|
186
173
|
|
|
187
174
|
return [...entry.users].filter((user) => user === home || homes.get(user) === home);
|
|
188
175
|
}
|
|
189
176
|
|
|
190
|
-
// a helper above the primary export, and a helper below it that breaks the
|
|
191
|
-
// depth-first order; the longest run already in order stays, so each report
|
|
192
|
-
// names one helper to move
|
|
193
177
|
function collectHelperReports(layout) {
|
|
194
178
|
const primary = layout.primary;
|
|
195
179
|
const reports = [];
|
|
@@ -218,7 +202,6 @@ function collectHelperReports(layout) {
|
|
|
218
202
|
return reports;
|
|
219
203
|
}
|
|
220
204
|
|
|
221
|
-
// the positions of one longest increasing run in `values`
|
|
222
205
|
function collectLongestRun(values) {
|
|
223
206
|
const lengths = values.map(() => 1);
|
|
224
207
|
const previous = values.map(() => -1);
|
|
@@ -243,9 +226,6 @@ function collectLongestRun(values) {
|
|
|
243
226
|
return kept;
|
|
244
227
|
}
|
|
245
228
|
|
|
246
|
-
// a const or type sits above every use in its home's block, with no helper
|
|
247
|
-
// that stays between it and its home; a const that a live function reads
|
|
248
|
-
// stays unchecked, since below the primary export it could be read unset
|
|
249
229
|
function collectDeclarationReports(layout, helperReports) {
|
|
250
230
|
const homes = layout.homes;
|
|
251
231
|
const moving = new Set(helperReports.map((report) => report.entry));
|
|
@@ -255,6 +235,8 @@ function collectDeclarationReports(layout, helperReports) {
|
|
|
255
235
|
for (const entry of layout.entries) {
|
|
256
236
|
const home = homes.get(entry) ?? null;
|
|
257
237
|
|
|
238
|
+
// load-time code can call a live function before a const below the primary
|
|
239
|
+
// export is set, so a const that a live function reads stays unchecked
|
|
258
240
|
if (home === null || (hasValue(entry) && isReadByLiveFunction(entry))) {
|
|
259
241
|
continue;
|
|
260
242
|
}
|
|
@@ -278,7 +260,6 @@ function collectDeclarationReports(layout, helperReports) {
|
|
|
278
260
|
return reports;
|
|
279
261
|
}
|
|
280
262
|
|
|
281
|
-
// a type has no value to read unset, so it is always checked
|
|
282
263
|
function hasValue(entry) {
|
|
283
264
|
const type = entry.declaration.type;
|
|
284
265
|
|
package/no-abbreviated-names.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// each `names` key is a short name and its value the text that replaces it;
|
|
2
|
-
// the rule matches a whole name, so `timeoutMs` passes when `ms` is listed
|
|
3
1
|
const noAbbreviatedNames = {
|
|
4
2
|
meta: {
|
|
5
3
|
type: 'suggestion',
|
|
@@ -46,9 +44,6 @@ const noAbbreviatedNames = {
|
|
|
46
44
|
}
|
|
47
45
|
};
|
|
48
46
|
|
|
49
|
-
// a computed key names its property as a plain key does when it is a
|
|
50
|
-
// string written in place, as in `{ ['src']: 1 }`; a computed identifier
|
|
51
|
-
// reads a variable, whose declaration is checked where it is made
|
|
52
47
|
const checkMemberName = (node, name) => {
|
|
53
48
|
if (!node.computed || name.type !== 'Identifier') {
|
|
54
49
|
checkName(name);
|
|
@@ -65,8 +60,6 @@ const noAbbreviatedNames = {
|
|
|
65
60
|
}
|
|
66
61
|
};
|
|
67
62
|
|
|
68
|
-
// a write to a member names that property, whether the member stands
|
|
69
|
-
// alone or sits inside a destructuring target
|
|
70
63
|
const checkAssignmentTarget = (node) => {
|
|
71
64
|
for (const member of collectTargetMembers(node)) {
|
|
72
65
|
checkMemberName(member, member.property);
|
|
@@ -79,8 +72,6 @@ const noAbbreviatedNames = {
|
|
|
79
72
|
}
|
|
80
73
|
};
|
|
81
74
|
|
|
82
|
-
// function-verb checks only a plain function or method name, so a quoted
|
|
83
|
-
// method, a signature or a declared function would pass both rules
|
|
84
75
|
const checkFunction = (node) => {
|
|
85
76
|
checkName(node.id);
|
|
86
77
|
checkParams(node);
|
|
@@ -94,7 +85,6 @@ const noAbbreviatedNames = {
|
|
|
94
85
|
FunctionExpression: checkFunction,
|
|
95
86
|
ArrowFunctionExpression: checkParams,
|
|
96
87
|
|
|
97
|
-
// a signature without a body names its parameters as an implementation does
|
|
98
88
|
TSDeclareFunction: checkFunction,
|
|
99
89
|
TSEmptyBodyFunctionExpression: checkParams,
|
|
100
90
|
TSFunctionType: checkParams,
|
|
@@ -117,19 +107,16 @@ const noAbbreviatedNames = {
|
|
|
117
107
|
MethodDefinition: checkKey,
|
|
118
108
|
TSAbstractMethodDefinition: checkKey,
|
|
119
109
|
|
|
120
|
-
// a class, an enum and a namespace are values at run time; a quoted
|
|
121
|
-
// module name is a path, not a value name
|
|
122
110
|
'ClassDeclaration, ClassExpression, TSEnumDeclaration'(node) {
|
|
123
111
|
checkName(node.id);
|
|
124
112
|
},
|
|
125
113
|
TSModuleDeclaration(node) {
|
|
114
|
+
// `declare module 'name'` quotes a module path, not a value name
|
|
126
115
|
if (node.id.type === 'Identifier') {
|
|
127
116
|
checkName(node.id);
|
|
128
117
|
}
|
|
129
118
|
},
|
|
130
119
|
|
|
131
|
-
// an import's local binding is a value name in this module, whatever the
|
|
132
|
-
// exporting module calls it; a type-only import names a type, not a value
|
|
133
120
|
'ImportSpecifier, ImportDefaultSpecifier, ImportNamespaceSpecifier'(node) {
|
|
134
121
|
if (!isTypeOnlyImport(node)) {
|
|
135
122
|
checkName(node.local);
|
|
@@ -149,7 +136,6 @@ const noAbbreviatedNames = {
|
|
|
149
136
|
checkName(node.id);
|
|
150
137
|
},
|
|
151
138
|
|
|
152
|
-
// an export alias is the name every importing module reads the value by
|
|
153
139
|
ExportSpecifier(node) {
|
|
154
140
|
if (!isTypeOnlyExport(node)) {
|
|
155
141
|
checkName(node.exported);
|
|
@@ -169,9 +155,6 @@ const noAbbreviatedNames = {
|
|
|
169
155
|
},
|
|
170
156
|
};
|
|
171
157
|
|
|
172
|
-
// the name a key or binding spells out in the source: an identifier, a
|
|
173
|
-
// string, or a template with no substitutions; a key built at run time has
|
|
174
|
-
// no static name, so the result is null
|
|
175
158
|
function findStaticName(node) {
|
|
176
159
|
if (node?.type === 'Identifier' || node?.type === 'PrivateIdentifier') {
|
|
177
160
|
return node.name;
|
|
@@ -188,8 +171,6 @@ function findStaticName(node) {
|
|
|
188
171
|
return null;
|
|
189
172
|
}
|
|
190
173
|
|
|
191
|
-
// the names a binding pattern declares: a destructured key's alias, not the
|
|
192
|
-
// key, since the key belongs to the object being read
|
|
193
174
|
function collectPatternIdentifiers(node) {
|
|
194
175
|
if (node === null || node === undefined) {
|
|
195
176
|
return [];
|
|
@@ -226,8 +207,6 @@ function collectPatternIdentifiers(node) {
|
|
|
226
207
|
return [];
|
|
227
208
|
}
|
|
228
209
|
|
|
229
|
-
// the members an assignment target writes; a bare identifier in the target
|
|
230
|
-
// writes a variable declared elsewhere, and its declaration is checked there
|
|
231
210
|
function collectTargetMembers(node) {
|
|
232
211
|
if (node === null || node === undefined) {
|
|
233
212
|
return [];
|
package/no-class.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// a custom error stays a class, since `instanceof` checks and stack traces
|
|
2
|
-
// need one
|
|
3
|
-
// bare or as a member such as `errors.BrewError`
|
|
2
|
+
// need one
|
|
4
3
|
const noClass = {
|
|
5
4
|
meta: {
|
|
6
5
|
type: 'problem',
|
|
@@ -2,9 +2,8 @@ import { readFileSync, readdirSync } from 'node:fs';
|
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import resolveRepoRoot from './resolve-repo-root.js';
|
|
4
4
|
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// server keeps it on that file across edits
|
|
5
|
+
// a report on one file per repo shows once per run, and an editor's
|
|
6
|
+
// language server keeps it on that file across edits
|
|
8
7
|
const anchorFiles = new Map();
|
|
9
8
|
|
|
10
9
|
const noCommentRuleOverride = {
|
|
@@ -45,8 +44,6 @@ export default noCommentRuleOverride;
|
|
|
45
44
|
|
|
46
45
|
const configPattern = /^\.oxlintrc(?:\.[\w-]+)?\.jsonc?$/u;
|
|
47
46
|
|
|
48
|
-
// every repo runs the comment rules and the type-assertion rules exactly as
|
|
49
|
-
// this config ships them, each named here without its plugin prefix
|
|
50
47
|
const lockedRules = [
|
|
51
48
|
'no-jsdoc',
|
|
52
49
|
'max-consecutive-line-comments',
|
|
@@ -54,9 +51,8 @@ const lockedRules = [
|
|
|
54
51
|
'no-hidden-cast',
|
|
55
52
|
];
|
|
56
53
|
|
|
57
|
-
// a rule
|
|
58
|
-
// `@typescript-eslint/consistent-type-assertions
|
|
59
|
-
// opposed to the same text inside a comment or a string value
|
|
54
|
+
// oxlint reads a rule under any plugin prefix, such as
|
|
55
|
+
// `@typescript-eslint/consistent-type-assertions`, or under its bare name
|
|
60
56
|
const keyPatterns = lockedRules.map(
|
|
61
57
|
(rule) => new RegExp(`"(?<key>(?:[^"/\\s]+/)?${rule})"\\s*:`, 'gu'),
|
|
62
58
|
);
|
package/no-file-snapshot.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { statSync } from 'node:fs';
|
|
2
2
|
import { basename, dirname, join } from 'node:path';
|
|
3
3
|
|
|
4
|
-
// the matchers that write `__snapshots__/<test file>.snap`; their inline
|
|
5
|
-
// counterparts keep the golden value in the test itself
|
|
6
4
|
const fileMatchers = ['toMatchSnapshot', 'toThrowErrorMatchingSnapshot'];
|
|
7
5
|
|
|
8
6
|
const noFileSnapshot = {
|
package/no-hidden-cast.js
CHANGED
|
@@ -50,8 +50,6 @@ const noHiddenCast = {
|
|
|
50
50
|
},
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
// the name an identifier or a member access ends in, `sql` for both `sql` and
|
|
54
|
-
// `db.sql`, or null for a computed member that is not a string literal
|
|
55
53
|
function findName(node) {
|
|
56
54
|
if (node.type === 'Identifier') {
|
|
57
55
|
return node.name;
|
package/no-restricted-words.js
CHANGED
|
@@ -48,8 +48,6 @@ const noRestrictedWords = {
|
|
|
48
48
|
},
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
// a letter, digit or underscore on either side makes the match part of a
|
|
52
|
-
// longer word (`impl`, `simple`), so only those characters bound it
|
|
53
51
|
function buildWordPattern(words) {
|
|
54
52
|
const alternatives = words.map((word) =>
|
|
55
53
|
word.replaceAll(/[$()*+.?[\\\]^{|}]/gu, String.raw`\$&`),
|