eslint-plugin-kerfjs 5.0.0-beta.136 → 5.0.0-beta.137
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/index.js +1 -1
- package/lib/rules/ui-wiring.js +74 -19
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -16,7 +16,7 @@ import uiPublicBoundaries from './lib/rules/ui-public-boundaries.js';
|
|
|
16
16
|
import uiWiring from './lib/rules/ui-wiring.js';
|
|
17
17
|
|
|
18
18
|
const plugin = {
|
|
19
|
-
meta: { name: 'eslint-plugin-kerfjs', version: '5.0.0-beta.
|
|
19
|
+
meta: { name: 'eslint-plugin-kerfjs', version: '5.0.0-beta.137' },
|
|
20
20
|
rules: {
|
|
21
21
|
'no-inline-jsx-event-handlers': noInlineJsxEventHandlers,
|
|
22
22
|
'no-raw-with-dynamic-arg': noRawWithDynamicArg,
|
package/lib/rules/ui-wiring.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
-
import { relative, resolve } from 'node:path';
|
|
1
|
+
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import { dirname, relative, resolve } from 'node:path';
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
helperCall,
|
|
@@ -32,27 +32,82 @@ function moduleImportSources(source) {
|
|
|
32
32
|
return [...withoutComments.matchAll(staticImports)].map((match) => match[1]);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
// ESLint invokes this rule once per file, but a wiring entry usually reaches
|
|
36
|
+
// the same modules on every invocation. Cache parsing and import resolution;
|
|
37
|
+
// the DFS below still builds the right graph for each entry and current buffer.
|
|
38
|
+
const moduleCache = new Map();
|
|
39
|
+
export function clearUiWiringModuleCache() {
|
|
40
|
+
moduleCache.clear();
|
|
41
|
+
}
|
|
42
|
+
function stamp(path) {
|
|
43
|
+
try {
|
|
44
|
+
const { mtimeMs, ctimeMs, size } = statSync(path);
|
|
45
|
+
return `${mtimeMs}:${ctimeMs}:${size}`;
|
|
46
|
+
} catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function moduleData(file, currentFile, currentText) {
|
|
52
|
+
const onDisk = stamp(file);
|
|
53
|
+
const cached = moduleCache.get(file);
|
|
54
|
+
const sourceIsCurrent = file === currentFile;
|
|
55
|
+
const fresh =
|
|
56
|
+
cached &&
|
|
57
|
+
cached.stamp === onDisk &&
|
|
58
|
+
(!sourceIsCurrent || cached.source === currentText) &&
|
|
59
|
+
cached.directories.every(([path, value]) => stamp(path) === value);
|
|
60
|
+
if (fresh) return cached;
|
|
61
|
+
let source;
|
|
62
|
+
try {
|
|
63
|
+
source = sourceIsCurrent ? currentText : readFileSync(file, 'utf8');
|
|
64
|
+
} catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
const dependencies = [];
|
|
68
|
+
const directories = new Map();
|
|
69
|
+
for (const [, specifier] of [
|
|
70
|
+
...source.matchAll(imports),
|
|
71
|
+
...source.matchAll(dynamicImports),
|
|
72
|
+
]) {
|
|
73
|
+
if (!specifier.startsWith('.')) continue;
|
|
74
|
+
const candidates = relativeImportCandidates(file, specifier);
|
|
75
|
+
for (const candidate of candidates) {
|
|
76
|
+
const directory = dirname(candidate);
|
|
77
|
+
if (!directories.has(directory))
|
|
78
|
+
directories.set(directory, stamp(directory));
|
|
79
|
+
}
|
|
80
|
+
const dependency = candidates.find(
|
|
81
|
+
(candidate) => script.test(candidate) && existsSync(candidate),
|
|
82
|
+
);
|
|
83
|
+
if (dependency) dependencies.push(dependency);
|
|
84
|
+
}
|
|
85
|
+
const data = {
|
|
86
|
+
source,
|
|
87
|
+
dependencies,
|
|
88
|
+
stamp: onDisk,
|
|
89
|
+
directories: [...directories],
|
|
90
|
+
};
|
|
91
|
+
// An unsaved editor buffer must not become the disk result seen by another
|
|
92
|
+
// file's lint pass.
|
|
93
|
+
if (!sourceIsCurrent) moduleCache.set(file, data);
|
|
94
|
+
else if (onDisk !== null)
|
|
95
|
+
try {
|
|
96
|
+
if (source === readFileSync(file, 'utf8')) moduleCache.set(file, data);
|
|
97
|
+
} catch {
|
|
98
|
+
// A virtual ESLint file has no reusable disk result.
|
|
99
|
+
}
|
|
100
|
+
return data;
|
|
101
|
+
}
|
|
102
|
+
|
|
35
103
|
function entryModules(entryFile, currentFile, currentText) {
|
|
36
104
|
const modules = new Map();
|
|
37
105
|
const visit = (file) => {
|
|
38
106
|
if (modules.has(file)) return;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
modules.set(file, source);
|
|
46
|
-
for (const [, specifier] of [
|
|
47
|
-
...source.matchAll(imports),
|
|
48
|
-
...source.matchAll(dynamicImports),
|
|
49
|
-
]) {
|
|
50
|
-
if (!specifier.startsWith('.')) continue;
|
|
51
|
-
const dependency = relativeImportCandidates(file, specifier).find(
|
|
52
|
-
(candidate) => script.test(candidate) && existsSync(candidate),
|
|
53
|
-
);
|
|
54
|
-
if (dependency) visit(dependency);
|
|
55
|
-
}
|
|
107
|
+
const data = moduleData(file, currentFile, currentText);
|
|
108
|
+
if (!data) return;
|
|
109
|
+
modules.set(file, data.source);
|
|
110
|
+
for (const dependency of data.dependencies) visit(dependency);
|
|
56
111
|
};
|
|
57
112
|
visit(entryFile);
|
|
58
113
|
return modules;
|
package/package.json
CHANGED