-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlint-source.test.mjs
More file actions
86 lines (80 loc) · 2.65 KB
/
Copy pathlint-source.test.mjs
File metadata and controls
86 lines (80 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import assert from "node:assert/strict";
import { resolve } from "node:path";
import { test } from "node:test";
import { inspectSource } from "./lint-source.mjs";
const root = resolve("/fixture");
function inspect(content, file = "apps/web/app/page.tsx") {
return inspectSource({ root, pathname: resolve(root, file), content });
}
test("rejects private source imports from apps and examples", () => {
assert.match(
inspect('import { value } from "../../../packages/core/src/index.js";')[0],
/cross-package source import from core/,
);
assert.match(
inspect(
'export * from "../../packages/core/src/index.js";',
"examples/node/index.ts",
)[0],
/cross-package source import from core/,
);
});
test("checks static, dynamic, CommonJS, and type-only import forms", () => {
for (const content of [
'import "@ndycode/timetablekit/src/index.js";',
'export * from "@ndycode/timetablekit/src/index.js";',
'const module = import("@ndycode/timetablekit/src/index.js");',
'const module = require("@ndycode/timetablekit/src/index.js");',
'const imported = module.require("@ndycode/timetablekit/src/index.js");',
'const imported = module.require("../../../packages/core/src/index.js");',
'type Result = import("@ndycode/timetablekit/src/index.js").Result;',
'import module = require("@ndycode/timetablekit/src/index.js");',
]) {
assert.match(inspect(content)[0], /cross-package source import/);
}
});
test("allows public exports and a package's own source", () => {
assert.deepEqual(
inspect('import { parseTimetable } from "@ndycode/timetablekit";'),
[],
);
assert.deepEqual(
inspect(
'import { value } from "../src/index.js";',
"packages/core/tests/core.test.ts",
),
[],
);
assert.match(
inspect(
'import { value } from "../../core/src/index.js";',
"packages/agent/src/index.ts",
)[0],
/cross-package source import from core/,
);
});
test("rejects unsafe types without rejecting prose, comments, or property names", () => {
assert.match(inspect("const value: any = 1;")[0], /explicit any/);
assert.deepEqual(
inspect(
'const text = "Review any conflicts"; // any\nconst options = { any: true };',
),
[],
);
assert.deepEqual(
inspect("const element = <p>Review any conflicts.</p>;"),
[],
);
});
test("ignores import examples in text and reports the actual source line", () => {
assert.deepEqual(
inspect(
"const example = 'import \"@ndycode/timetablekit/src/index.js\";';",
),
[],
);
assert.match(
inspect('\n\nexport * from "@ndycode/timetablekit/src/index.js";')[0],
/:3 cross-package/,
);
});