@mapringg/standard 0.0.0-stage → 1.15.3
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/.claude/skills/adopt-standard/SKILL.md +189 -0
- package/.claude/skills/capture/SKILL.md +27 -0
- package/.claude/skills/pr/LICENSE +21 -0
- package/.claude/skills/pr/SKILL.md +170 -0
- package/.claude/skills/pr/UPSTREAM.md +4 -0
- package/.claude/skills/review-standard/SKILL.md +12 -0
- package/.claude/skills/test-audit/SKILL.md +25 -0
- package/.claude/skills/upgrade-standard/SKILL.md +25 -0
- package/LICENSE +21 -0
- package/README.md +10 -2
- package/bin/check-pr.mjs +11 -0
- package/bin/upload-evidence.mjs +120 -0
- package/knip.json +25 -0
- package/oxfmt.json +8 -0
- package/oxlint.json +464 -0
- package/package.json +63 -4
- package/packages/create-mapringg-repo/LICENSE +21 -0
- package/packages/create-mapringg-repo/cli.mjs +323 -0
- package/packages/create-mapringg-repo/github.mjs +128 -0
- package/packages/create-mapringg-repo/package.json +25 -0
- package/packages/create-mapringg-repo/release.mjs +52 -0
- package/packages/create-mapringg-repo/setup.mjs +173 -0
- package/src/plugin/agent-docs.mjs +240 -0
- package/src/plugin/design-system.mjs +75 -0
- package/src/plugin/feature-imports.mjs +38 -0
- package/src/plugin/hono.mjs +186 -0
- package/src/plugin/index.mjs +42 -0
- package/src/plugin/markdown-lines.mjs +35 -0
- package/src/plugin/next-data.mjs +124 -0
- package/src/plugin/next-routes.mjs +63 -0
- package/src/plugin/no-chained-assertions.mjs +22 -0
- package/src/plugin/no-comments.mjs +23 -0
- package/src/plugin/no-return-types.mjs +48 -0
- package/src/plugin/no-typeof.mjs +27 -0
- package/src/plugin/owners.mjs +428 -0
- package/src/plugin/params.mjs +75 -0
- package/src/plugin/paths.mjs +192 -0
- package/src/plugin/pr-check.mjs +141 -0
- package/src/plugin/query-client.mjs +49 -0
- package/src/plugin/reducer.mjs +84 -0
- package/src/plugin/repo-shape.mjs +351 -0
- package/src/plugin/repository-docs.mjs +119 -0
- package/src/plugin/server-actions.mjs +60 -0
- package/src/plugin/tests.mjs +222 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
import { classify } from "./markdown-lines.mjs";
|
|
5
|
+
import { listFiles } from "./paths.mjs";
|
|
6
|
+
|
|
7
|
+
const TITLE = /^# [^#\s].*$/;
|
|
8
|
+
const HEADING = /^ {0,3}#{1,6}(?:\s|$)/;
|
|
9
|
+
const BULLET = /^- \S/;
|
|
10
|
+
const QUICK_START = "## Quick start";
|
|
11
|
+
const VISIBLE_LIMIT = 100;
|
|
12
|
+
const SEGMENTER = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
13
|
+
const LINKS =
|
|
14
|
+
/!?\[([^\]\n]+)\](?:\(\s*(?:<[^>\n]*>|[^\s()]*(?:\([^()\n]*\)[^\s()]*)*)(?:\s+(?:"[^"\n]*"|'[^'\n]*'))?\s*\)|\[[^\]\n]*\])/g;
|
|
15
|
+
|
|
16
|
+
const CODE_SPAN = /(`+)([^\n]*?)\1/g;
|
|
17
|
+
|
|
18
|
+
function visibleLength(text) {
|
|
19
|
+
const code = [];
|
|
20
|
+
const prose = text
|
|
21
|
+
.replace(CODE_SPAN, (_, _fence, value) => {
|
|
22
|
+
code.push(value);
|
|
23
|
+
return "\u0000";
|
|
24
|
+
})
|
|
25
|
+
.replace(LINKS, "$1")
|
|
26
|
+
.replace(/<\/?[a-z][^>]*>/gi, "")
|
|
27
|
+
.replace(/(\*{1,3}|_{1,3})(\S(?:.*?\S)?)\1/g, "$2");
|
|
28
|
+
let index = 0;
|
|
29
|
+
return Array.from(SEGMENTER.segment(prose.replaceAll("\u0000", () => code[index++]).trim())).length;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function checkLength(text, line, report) {
|
|
33
|
+
const length = visibleLength(text);
|
|
34
|
+
if (length > VISIBLE_LIMIT) report(line, "Shorten this text to 100 visible characters (currently " + length + ").");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function checkAgents(lines, report) {
|
|
38
|
+
if (lines[0]?.line !== "# AGENTS.md") report(1, "Start with # AGENTS.md.");
|
|
39
|
+
let section = null;
|
|
40
|
+
for (const { line, kind, number } of lines.slice(1)) {
|
|
41
|
+
if (!line.trim() || kind === "generated") continue;
|
|
42
|
+
if (line === "## Rules" && section === null) {
|
|
43
|
+
section = "Rules";
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (line === "## Sources" && section !== "Sources") {
|
|
47
|
+
section = "Sources";
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (section && kind === "prose" && BULLET.test(line)) checkLength(line.slice(2), number, report);
|
|
51
|
+
else report(number, "Use ## Rules and optional ## Sources with flat, single-line bullets.");
|
|
52
|
+
}
|
|
53
|
+
if (!section) report(1, "Add ## Rules or ## Sources with a scoped instruction.");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function checkReadme(lines, report) {
|
|
57
|
+
const title = lines[0]?.line ?? "";
|
|
58
|
+
if (!TITLE.test(title) || /^# README(?:\.md)?\s*$/i.test(title))
|
|
59
|
+
report(1, "Start with a # heading naming the project.");
|
|
60
|
+
const start = lines.findIndex(({ line, kind }) => kind === "prose" && line === QUICK_START);
|
|
61
|
+
if (start < 0) report(1, "Add ## Quick start after the overview.");
|
|
62
|
+
const before = lines.slice(1, start < 0 ? undefined : start);
|
|
63
|
+
const overview = before
|
|
64
|
+
.map(({ line }) => line)
|
|
65
|
+
.join("\n")
|
|
66
|
+
.trim();
|
|
67
|
+
if (
|
|
68
|
+
!overview ||
|
|
69
|
+
/\n[ \t]*\n/.test(overview) ||
|
|
70
|
+
before.some(({ line, kind }) => kind !== "prose" || BULLET.test(line) || HEADING.test(line))
|
|
71
|
+
)
|
|
72
|
+
report(2, "Give the project a single overview paragraph below its title.");
|
|
73
|
+
|
|
74
|
+
let paragraph = [];
|
|
75
|
+
let first = 1;
|
|
76
|
+
for (const { line, kind, number } of lines.slice(1)) {
|
|
77
|
+
const structural = kind !== "prose" || !line.trim() || HEADING.test(line) || line.startsWith("|");
|
|
78
|
+
const bullet = /^(?:[-*+]|\d+[.)])\s+/.exec(line);
|
|
79
|
+
if (structural || bullet) {
|
|
80
|
+
checkLength(paragraph.join(" "), first, report);
|
|
81
|
+
paragraph = [];
|
|
82
|
+
}
|
|
83
|
+
if (HEADING.test(line) && kind === "prose" && number !== start + 1)
|
|
84
|
+
report(number, "Use ## Quick start as the sole README section.");
|
|
85
|
+
if (structural) continue;
|
|
86
|
+
if (!paragraph.length) first = number;
|
|
87
|
+
paragraph.push(line.slice(bullet?.[0].length ?? 0).trim());
|
|
88
|
+
}
|
|
89
|
+
checkLength(paragraph.join(" "), first, report);
|
|
90
|
+
if (start >= 0 && !lines.slice(start + 1).some(({ line }) => line.trim()))
|
|
91
|
+
report(start + 1, "Add the steps to get started.");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function repositoryDocProblems(root) {
|
|
95
|
+
const files = listFiles(root).filter((file) => !file.startsWith("vendor/"));
|
|
96
|
+
const findings = [];
|
|
97
|
+
for (const required of ["README.md", "AGENTS.md"])
|
|
98
|
+
if (!files.includes(required)) findings.push(required + ":1: Add this file at the repository root.");
|
|
99
|
+
|
|
100
|
+
for (const file of files) {
|
|
101
|
+
const agents = /(?:^|\/)AGENTS\.md$/.test(file);
|
|
102
|
+
if (!agents && !/(?:^|\/)README\.md$/i.test(file)) continue;
|
|
103
|
+
const report = (line, message) => findings.push(file + ":" + line + ": " + message);
|
|
104
|
+
if (!agents && file !== "README.md") {
|
|
105
|
+
report(1, "Keep the repository's README.md at the root.");
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const lines = classify(readFileSync(join(root, file), "utf8")).map((item, index) => ({
|
|
109
|
+
...item,
|
|
110
|
+
number: index + 1,
|
|
111
|
+
}));
|
|
112
|
+
for (const { line, kind, number } of lines)
|
|
113
|
+
if (kind === "prose" && line.replace(CODE_SPAN, "").includes("<!--"))
|
|
114
|
+
report(number, "Remove handwritten comments and put lasting instructions under Rules.");
|
|
115
|
+
if (agents) checkAgents(lines, report);
|
|
116
|
+
else checkReadme(lines, report);
|
|
117
|
+
}
|
|
118
|
+
return findings;
|
|
119
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { exportedIds, stem } from "./paths.mjs";
|
|
2
|
+
|
|
3
|
+
function directives(body) {
|
|
4
|
+
const found = [];
|
|
5
|
+
for (const node of Array.isArray(body) ? body : []) {
|
|
6
|
+
if (node.type !== "ExpressionStatement" || typeof node.directive !== "string") break;
|
|
7
|
+
found.push(node);
|
|
8
|
+
}
|
|
9
|
+
return found;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default {
|
|
13
|
+
meta: {
|
|
14
|
+
type: "problem",
|
|
15
|
+
docs: { description: "Server Actions live only in <feature>-actions.ts and their names end in Action." },
|
|
16
|
+
},
|
|
17
|
+
create(context) {
|
|
18
|
+
const named = stem(context.filename).endsWith("-actions");
|
|
19
|
+
const actions = named && /\.[cm]?ts$/.test(context.filename);
|
|
20
|
+
const inline = (node) => {
|
|
21
|
+
const found = directives(node.body?.body).find((item) => item.directive === "use server");
|
|
22
|
+
if (found)
|
|
23
|
+
context.report({
|
|
24
|
+
node: found,
|
|
25
|
+
message: "Export the action from <feature>-actions.ts instead of defining it inline.",
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
Program(program) {
|
|
30
|
+
const top = directives(program.body).find((item) => item.directive === "use server");
|
|
31
|
+
if (top && !actions)
|
|
32
|
+
context.report({
|
|
33
|
+
node: top,
|
|
34
|
+
message: "Move the action into <feature>-actions.ts, the only file with 'use server'.",
|
|
35
|
+
});
|
|
36
|
+
if (named && !actions)
|
|
37
|
+
context.report({
|
|
38
|
+
node: program,
|
|
39
|
+
message:
|
|
40
|
+
"Rename this component file so it does not end in -actions; <feature>-actions.ts holds only Server Actions.",
|
|
41
|
+
});
|
|
42
|
+
if (actions && !top)
|
|
43
|
+
context.report({ node: program, message: "Start <feature>-actions.ts with 'use server'." });
|
|
44
|
+
},
|
|
45
|
+
FunctionDeclaration: inline,
|
|
46
|
+
FunctionExpression: inline,
|
|
47
|
+
ArrowFunctionExpression: inline,
|
|
48
|
+
ExportNamedDeclaration(node) {
|
|
49
|
+
if (!actions || node.exportKind === "type" || node.declaration?.type?.startsWith("TS")) return;
|
|
50
|
+
for (const id of exportedIds(node)) {
|
|
51
|
+
const name = id.name ?? id.value;
|
|
52
|
+
if (!name.endsWith("Action")) context.report({ node: id, message: `Rename the action to ${name}Action.` });
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
ExportDefaultDeclaration(node) {
|
|
56
|
+
if (actions) context.report({ node, message: "Export the action by name, ending in Action." });
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
};
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { isTestSupport } from "./paths.mjs";
|
|
2
|
+
|
|
3
|
+
const TESTS = new Set(["test", "it"]);
|
|
4
|
+
const BLOCKS = new Set(["test", "it", "describe", "suite"]);
|
|
5
|
+
const MOCKERS = new Set(["vi", "jest"]);
|
|
6
|
+
const MOCKS = new Set(["mock", "doMock", "unstable_mockModule", "setMock", "stubGlobal", "stubEnv", "mocked"]);
|
|
7
|
+
const FAKES =
|
|
8
|
+
/^(?:mockImplementation|mockImplementationOnce|mockReturnValue|mockReturnValueOnce|mockResolvedValue|mockResolvedValueOnce|mockRejectedValue|mockRejectedValueOnce)$/;
|
|
9
|
+
const DOUBLE = "Fake HTTP with MSW handlers and other boundaries with a typed fake in *.fixture.ts.";
|
|
10
|
+
const HTTP_FAKE = "Fake HTTP with MSW handlers instead of a fetch fake.";
|
|
11
|
+
const RENDERS = new Set(["render", "renderRouter", "renderHook", "mount"]);
|
|
12
|
+
const PRESENCE = new Set(["toBeInTheDocument", "toBeTruthy", "toBeDefined", "toBeVisible", "toBeOnTheScreen"]);
|
|
13
|
+
const CALL_CHECK =
|
|
14
|
+
/^(?:toHaveBeenCalled|toBeCalled|toHaveBeenLastCalledWith|toHaveBeenNthCalledWith|lastCalledWith|nthCalledWith)/;
|
|
15
|
+
const LOOPS = new Set(["ForStatement", "ForInStatement", "ForOfStatement", "WhileStatement", "DoWhileStatement"]);
|
|
16
|
+
const FUNCTION = new Set(["FunctionExpression", "ArrowFunctionExpression"]);
|
|
17
|
+
const BEFORE_HOOKS = new Set(["beforeEach", "beforeAll"]);
|
|
18
|
+
const AFTER_HOOKS = new Set(["afterEach", "afterAll"]);
|
|
19
|
+
const FAKE_TIMERS = new Set(["useFakeTimers", "setSystemTime"]);
|
|
20
|
+
const TIMER_CALLS = new Set([...FAKE_TIMERS, "useRealTimers"]);
|
|
21
|
+
const HTTP_SERVERS = /^(?:express|(?:node:)?https?)$/;
|
|
22
|
+
const CONFIG = /^(?:vitest|vite|jest)\.config\.[cm]?[jt]s$/;
|
|
23
|
+
|
|
24
|
+
function rootName(node) {
|
|
25
|
+
let current = node;
|
|
26
|
+
while (current.type === "MemberExpression" || current.type === "CallExpression")
|
|
27
|
+
current = current.type === "CallExpression" ? current.callee : current.object;
|
|
28
|
+
return current.type === "Identifier" ? current.name : null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function isBlock(node, names) {
|
|
32
|
+
const callee = node.callee;
|
|
33
|
+
if (callee.type === "CallExpression") return isBlock(callee, names);
|
|
34
|
+
return names.has(rootName(callee) ?? "") && (callee.type === "Identifier" || callee.type === "MemberExpression");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function memberCall(node, object, properties) {
|
|
38
|
+
const callee = node.callee;
|
|
39
|
+
return (
|
|
40
|
+
callee.type === "MemberExpression" &&
|
|
41
|
+
callee.object.type === "Identifier" &&
|
|
42
|
+
object.has(callee.object.name) &&
|
|
43
|
+
properties.has(callee.property.name)
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function inLoop(node) {
|
|
48
|
+
for (let current = node.parent; current; current = current.parent) {
|
|
49
|
+
if (LOOPS.has(current.type)) return true;
|
|
50
|
+
if (
|
|
51
|
+
FUNCTION.has(current.type) &&
|
|
52
|
+
current.parent?.type === "CallExpression" &&
|
|
53
|
+
["forEach", "map", "flatMap"].includes(current.parent.callee.property?.name)
|
|
54
|
+
)
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function calledName(call) {
|
|
61
|
+
return call.callee.type === "Identifier" ? call.callee.name : null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function timerScope(node) {
|
|
65
|
+
for (let current = node.parent; current; current = current.parent) {
|
|
66
|
+
const call = current.parent;
|
|
67
|
+
if (!FUNCTION.has(current.type) || call?.type !== "CallExpression" || !call.arguments.includes(current)) continue;
|
|
68
|
+
if (AFTER_HOOKS.has(calledName(call))) return null;
|
|
69
|
+
if (BEFORE_HOOKS.has(calledName(call))) {
|
|
70
|
+
const scope = timerScope(call);
|
|
71
|
+
return scope && { container: scope.container, start: scope.container?.range[0] ?? 0 };
|
|
72
|
+
}
|
|
73
|
+
if (isBlock(call, BLOCKS)) return { container: current, start: node.range[0] };
|
|
74
|
+
}
|
|
75
|
+
return { container: null, start: node.range[0] };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function contains(outer, inner) {
|
|
79
|
+
return !outer || (outer.range[0] <= inner.range[0] && inner.range[1] <= outer.range[1]);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function strictListen(node) {
|
|
83
|
+
const options = node.arguments[0];
|
|
84
|
+
return (
|
|
85
|
+
options?.type === "ObjectExpression" &&
|
|
86
|
+
options.properties.some(
|
|
87
|
+
(item) =>
|
|
88
|
+
["onUnhandledRequest", "onUnhandledFrame"].includes(item.key?.name ?? item.key?.value) &&
|
|
89
|
+
item.value.value === "error",
|
|
90
|
+
)
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function hasTimeout(node) {
|
|
95
|
+
return (
|
|
96
|
+
node?.type === "ObjectExpression" &&
|
|
97
|
+
node.properties.some((property) => (property.key?.name ?? property.key?.value) === "timeout")
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export default {
|
|
102
|
+
meta: {
|
|
103
|
+
type: "problem",
|
|
104
|
+
docs: { description: "Tests are deterministic, assert outcomes and fake only the network, through MSW." },
|
|
105
|
+
},
|
|
106
|
+
create(context) {
|
|
107
|
+
const name = context.filename.split(/[\\/]/).at(-1);
|
|
108
|
+
if (CONFIG.test(name)) {
|
|
109
|
+
return {
|
|
110
|
+
Property(node) {
|
|
111
|
+
const key = node.key?.name ?? node.key?.value;
|
|
112
|
+
if (key === "thresholds" || key === "coverageThreshold")
|
|
113
|
+
context.report({
|
|
114
|
+
node,
|
|
115
|
+
message: "Remove the coverage threshold; keep only tests that protect a contract.",
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
if (!isTestSupport(name)) return {};
|
|
121
|
+
const fixture = /\.fixture\.[cm]?[jt]sx?$/.test(name);
|
|
122
|
+
const report = (node, message) => context.report({ node, message });
|
|
123
|
+
const bodies = new Map();
|
|
124
|
+
const clocks = [];
|
|
125
|
+
const toggles = [];
|
|
126
|
+
const faked = (node) => {
|
|
127
|
+
const before = toggles.filter((item) => item.start < node.range[0] && contains(item.container, node));
|
|
128
|
+
return (
|
|
129
|
+
before.length > 0 &&
|
|
130
|
+
before.reduce((last, item) =>
|
|
131
|
+
item.start > last.start || (item.start === last.start && item.order > last.order) ? item : last,
|
|
132
|
+
).fake
|
|
133
|
+
);
|
|
134
|
+
};
|
|
135
|
+
let msw = false;
|
|
136
|
+
const servers = new Set();
|
|
137
|
+
const bodyOf = (node) => {
|
|
138
|
+
for (let current = node.parent; current; current = current.parent)
|
|
139
|
+
if (bodies.has(current)) return bodies.get(current);
|
|
140
|
+
return null;
|
|
141
|
+
};
|
|
142
|
+
return {
|
|
143
|
+
CallExpression(node) {
|
|
144
|
+
const callee = node.callee;
|
|
145
|
+
const property = callee.type === "MemberExpression" ? callee.property.name : null;
|
|
146
|
+
if (isBlock(node, BLOCKS)) {
|
|
147
|
+
if (inLoop(node)) report(node, "Write one test.each with a table instead of a loop.");
|
|
148
|
+
const args = node.arguments;
|
|
149
|
+
if (typeof args[2]?.value === "number" || hasTimeout(args[2]) || hasTimeout(args[1]))
|
|
150
|
+
report(node, "Drop the timeout and make the test fast and deterministic.");
|
|
151
|
+
if (isBlock(node, TESTS)) {
|
|
152
|
+
const body = args.findLast((arg) => FUNCTION.has(arg.type));
|
|
153
|
+
if (body) bodies.set(body, { node, render: false, matchers: [] });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (memberCall(node, MOCKERS, TIMER_CALLS)) {
|
|
157
|
+
const scope = timerScope(node);
|
|
158
|
+
if (scope) toggles.push({ ...scope, order: node.range[0], fake: FAKE_TIMERS.has(property) });
|
|
159
|
+
}
|
|
160
|
+
if (memberCall(node, new Set(["Date", "performance"]), new Set(["now"]))) clocks.push(node);
|
|
161
|
+
if (memberCall(node, MOCKERS, MOCKS) && !(fixture && property === "stubEnv")) report(node, DOUBLE);
|
|
162
|
+
if (!fixture && memberCall(node, MOCKERS, new Set(["fn"])) && node.arguments.length > 0) report(node, DOUBLE);
|
|
163
|
+
if (!fixture && property && FAKES.test(property)) report(node, DOUBLE);
|
|
164
|
+
if (property === "defineProperty" && rootName(callee) === "Object") report(node, DOUBLE);
|
|
165
|
+
if (
|
|
166
|
+
property === "listen" &&
|
|
167
|
+
msw &&
|
|
168
|
+
typeof node.arguments[0]?.value !== "number" &&
|
|
169
|
+
!servers.has(rootName(callee.object)) &&
|
|
170
|
+
!strictListen(node)
|
|
171
|
+
)
|
|
172
|
+
report(
|
|
173
|
+
node,
|
|
174
|
+
'Start the MSW server with listen({ onUnhandledRequest: "error" }) (onUnhandledFrame in MSW 3).',
|
|
175
|
+
);
|
|
176
|
+
const body = bodyOf(node);
|
|
177
|
+
if (!body) return;
|
|
178
|
+
if (callee.type === "Identifier" && RENDERS.has(callee.name)) body.render = true;
|
|
179
|
+
if (property?.startsWith("to") && rootName(callee) === "expect") body.matchers.push(property);
|
|
180
|
+
},
|
|
181
|
+
Property(node) {
|
|
182
|
+
if (fixture && (node.key?.name ?? node.key?.value) === "fetch") report(node, HTTP_FAKE);
|
|
183
|
+
},
|
|
184
|
+
ImportDeclaration(node) {
|
|
185
|
+
if (/^msw(?:\/|$)/.test(node.source.value)) msw = true;
|
|
186
|
+
if (HTTP_SERVERS.test(node.source.value))
|
|
187
|
+
for (const specifier of node.specifiers) servers.add(specifier.local.name);
|
|
188
|
+
},
|
|
189
|
+
VariableDeclarator(node) {
|
|
190
|
+
if (node.id.type === "Identifier" && node.init && servers.has(rootName(node.init))) servers.add(node.id.name);
|
|
191
|
+
},
|
|
192
|
+
AssignmentExpression(node) {
|
|
193
|
+
const target = node.left;
|
|
194
|
+
if (target.type !== "MemberExpression") return;
|
|
195
|
+
const text = context.sourceCode.getText(target);
|
|
196
|
+
if (fixture && node.operator === "??=" && /^(?:globalThis|window|self)\.\w+$/.test(text)) return;
|
|
197
|
+
if (/(?:^|\.)prototype\./.test(text) || /^(?:globalThis|window|global|self)\./.test(text)) report(node, DOUBLE);
|
|
198
|
+
},
|
|
199
|
+
NewExpression(node) {
|
|
200
|
+
if (node.callee.type === "Identifier" && node.callee.name === "Date" && node.arguments.length === 0)
|
|
201
|
+
clocks.push(node);
|
|
202
|
+
},
|
|
203
|
+
WhileStatement(node) {
|
|
204
|
+
report(node, "Await the real event instead of looping.");
|
|
205
|
+
},
|
|
206
|
+
DoWhileStatement(node) {
|
|
207
|
+
report(node, "Await the real event instead of looping.");
|
|
208
|
+
},
|
|
209
|
+
"Program:exit"() {
|
|
210
|
+
for (const node of clocks)
|
|
211
|
+
if (!faked(node))
|
|
212
|
+
report(node, "Call vi.useFakeTimers() and vi.setSystemTime() instead of reading the real clock.");
|
|
213
|
+
for (const { node, render, matchers } of bodies.values()) {
|
|
214
|
+
if (render && matchers.every((matcher) => PRESENCE.has(matcher)))
|
|
215
|
+
report(node, "Assert behavior after an interaction, or delete the render-only test.");
|
|
216
|
+
else if (matchers.length > 0 && matchers.every((matcher) => CALL_CHECK.test(matcher)))
|
|
217
|
+
report(node, "Assert the outcome the user or caller sees, not only that a function was called.");
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
},
|
|
222
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"strict": true,
|
|
5
|
+
"noUncheckedIndexedAccess": true,
|
|
6
|
+
"exactOptionalPropertyTypes": true,
|
|
7
|
+
"noImplicitOverride": true,
|
|
8
|
+
"noImplicitReturns": true,
|
|
9
|
+
"noFallthroughCasesInSwitch": true,
|
|
10
|
+
"verbatimModuleSyntax": true,
|
|
11
|
+
"isolatedModules": true,
|
|
12
|
+
"erasableSyntaxOnly": true,
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"module": "preserve",
|
|
16
|
+
"moduleResolution": "bundler",
|
|
17
|
+
"target": "es2024",
|
|
18
|
+
"lib": ["es2024"],
|
|
19
|
+
"jsx": "react-jsx",
|
|
20
|
+
"noEmit": true,
|
|
21
|
+
"allowImportingTsExtensions": true
|
|
22
|
+
}
|
|
23
|
+
}
|