@zgeoff/oxlint-config 0.5.1 → 0.6.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 +42 -2
- package/collect-refusing-edges.js +19 -0
- package/collect-zone-names.js +4 -0
- package/function-verb.js +56 -56
- package/{load-zone-options.js → get-zone-options.js} +3 -3
- package/import-zones-entry.d.ts +59 -0
- package/import-zones-entry.js +2 -0
- package/import-zones-schema.js +19 -19
- package/import-zones.js +121 -131
- package/is-edge-refusing.js +22 -0
- package/is-entry-applying.js +6 -0
- package/is-in-any-zone.js +3 -0
- package/load-workspace-manifests.js +6 -6
- package/max-consecutive-line-comments.js +36 -36
- package/no-abbreviated-names.js +30 -30
- package/no-comment-rule-override.js +40 -31
- package/no-hidden-cast.js +71 -0
- package/no-jsdoc.js +15 -15
- package/oxlintrc.json +8 -2
- package/package.json +15 -3
- package/plugin.js +20 -18
- package/resolve-import-target.js +131 -131
- package/resolve-repo-root.js +6 -6
- package/setup-test-only.js +10 -10
- package/test-beside-module.js +32 -32
- package/verb-contract.js +93 -93
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import isEntryApplying from './is-entry-applying.js';
|
|
2
|
+
import isInAnyZone from './is-in-any-zone.js';
|
|
3
|
+
|
|
4
|
+
// `entry` is a compiled edge; `edgeImport` is `{ from, to, fromZones,
|
|
5
|
+
// toZones, typeOnly }`, both paths relative to the repo root
|
|
6
|
+
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
|
+
const isForbidden =
|
|
10
|
+
(entry.to === undefined || isInAnyZone(edgeImport.toZones, entry.to)) &&
|
|
11
|
+
(entry.allow === undefined || !isInAnyZone(edgeImport.toZones, entry.allow));
|
|
12
|
+
const isTypeExempt =
|
|
13
|
+
edgeImport.typeOnly &&
|
|
14
|
+
(entry.allowTypeOnly === true || entry.typeOnlyTargets?.(edgeImport.to) === true);
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
isEntryApplying(entry, edgeImport.from, edgeImport.fromZones) &&
|
|
18
|
+
isForbidden &&
|
|
19
|
+
!isTypeExempt &&
|
|
20
|
+
entry.within?.(edgeImport.from, edgeImport.to) !== true
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -25,10 +25,6 @@ function withManifestCache(key, load) {
|
|
|
25
25
|
return loadedManifests.get(key);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
function splitGlob(glob) {
|
|
29
|
-
return glob.split('/').filter((segment) => segment !== '' && segment !== '.');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
28
|
function readGlobDirectories(root, segments, prefix) {
|
|
33
29
|
const [segment, ...rest] = segments;
|
|
34
30
|
|
|
@@ -48,7 +44,11 @@ function readGlobDirectories(root, segments, prefix) {
|
|
|
48
44
|
return names.flatMap((name) => readGlobDirectories(root, rest, join(prefix, name)));
|
|
49
45
|
}
|
|
50
46
|
|
|
51
|
-
|
|
47
|
+
function splitGlob(glob) {
|
|
48
|
+
return glob.split('/').filter((segment) => segment !== '' && segment !== '.');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// `directory` is the field the resolver reads from every manifest it loads
|
|
52
52
|
function loadManifest(directory) {
|
|
53
53
|
const path = join(directory, 'package.json');
|
|
54
54
|
|
|
@@ -58,7 +58,7 @@ function loadManifest(directory) {
|
|
|
58
58
|
|
|
59
59
|
const manifest = JSON.parse(readFileSync(path, 'utf8'));
|
|
60
60
|
|
|
61
|
-
manifest.
|
|
61
|
+
manifest.directory = directory;
|
|
62
62
|
|
|
63
63
|
return manifest;
|
|
64
64
|
}
|
|
@@ -1,39 +1,3 @@
|
|
|
1
|
-
// tool directives are not prose: they neither count toward a run nor join
|
|
2
|
-
// the prose on either side of them into one
|
|
3
|
-
const directivePattern =
|
|
4
|
-
/^\s*(?:oxlint-|eslint-|@ts-|prettier-|oxfmt-|biome-ignore|#region|#endregion|\/\s*<)/u;
|
|
5
|
-
|
|
6
|
-
function isOwnLine(text, comment) {
|
|
7
|
-
const lineStart = text.lastIndexOf('\n', comment.range[0] - 1) + 1;
|
|
8
|
-
|
|
9
|
-
return /^[ \t]*$/u.test(text.slice(lineStart, comment.range[0]));
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function isProseLine(text, comment) {
|
|
13
|
-
return (
|
|
14
|
-
comment.type === 'Line' && !directivePattern.test(comment.value) && isOwnLine(text, comment)
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// a run is prose line comments on consecutive lines; whatever else occupies
|
|
19
|
-
// a line between two of them (code, a blank, a directive, a block comment)
|
|
20
|
-
// breaks adjacency and so ends the run
|
|
21
|
-
function collectRuns(text, comments) {
|
|
22
|
-
const runs = [];
|
|
23
|
-
|
|
24
|
-
for (const comment of comments.filter((candidate) => isProseLine(text, candidate))) {
|
|
25
|
-
const run = runs.at(-1);
|
|
26
|
-
|
|
27
|
-
if (run !== undefined && comment.loc.start.line === run.at(-1).loc.end.line + 1) {
|
|
28
|
-
run.push(comment);
|
|
29
|
-
} else {
|
|
30
|
-
runs.push([comment]);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return runs;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
1
|
const maxConsecutiveLineComments = {
|
|
38
2
|
meta: {
|
|
39
3
|
type: 'suggestion',
|
|
@@ -74,3 +38,39 @@ const maxConsecutiveLineComments = {
|
|
|
74
38
|
};
|
|
75
39
|
|
|
76
40
|
export default maxConsecutiveLineComments;
|
|
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
|
+
function collectRuns(text, comments) {
|
|
46
|
+
const runs = [];
|
|
47
|
+
|
|
48
|
+
for (const comment of comments.filter((candidate) => isProseLine(text, candidate))) {
|
|
49
|
+
const run = runs.at(-1);
|
|
50
|
+
|
|
51
|
+
if (run !== undefined && comment.loc.start.line === run.at(-1).loc.end.line + 1) {
|
|
52
|
+
run.push(comment);
|
|
53
|
+
} else {
|
|
54
|
+
runs.push([comment]);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return runs;
|
|
59
|
+
}
|
|
60
|
+
|
|
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
|
+
const directivePattern =
|
|
64
|
+
/^\s*(?:oxlint-|eslint-|@ts-|prettier-|oxfmt-|biome-ignore|#region|#endregion|\/\s*<)/u;
|
|
65
|
+
|
|
66
|
+
function isProseLine(text, comment) {
|
|
67
|
+
return (
|
|
68
|
+
comment.type === 'Line' && !directivePattern.test(comment.value) && isOwnLine(text, comment)
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function isOwnLine(text, comment) {
|
|
73
|
+
const lineStart = text.lastIndexOf('\n', comment.range[0] - 1) + 1;
|
|
74
|
+
|
|
75
|
+
return /^[ \t]*$/u.test(text.slice(lineStart, comment.range[0]));
|
|
76
|
+
}
|
package/no-abbreviated-names.js
CHANGED
|
@@ -188,84 +188,84 @@ function findStaticName(node) {
|
|
|
188
188
|
return null;
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
function isTypeOnlyExport(specifier) {
|
|
196
|
-
return specifier.exportKind === 'type' || specifier.parent.exportKind === 'type';
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// the members an assignment target writes; a bare identifier in the target
|
|
200
|
-
// writes a variable declared elsewhere, and its declaration is checked there
|
|
201
|
-
function collectTargetMembers(node) {
|
|
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
|
+
function collectPatternIdentifiers(node) {
|
|
202
194
|
if (node === null || node === undefined) {
|
|
203
195
|
return [];
|
|
204
196
|
}
|
|
205
197
|
|
|
206
|
-
if (node.type === '
|
|
198
|
+
if (node.type === 'Identifier') {
|
|
207
199
|
return [node];
|
|
208
200
|
}
|
|
209
201
|
|
|
210
202
|
if (node.type === 'ObjectPattern') {
|
|
211
203
|
return node.properties.flatMap((property) => {
|
|
212
|
-
const
|
|
204
|
+
const binding = property.type === 'RestElement' ? property : property.value;
|
|
213
205
|
|
|
214
|
-
return
|
|
206
|
+
return collectPatternIdentifiers(binding);
|
|
215
207
|
});
|
|
216
208
|
}
|
|
217
209
|
|
|
218
210
|
if (node.type === 'ArrayPattern') {
|
|
219
|
-
return node.elements.flatMap((element) =>
|
|
211
|
+
return node.elements.flatMap((element) => collectPatternIdentifiers(element));
|
|
220
212
|
}
|
|
221
213
|
|
|
222
214
|
if (node.type === 'AssignmentPattern') {
|
|
223
|
-
return
|
|
215
|
+
return collectPatternIdentifiers(node.left);
|
|
224
216
|
}
|
|
225
217
|
|
|
226
218
|
if (node.type === 'RestElement') {
|
|
227
|
-
return
|
|
219
|
+
return collectPatternIdentifiers(node.argument);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (node.type === 'TSParameterProperty') {
|
|
223
|
+
return collectPatternIdentifiers(node.parameter);
|
|
228
224
|
}
|
|
229
225
|
|
|
230
226
|
return [];
|
|
231
227
|
}
|
|
232
228
|
|
|
233
|
-
// the
|
|
234
|
-
//
|
|
235
|
-
function
|
|
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
|
+
function collectTargetMembers(node) {
|
|
236
232
|
if (node === null || node === undefined) {
|
|
237
233
|
return [];
|
|
238
234
|
}
|
|
239
235
|
|
|
240
|
-
if (node.type === '
|
|
236
|
+
if (node.type === 'MemberExpression') {
|
|
241
237
|
return [node];
|
|
242
238
|
}
|
|
243
239
|
|
|
244
240
|
if (node.type === 'ObjectPattern') {
|
|
245
241
|
return node.properties.flatMap((property) => {
|
|
246
|
-
const
|
|
242
|
+
const target = property.type === 'RestElement' ? property : property.value;
|
|
247
243
|
|
|
248
|
-
return
|
|
244
|
+
return collectTargetMembers(target);
|
|
249
245
|
});
|
|
250
246
|
}
|
|
251
247
|
|
|
252
248
|
if (node.type === 'ArrayPattern') {
|
|
253
|
-
return node.elements.flatMap((element) =>
|
|
249
|
+
return node.elements.flatMap((element) => collectTargetMembers(element));
|
|
254
250
|
}
|
|
255
251
|
|
|
256
252
|
if (node.type === 'AssignmentPattern') {
|
|
257
|
-
return
|
|
253
|
+
return collectTargetMembers(node.left);
|
|
258
254
|
}
|
|
259
255
|
|
|
260
256
|
if (node.type === 'RestElement') {
|
|
261
|
-
return
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
if (node.type === 'TSParameterProperty') {
|
|
265
|
-
return collectPatternIdentifiers(node.parameter);
|
|
257
|
+
return collectTargetMembers(node.argument);
|
|
266
258
|
}
|
|
267
259
|
|
|
268
260
|
return [];
|
|
269
261
|
}
|
|
270
262
|
|
|
263
|
+
function isTypeOnlyImport(specifier) {
|
|
264
|
+
return specifier.importKind === 'type' || specifier.parent.importKind === 'type';
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function isTypeOnlyExport(specifier) {
|
|
268
|
+
return specifier.exportKind === 'type' || specifier.parent.exportKind === 'type';
|
|
269
|
+
}
|
|
270
|
+
|
|
271
271
|
export default noAbbreviatedNames;
|
|
@@ -2,47 +2,17 @@ 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
|
-
// every repo runs the comment rules exactly as this config ships them
|
|
6
|
-
const lockedRules = ['zgeoff/no-jsdoc', 'zgeoff/max-consecutive-line-comments'];
|
|
7
|
-
|
|
8
|
-
const configPattern = /^\.oxlintrc(?:\.[\w-]+)?\.jsonc?$/u;
|
|
9
|
-
|
|
10
|
-
// a rule key, as opposed to the same text inside a comment or a string value
|
|
11
|
-
const keyPatterns = lockedRules.map((rule) => ({
|
|
12
|
-
rule,
|
|
13
|
-
pattern: new RegExp(`"${rule}"\\s*:`, 'u'),
|
|
14
|
-
}));
|
|
15
|
-
|
|
16
5
|
// the one file per repo that carries the report, so a repo with an override
|
|
17
6
|
// sees it once per run rather than on every file, and an editor's language
|
|
18
7
|
// server keeps it on that file across edits
|
|
19
8
|
const anchorFiles = new Map();
|
|
20
9
|
|
|
21
|
-
function buildCommentFreeText(text) {
|
|
22
|
-
return text.replaceAll(
|
|
23
|
-
/(?<string>"(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//gu,
|
|
24
|
-
(...match) => match.at(-1).string ?? '',
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function loadOverrides(root) {
|
|
29
|
-
const configs = readdirSync(root).filter((name) => configPattern.test(name));
|
|
30
|
-
|
|
31
|
-
return configs.flatMap((name) => {
|
|
32
|
-
const text = buildCommentFreeText(readFileSync(join(root, name), 'utf8'));
|
|
33
|
-
|
|
34
|
-
return keyPatterns
|
|
35
|
-
.filter((entry) => entry.pattern.test(text))
|
|
36
|
-
.map((entry) => ({ config: name, rule: entry.rule }));
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
10
|
const noCommentRuleOverride = {
|
|
41
11
|
meta: {
|
|
42
12
|
type: 'problem',
|
|
43
13
|
messages: {
|
|
44
14
|
override:
|
|
45
|
-
'{{config}} sets {{rule}}. Delete the setting: every repo runs
|
|
15
|
+
'{{config}} sets {{rule}}. Delete the setting: every repo runs {{rule}} as @zgeoff/oxlint-config ships it.',
|
|
46
16
|
},
|
|
47
17
|
schema: [],
|
|
48
18
|
},
|
|
@@ -72,3 +42,42 @@ const noCommentRuleOverride = {
|
|
|
72
42
|
};
|
|
73
43
|
|
|
74
44
|
export default noCommentRuleOverride;
|
|
45
|
+
|
|
46
|
+
const configPattern = /^\.oxlintrc(?:\.[\w-]+)?\.jsonc?$/u;
|
|
47
|
+
|
|
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
|
+
const lockedRules = [
|
|
51
|
+
'no-jsdoc',
|
|
52
|
+
'max-consecutive-line-comments',
|
|
53
|
+
'consistent-type-assertions',
|
|
54
|
+
'no-hidden-cast',
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
// a rule key under any plugin prefix or none, since oxlint also reads
|
|
58
|
+
// `@typescript-eslint/consistent-type-assertions` and the bare name, as
|
|
59
|
+
// opposed to the same text inside a comment or a string value
|
|
60
|
+
const keyPatterns = lockedRules.map(
|
|
61
|
+
(rule) => new RegExp(`"(?<key>(?:[^"/\\s]+/)?${rule})"\\s*:`, 'gu'),
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
function loadOverrides(root) {
|
|
65
|
+
const configs = readdirSync(root).filter((name) => configPattern.test(name));
|
|
66
|
+
|
|
67
|
+
return configs.flatMap((name) => {
|
|
68
|
+
const text = buildCommentFreeText(readFileSync(join(root, name), 'utf8'));
|
|
69
|
+
|
|
70
|
+
return keyPatterns.flatMap((pattern) => {
|
|
71
|
+
const keys = new Set(Array.from(text.matchAll(pattern), (match) => match.groups.key));
|
|
72
|
+
|
|
73
|
+
return [...keys].map((rule) => ({ config: name, rule }));
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function buildCommentFreeText(text) {
|
|
79
|
+
return text.replaceAll(
|
|
80
|
+
/(?<string>"(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//gu,
|
|
81
|
+
(...match) => match.at(-1).string ?? '',
|
|
82
|
+
);
|
|
83
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// a plain lint run has no types to tell Kysely's `sql` or bun:sqlite's
|
|
2
|
+
// `query` from another library's of the same name, so the rule matches by name
|
|
3
|
+
const castMethods = new Set(['$castTo', '$narrowType', '$assertType']);
|
|
4
|
+
const rowMethods = new Set(['query', 'prepare']);
|
|
5
|
+
const configMethods = new Set([
|
|
6
|
+
'getObject',
|
|
7
|
+
'requireObject',
|
|
8
|
+
'getSecretObject',
|
|
9
|
+
'requireSecretObject',
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const noHiddenCast = {
|
|
13
|
+
meta: {
|
|
14
|
+
type: 'problem',
|
|
15
|
+
messages: {
|
|
16
|
+
sqlType:
|
|
17
|
+
'A type argument on `sql` claims a result type that the database never checks. Drop it, read the result as `unknown`, and parse it with zod or narrow it with a guard.',
|
|
18
|
+
castMethod:
|
|
19
|
+
'`{{method}}()` claims a type that Kysely never checks. Declare the type in the table types, or narrow the result with a guard.',
|
|
20
|
+
rowType:
|
|
21
|
+
'A type argument on `{{method}}()` claims a row type that the database never checks. Query through Kysely over declared table types, or parse each row with zod.',
|
|
22
|
+
configType:
|
|
23
|
+
'A type argument on `{{method}}()` claims a config shape that Pulumi never checks. Drop it and parse the value with zod.',
|
|
24
|
+
},
|
|
25
|
+
schema: [],
|
|
26
|
+
},
|
|
27
|
+
create(context) {
|
|
28
|
+
return {
|
|
29
|
+
TaggedTemplateExpression(node) {
|
|
30
|
+
if (node.typeArguments && findName(node.tag) === 'sql') {
|
|
31
|
+
context.report({ node, messageId: 'sqlType' });
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
CallExpression(node) {
|
|
35
|
+
const method = node.callee.type === 'MemberExpression' ? findName(node.callee) : null;
|
|
36
|
+
|
|
37
|
+
if (method === null) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (castMethods.has(method)) {
|
|
42
|
+
context.report({ node, messageId: 'castMethod', data: { method } });
|
|
43
|
+
} else if (node.typeArguments && rowMethods.has(method)) {
|
|
44
|
+
context.report({ node, messageId: 'rowType', data: { method } });
|
|
45
|
+
} else if (node.typeArguments && configMethods.has(method)) {
|
|
46
|
+
context.report({ node, messageId: 'configType', data: { method } });
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
};
|
|
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
|
+
function findName(node) {
|
|
56
|
+
if (node.type === 'Identifier') {
|
|
57
|
+
return node.name;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (node.type !== 'MemberExpression') {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!node.computed) {
|
|
65
|
+
return node.property.name;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return typeof node.property.value === 'string' ? node.property.value : null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export default noHiddenCast;
|
package/no-jsdoc.js
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
// mirrors eslint-plugin-jsdoc's default singleLineTags: a block that exists to
|
|
2
|
-
// cast inline (`/** @type {Foo} */ (bar)`) is a type annotation, not prose
|
|
3
|
-
const inlineTagPattern = /^@(?:type|lends)\b/u;
|
|
4
|
-
|
|
5
|
-
function isJSDoc(comment) {
|
|
6
|
-
return comment.type === 'Block' && comment.value.startsWith('*');
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function isInlineCast(comment) {
|
|
10
|
-
return (
|
|
11
|
-
comment.loc.start.line === comment.loc.end.line &&
|
|
12
|
-
inlineTagPattern.test(comment.value.slice(1).trim())
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
1
|
const noJSDoc = {
|
|
17
2
|
meta: {
|
|
18
3
|
type: 'suggestion',
|
|
@@ -38,3 +23,18 @@ const noJSDoc = {
|
|
|
38
23
|
};
|
|
39
24
|
|
|
40
25
|
export default noJSDoc;
|
|
26
|
+
|
|
27
|
+
function isJSDoc(comment) {
|
|
28
|
+
return comment.type === 'Block' && comment.value.startsWith('*');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// mirrors eslint-plugin-jsdoc's default singleLineTags: a block that exists to
|
|
32
|
+
// cast inline (`/** @type {Foo} */ (bar)`) is a type annotation, not prose
|
|
33
|
+
const inlineTagPattern = /^@(?:type|lends)\b/u;
|
|
34
|
+
|
|
35
|
+
function isInlineCast(comment) {
|
|
36
|
+
return (
|
|
37
|
+
comment.loc.start.line === comment.loc.end.line &&
|
|
38
|
+
inlineTagPattern.test(comment.value.slice(1).trim())
|
|
39
|
+
);
|
|
40
|
+
}
|
package/oxlintrc.json
CHANGED
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"zgeoff/no-await-in-logical": "error",
|
|
28
28
|
"zgeoff/no-switch": "error",
|
|
29
29
|
"zgeoff/no-class": "error",
|
|
30
|
+
"zgeoff/no-hidden-cast": "error",
|
|
30
31
|
"zgeoff/no-jsdoc": "error",
|
|
31
32
|
"zgeoff/max-consecutive-line-comments": ["error", { "max": 3 }],
|
|
32
33
|
"zgeoff/no-comment-rule-override": "error",
|
|
@@ -96,6 +97,12 @@
|
|
|
96
97
|
// restriction-category cherry-picks
|
|
97
98
|
"typescript/no-explicit-any": "error",
|
|
98
99
|
"typescript/no-non-null-assertion": "error",
|
|
100
|
+
|
|
101
|
+
// every type assertion other than `as const` fails; one that survives
|
|
102
|
+
// carries a disable comment naming this rule, which already covers each
|
|
103
|
+
// assertion the type-aware no-unsafe-type-assertion would check
|
|
104
|
+
"typescript/consistent-type-assertions": ["error", { "assertionStyle": "never" }],
|
|
105
|
+
"typescript/no-unsafe-type-assertion": "off",
|
|
99
106
|
"import/no-cycle": "error",
|
|
100
107
|
|
|
101
108
|
"no-shadow": "error",
|
|
@@ -215,8 +222,7 @@
|
|
|
215
222
|
"typescript/no-unsafe-assignment": "off",
|
|
216
223
|
"typescript/no-unsafe-call": "off",
|
|
217
224
|
"typescript/no-unsafe-member-access": "off",
|
|
218
|
-
"typescript/no-unsafe-return": "off"
|
|
219
|
-
"typescript/no-unsafe-type-assertion": "off"
|
|
225
|
+
"typescript/no-unsafe-return": "off"
|
|
220
226
|
}
|
|
221
227
|
}
|
|
222
228
|
]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zgeoff/oxlint-config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Shareable oxlint config: strict categories, house-style rules, and a custom JS plugin",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -25,14 +25,22 @@
|
|
|
25
25
|
"no-class.js",
|
|
26
26
|
"no-jsdoc.js",
|
|
27
27
|
"no-comment-rule-override.js",
|
|
28
|
+
"no-hidden-cast.js",
|
|
28
29
|
"test-beside-module.js",
|
|
29
30
|
"no-file-snapshot.js",
|
|
30
31
|
"setup-test-only.js",
|
|
31
32
|
"import-zones.js",
|
|
32
33
|
"import-zones-schema.js",
|
|
34
|
+
"import-zones-entry.js",
|
|
35
|
+
"import-zones-entry.d.ts",
|
|
36
|
+
"collect-refusing-edges.js",
|
|
37
|
+
"is-edge-refusing.js",
|
|
38
|
+
"is-entry-applying.js",
|
|
39
|
+
"is-in-any-zone.js",
|
|
40
|
+
"collect-zone-names.js",
|
|
33
41
|
"resolve-repo-root.js",
|
|
34
42
|
"load-workspace-manifests.js",
|
|
35
|
-
"
|
|
43
|
+
"get-zone-options.js",
|
|
36
44
|
"make-glob-matcher.js",
|
|
37
45
|
"resolve-import-target.js",
|
|
38
46
|
"index.js"
|
|
@@ -41,7 +49,11 @@
|
|
|
41
49
|
"exports": {
|
|
42
50
|
".": "./index.js",
|
|
43
51
|
"./oxlintrc.json": "./oxlintrc.json",
|
|
44
|
-
"./plugin": "./plugin.js"
|
|
52
|
+
"./plugin": "./plugin.js",
|
|
53
|
+
"./import-zones": {
|
|
54
|
+
"types": "./import-zones-entry.d.ts",
|
|
55
|
+
"default": "./import-zones-entry.js"
|
|
56
|
+
}
|
|
45
57
|
},
|
|
46
58
|
"publishConfig": {
|
|
47
59
|
"access": "public"
|
package/plugin.js
CHANGED
|
@@ -6,30 +6,13 @@ import noAbbreviatedNames from './no-abbreviated-names.js';
|
|
|
6
6
|
import noClass from './no-class.js';
|
|
7
7
|
import noCommentRuleOverride from './no-comment-rule-override.js';
|
|
8
8
|
import noFileSnapshot from './no-file-snapshot.js';
|
|
9
|
+
import noHiddenCast from './no-hidden-cast.js';
|
|
9
10
|
import noJSDoc from './no-jsdoc.js';
|
|
10
11
|
import noRestrictedWords from './no-restricted-words.js';
|
|
11
12
|
import setupTestOnly from './setup-test-only.js';
|
|
12
13
|
import testBesideModule from './test-beside-module.js';
|
|
13
14
|
import verbContract from './verb-contract.js';
|
|
14
15
|
|
|
15
|
-
// custom rules loaded through oxlint's jsPlugins (ESLint v9 rule API): each
|
|
16
|
-
// bans a shape no native oxlint rule can express, as an esquery selector or a
|
|
17
|
-
// source-comment scan
|
|
18
|
-
|
|
19
|
-
function buildBanRule(type, message, selectors) {
|
|
20
|
-
return {
|
|
21
|
-
meta: { type, messages: { banned: message }, schema: [] },
|
|
22
|
-
create(context) {
|
|
23
|
-
const entries = selectors.map((selector) => [
|
|
24
|
-
selector,
|
|
25
|
-
(node) => context.report({ node, messageId: 'banned' }),
|
|
26
|
-
]);
|
|
27
|
-
|
|
28
|
-
return Object.fromEntries(entries);
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
16
|
const plugin = {
|
|
34
17
|
meta: { name: 'zgeoff' },
|
|
35
18
|
rules: {
|
|
@@ -108,6 +91,7 @@ const plugin = {
|
|
|
108
91
|
['SwitchStatement'],
|
|
109
92
|
),
|
|
110
93
|
'no-class': noClass,
|
|
94
|
+
'no-hidden-cast': noHiddenCast,
|
|
111
95
|
'no-jsdoc': noJSDoc,
|
|
112
96
|
'max-consecutive-line-comments': maxConsecutiveLineComments,
|
|
113
97
|
'no-comment-rule-override': noCommentRuleOverride,
|
|
@@ -124,3 +108,21 @@ const plugin = {
|
|
|
124
108
|
};
|
|
125
109
|
|
|
126
110
|
export default plugin;
|
|
111
|
+
|
|
112
|
+
// custom rules loaded through oxlint's jsPlugins (ESLint v9 rule API): each
|
|
113
|
+
// bans a shape no native oxlint rule can express, as an esquery selector or a
|
|
114
|
+
// source-comment scan
|
|
115
|
+
|
|
116
|
+
function buildBanRule(type, message, selectors) {
|
|
117
|
+
return {
|
|
118
|
+
meta: { type, messages: { banned: message }, schema: [] },
|
|
119
|
+
create(context) {
|
|
120
|
+
const entries = selectors.map((selector) => [
|
|
121
|
+
selector,
|
|
122
|
+
(node) => context.report({ node, messageId: 'banned' }),
|
|
123
|
+
]);
|
|
124
|
+
|
|
125
|
+
return Object.fromEntries(entries);
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
}
|