@zgeoff/oxlint-config 0.10.3 → 0.10.4
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/feature-folders.js +3 -9
- package/file-named-for-export.js +50 -3
- package/import-zones.js +1 -5
- package/package.json +4 -1
- package/resolve-package-directory.js +29 -0
- package/to-pending-path.js +5 -0
- package/to-root-path.js +5 -0
package/feature-folders.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { basename, join
|
|
1
|
+
import { basename, join } from 'node:path';
|
|
2
2
|
import buildImportSettings from './build-import-settings.js';
|
|
3
3
|
import findFeatureFolder from './find-feature-folder.js';
|
|
4
4
|
import pickFolderKind from './pick-folder-kind.js';
|
|
@@ -8,6 +8,8 @@ import readStalePending from './read-stale-pending.js';
|
|
|
8
8
|
import resolveImportTarget from './resolve-import-target.js';
|
|
9
9
|
import resolveRepoRoot from './resolve-repo-root.js';
|
|
10
10
|
import resolveSourcePackage from './resolve-source-package.js';
|
|
11
|
+
import toPendingPath from './to-pending-path.js';
|
|
12
|
+
import toRootPath from './to-root-path.js';
|
|
11
13
|
|
|
12
14
|
const looseModuleLimit = 8;
|
|
13
15
|
|
|
@@ -88,14 +90,6 @@ const featureFolders = {
|
|
|
88
90
|
|
|
89
91
|
export default featureFolders;
|
|
90
92
|
|
|
91
|
-
function toPendingPath(entry) {
|
|
92
|
-
return posix.normalize(entry).replace(/(?<=.)\/+$/u, '');
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function toRootPath(root, path) {
|
|
96
|
-
return relative(root, path).split(sep).join('/') || '.';
|
|
97
|
-
}
|
|
98
|
-
|
|
99
93
|
function buildUtilsVisitors(file) {
|
|
100
94
|
const settings = buildImportSettings(file.root);
|
|
101
95
|
const check = (node) => {
|
package/file-named-for-export.js
CHANGED
|
@@ -1,20 +1,63 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { basename, join } from 'node:path';
|
|
3
|
+
import resolvePackageDirectory from './resolve-package-directory.js';
|
|
4
|
+
import resolveRepoRoot from './resolve-repo-root.js';
|
|
5
|
+
import toPendingPath from './to-pending-path.js';
|
|
6
|
+
import toRootPath from './to-root-path.js';
|
|
2
7
|
|
|
3
8
|
const exemptBases = new Set(['index', 'types', 'constants']);
|
|
4
9
|
|
|
10
|
+
// a report on one file per repo shows once per run, and an editor's
|
|
11
|
+
// language server keeps it on that file across edits
|
|
12
|
+
const anchorFiles = new Map();
|
|
13
|
+
|
|
5
14
|
const fileNamedForExport = {
|
|
6
15
|
meta: {
|
|
7
16
|
type: 'suggestion',
|
|
8
17
|
messages: {
|
|
9
18
|
mismatch:
|
|
10
19
|
"No export of '{{file}}' is named for the file: name the main export '{{base}}' in camelCase, PascalCase or SCREAMING_SNAKE_CASE, or rename the file for its main export.",
|
|
20
|
+
pendingMissing:
|
|
21
|
+
'`{{entry}}` in the `pending` option of zgeoff/file-named-for-export names no package; remove it from `pending`.',
|
|
11
22
|
},
|
|
12
|
-
schema: [
|
|
23
|
+
schema: [
|
|
24
|
+
{
|
|
25
|
+
type: 'object',
|
|
26
|
+
properties: { pending: { type: 'array', items: { type: 'string' } } },
|
|
27
|
+
additionalProperties: false,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
13
30
|
},
|
|
14
31
|
create(context) {
|
|
32
|
+
const filename = context.physicalFilename;
|
|
33
|
+
const root = resolveRepoRoot(filename) ?? context.cwd;
|
|
34
|
+
const pending = (context.options[0]?.pending ?? []).map((entry) => toPendingPath(entry));
|
|
35
|
+
const directory = pending.length === 0 ? null : resolvePackageDirectory(filename, root);
|
|
36
|
+
const isPending = directory !== null && pending.includes(toRootPath(root, directory));
|
|
37
|
+
|
|
38
|
+
if (!anchorFiles.has(root)) {
|
|
39
|
+
anchorFiles.set(root, filename);
|
|
40
|
+
}
|
|
41
|
+
|
|
15
42
|
return {
|
|
16
43
|
Program(program) {
|
|
17
|
-
|
|
44
|
+
if (anchorFiles.get(root) === filename) {
|
|
45
|
+
const start = program.body[0]?.loc.start ?? { line: 1, column: 0 };
|
|
46
|
+
|
|
47
|
+
for (const entry of readMissingPending(root, pending)) {
|
|
48
|
+
context.report({
|
|
49
|
+
loc: { start, end: start },
|
|
50
|
+
messageId: 'pendingMissing',
|
|
51
|
+
data: { entry },
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (isPending) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const file = basename(filename);
|
|
18
61
|
const [base, ...suffixes] = file.split('.');
|
|
19
62
|
|
|
20
63
|
// a role suffix, such as `.config` or `.bench`, marks a file that a tool loads, and the
|
|
@@ -47,6 +90,10 @@ const fileNamedForExport = {
|
|
|
47
90
|
|
|
48
91
|
export default fileNamedForExport;
|
|
49
92
|
|
|
93
|
+
function readMissingPending(root, pending) {
|
|
94
|
+
return pending.filter((entry) => !existsSync(join(root, entry, 'package.json')));
|
|
95
|
+
}
|
|
96
|
+
|
|
50
97
|
const exportTypes = new Set([
|
|
51
98
|
'ExportNamedDeclaration',
|
|
52
99
|
'ExportDefaultDeclaration',
|
package/import-zones.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isBuiltin } from 'node:module';
|
|
2
|
-
import { relative, sep } from 'node:path';
|
|
3
2
|
import collectZoneNames from './collect-zone-names.js';
|
|
4
3
|
import getZoneOptions from './get-zone-options.js';
|
|
5
4
|
import importZonesSchema from './import-zones-schema.js';
|
|
@@ -9,6 +8,7 @@ import isInAnyZone from './is-in-any-zone.js';
|
|
|
9
8
|
import loadWorkspaceManifests from './load-workspace-manifests.js';
|
|
10
9
|
import resolveImportTarget from './resolve-import-target.js';
|
|
11
10
|
import resolveRepoRoot from './resolve-repo-root.js';
|
|
11
|
+
import toRootPath from './to-root-path.js';
|
|
12
12
|
|
|
13
13
|
const importZones = {
|
|
14
14
|
meta: {
|
|
@@ -100,10 +100,6 @@ function loadFileState(context) {
|
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
function toRootPath(root, path) {
|
|
104
|
-
return relative(root, path).split(sep).join('/');
|
|
105
|
-
}
|
|
106
|
-
|
|
107
103
|
function checkUnzoned(file, program) {
|
|
108
104
|
// anchor on the first statement, not offset 0, so a disable comment at the
|
|
109
105
|
// top of the file covers the report
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zgeoff/oxlint-config",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.4",
|
|
4
4
|
"description": "Shareable oxlint config: strict categories, house-style rules, and a custom JS plugin",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -73,6 +73,9 @@
|
|
|
73
73
|
"build-seed-only.js",
|
|
74
74
|
"test-beside-seed.js",
|
|
75
75
|
"file-named-for-export.js",
|
|
76
|
+
"resolve-package-directory.js",
|
|
77
|
+
"to-pending-path.js",
|
|
78
|
+
"to-root-path.js",
|
|
76
79
|
"read-folder-sources.js",
|
|
77
80
|
"collect-written-tables.js",
|
|
78
81
|
"collect-sql-writes.js",
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { dirname, join, relative, sep } from 'node:path';
|
|
3
|
+
|
|
4
|
+
// a folder whose `src/` holds the file wins over every `package.json` below it, so one inside
|
|
5
|
+
// `src/`, such as one that sets `type`, does not stand in for the package; the walk stops at the
|
|
6
|
+
// repo root, so a `package.json` above the checkout never counts
|
|
7
|
+
export default function resolvePackageDirectory(filename, root) {
|
|
8
|
+
let nearest = null;
|
|
9
|
+
let source = null;
|
|
10
|
+
let directory = dirname(filename);
|
|
11
|
+
|
|
12
|
+
while (true) {
|
|
13
|
+
if (existsSync(join(directory, 'package.json'))) {
|
|
14
|
+
nearest ??= directory;
|
|
15
|
+
|
|
16
|
+
if (!relative(join(directory, 'src'), filename).startsWith(`..${sep}`)) {
|
|
17
|
+
source = directory;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const parent = dirname(directory);
|
|
22
|
+
|
|
23
|
+
if (directory === root || parent === directory) {
|
|
24
|
+
return source ?? nearest;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
directory = parent;
|
|
28
|
+
}
|
|
29
|
+
}
|