@zgeoff/oxlint-config 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- 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 +30 -30
- package/no-jsdoc.js +15 -15
- package/package.json +14 -3
- package/plugin.js +18 -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 +35 -33
- package/verb-contract.js +93 -93
|
@@ -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,41 +2,11 @@ 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',
|
|
@@ -72,3 +42,33 @@ 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 exactly as this config ships them
|
|
49
|
+
const lockedRules = ['zgeoff/no-jsdoc', 'zgeoff/max-consecutive-line-comments'];
|
|
50
|
+
|
|
51
|
+
// a rule key, as opposed to the same text inside a comment or a string value
|
|
52
|
+
const keyPatterns = lockedRules.map((rule) => ({
|
|
53
|
+
rule,
|
|
54
|
+
pattern: new RegExp(`"${rule}"\\s*:`, 'u'),
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
function loadOverrides(root) {
|
|
58
|
+
const configs = readdirSync(root).filter((name) => configPattern.test(name));
|
|
59
|
+
|
|
60
|
+
return configs.flatMap((name) => {
|
|
61
|
+
const text = buildCommentFreeText(readFileSync(join(root, name), 'utf8'));
|
|
62
|
+
|
|
63
|
+
return keyPatterns
|
|
64
|
+
.filter((entry) => entry.pattern.test(text))
|
|
65
|
+
.map((entry) => ({ config: name, rule: entry.rule }));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function buildCommentFreeText(text) {
|
|
70
|
+
return text.replaceAll(
|
|
71
|
+
/(?<string>"(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//gu,
|
|
72
|
+
(...match) => match.at(-1).string ?? '',
|
|
73
|
+
);
|
|
74
|
+
}
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zgeoff/oxlint-config",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "Shareable oxlint config: strict categories, house-style rules, and a custom JS plugin",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -30,9 +30,16 @@
|
|
|
30
30
|
"setup-test-only.js",
|
|
31
31
|
"import-zones.js",
|
|
32
32
|
"import-zones-schema.js",
|
|
33
|
+
"import-zones-entry.js",
|
|
34
|
+
"import-zones-entry.d.ts",
|
|
35
|
+
"collect-refusing-edges.js",
|
|
36
|
+
"is-edge-refusing.js",
|
|
37
|
+
"is-entry-applying.js",
|
|
38
|
+
"is-in-any-zone.js",
|
|
39
|
+
"collect-zone-names.js",
|
|
33
40
|
"resolve-repo-root.js",
|
|
34
41
|
"load-workspace-manifests.js",
|
|
35
|
-
"
|
|
42
|
+
"get-zone-options.js",
|
|
36
43
|
"make-glob-matcher.js",
|
|
37
44
|
"resolve-import-target.js",
|
|
38
45
|
"index.js"
|
|
@@ -41,7 +48,11 @@
|
|
|
41
48
|
"exports": {
|
|
42
49
|
".": "./index.js",
|
|
43
50
|
"./oxlintrc.json": "./oxlintrc.json",
|
|
44
|
-
"./plugin": "./plugin.js"
|
|
51
|
+
"./plugin": "./plugin.js",
|
|
52
|
+
"./import-zones": {
|
|
53
|
+
"types": "./import-zones-entry.d.ts",
|
|
54
|
+
"default": "./import-zones-entry.js"
|
|
55
|
+
}
|
|
45
56
|
},
|
|
46
57
|
"publishConfig": {
|
|
47
58
|
"access": "public"
|
package/plugin.js
CHANGED
|
@@ -12,24 +12,6 @@ import setupTestOnly from './setup-test-only.js';
|
|
|
12
12
|
import testBesideModule from './test-beside-module.js';
|
|
13
13
|
import verbContract from './verb-contract.js';
|
|
14
14
|
|
|
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
15
|
const plugin = {
|
|
34
16
|
meta: { name: 'zgeoff' },
|
|
35
17
|
rules: {
|
|
@@ -124,3 +106,21 @@ const plugin = {
|
|
|
124
106
|
};
|
|
125
107
|
|
|
126
108
|
export default plugin;
|
|
109
|
+
|
|
110
|
+
// custom rules loaded through oxlint's jsPlugins (ESLint v9 rule API): each
|
|
111
|
+
// bans a shape no native oxlint rule can express, as an esquery selector or a
|
|
112
|
+
// source-comment scan
|
|
113
|
+
|
|
114
|
+
function buildBanRule(type, message, selectors) {
|
|
115
|
+
return {
|
|
116
|
+
meta: { type, messages: { banned: message }, schema: [] },
|
|
117
|
+
create(context) {
|
|
118
|
+
const entries = selectors.map((selector) => [
|
|
119
|
+
selector,
|
|
120
|
+
(node) => context.report({ node, messageId: 'banned' }),
|
|
121
|
+
]);
|
|
122
|
+
|
|
123
|
+
return Object.fromEntries(entries);
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|