vite-doctor 0.0.2 → 0.0.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/dist/cli.mjs +2 -2
- package/dist/{core-DXS10waH.mjs → core-WTY_jAiL.mjs} +204 -20
- package/dist/{doctor-D_fAijfx.mjs → doctor-DfkqNcNR.mjs} +7 -7
- package/dist/{index-oT29pHXX.d.mts → index-CFlFH8Pi.d.mts} +4 -1
- package/dist/index.mjs +1 -1
- package/dist/nitro-D2XxIgEp.mjs +2 -0
- package/dist/{plugin-QYmdGYMa.mjs → plugin-7rCuA-AZ.mjs} +2 -2
- package/dist/plugin.mjs +1 -1
- package/dist/rule-packs/nitro/index.d.mts +2 -2
- package/dist/rule-packs/nitro/index.mjs +3 -3
- package/dist/rule-packs/nitro/rules.d.mts +2 -2
- package/dist/rule-packs/nitro/rules.mjs +2 -2
- package/dist/rule-packs/nuxt/rules/index.d.mts +1 -1
- package/dist/rule-packs/nuxt/rules/index.mjs +2 -2
- package/dist/rule-packs/vite/index.mjs +1 -1
- package/dist/rule-packs/vite/rules/index.mjs +1 -1
- package/dist/rule-packs/vue/index.mjs +1 -1
- package/dist/rule-packs/vue/rules.mjs +1 -1
- package/dist/{rules-Ci1PkZG_.mjs → rules-BDMsIiOi.mjs} +205 -14
- package/dist/rules-BGjZej-N.mjs +2 -0
- package/dist/{rules-CpZKSMoL.mjs → rules-DBiaAWeX.mjs} +20 -10
- package/dist/{rules-Wl3xtW3p.mjs → rules-M6yUv7EP.mjs} +18 -13
- package/dist/{rules-TJ8mVfH6.mjs → rules-cyFhFs4w.mjs} +1 -1
- package/dist/rules.mjs +2 -2
- package/package.json +2 -2
- package/dist/nitro-CFxa1y5r.mjs +0 -2
- package/dist/rules-8_T4dDGE.mjs +0 -2
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import { i as viteDoctorVersion, n as shouldFailDoctorRun, r as viteDoctorRulePacks, t as runViteDoctor } from "./doctor-
|
|
2
|
+
import { c as cleanCache, i as explainRule, n as createReport, r as createRulesReport } from "./core-WTY_jAiL.mjs";
|
|
3
|
+
import { i as viteDoctorVersion, n as shouldFailDoctorRun, r as viteDoctorRulePacks, t as runViteDoctor } from "./doctor-DfkqNcNR.mjs";
|
|
4
4
|
import { resolve } from "pathe";
|
|
5
5
|
import { realpathSync, statSync } from "node:fs";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
@@ -4,11 +4,11 @@ import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, wri
|
|
|
4
4
|
import { createHash } from "node:crypto";
|
|
5
5
|
import * as oxcParser from "oxc-parser";
|
|
6
6
|
import { parseSync } from "oxc-parser";
|
|
7
|
+
import { defineDiagnostics, formatDiagnostic } from "nostics";
|
|
7
8
|
import { glob } from "node:fs/promises";
|
|
8
9
|
import { execFile } from "node:child_process";
|
|
9
10
|
import { matchesGlob } from "node:path";
|
|
10
11
|
import MagicString from "magic-string";
|
|
11
|
-
import { defineDiagnostics, formatDiagnostic } from "nostics";
|
|
12
12
|
import pc from "picocolors";
|
|
13
13
|
//#region src/core/internal/script.ts
|
|
14
14
|
function parseScript(file, source, lang = langFromFile(file)) {
|
|
@@ -121,13 +121,59 @@ function sha256$1(input) {
|
|
|
121
121
|
return createHash("sha256").update(input).digest("hex");
|
|
122
122
|
}
|
|
123
123
|
//#endregion
|
|
124
|
-
//#region src/core/
|
|
124
|
+
//#region src/core/internal-diagnostic-handles.ts
|
|
125
|
+
const doctorInternalDiagnostics = defineDiagnostics({ codes: {
|
|
126
|
+
DOC0012: {
|
|
127
|
+
why: (params) => `Duplicate Doctor diagnostic code "${params.code}".`,
|
|
128
|
+
fix: (params) => `Assign a unique Diagnostic Code instead of registering "${params.code}" twice.`
|
|
129
|
+
},
|
|
130
|
+
DOC0013: {
|
|
131
|
+
why: (params) => params.code ? `No Doctor diagnostic handle is registered for rule "${params.ruleId}" and code "${params.code}".` : `No Doctor diagnostic code is registered for rule "${params.ruleId}".`,
|
|
132
|
+
fix: "Register a Diagnostic Code for the rule before it can report diagnostics."
|
|
133
|
+
},
|
|
134
|
+
DOC0014: {
|
|
135
|
+
why: (params) => `Rule "${params.ruleId}" reported a diagnostic without a nostics name/code.`,
|
|
136
|
+
fix: "Report diagnostics through a registered Doctor nostics handle."
|
|
137
|
+
},
|
|
138
|
+
DOC0015: {
|
|
139
|
+
why: (params) => `Rule pack "${params.pack}" must define a non-empty recommended preset.`,
|
|
140
|
+
fix: "Add at least one rule ID to the rule pack recommended preset."
|
|
141
|
+
},
|
|
142
|
+
DOC0016: {
|
|
143
|
+
why: (params) => `Invalid Config Extends entry "${params.entry}". Use "pack/preset".`,
|
|
144
|
+
fix: "Use a rule-pack-qualified preset such as \"vite-doctor/vue/recommended\"."
|
|
145
|
+
},
|
|
146
|
+
DOC0017: {
|
|
147
|
+
why: (params) => `Unknown Rule Pack "${params.pack}" in Config Extends entry "${params.entry}".`,
|
|
148
|
+
fix: "Use an installed Rule Pack name or remove the Config Extends entry."
|
|
149
|
+
},
|
|
150
|
+
DOC0018: {
|
|
151
|
+
why: (params) => `Unknown Preset "${params.preset}" for Rule Pack "${params.pack}" in Config Extends entry "${params.entry}".`,
|
|
152
|
+
fix: "Use a Preset exposed by the selected Rule Pack."
|
|
153
|
+
},
|
|
154
|
+
DOC0019: {
|
|
155
|
+
why: (params) => `Invalid severity for rule "${params.ruleId}": ${params.severity}.`,
|
|
156
|
+
fix: "Use \"blocker\", \"error\", \"warn\", \"info\", or \"off\"."
|
|
157
|
+
},
|
|
158
|
+
DOC0020: {
|
|
159
|
+
why: (params) => `Invalid config for rule "${params.ruleId}".`,
|
|
160
|
+
fix: "Use \"off\", a severity string, or a [severity, options] tuple."
|
|
161
|
+
},
|
|
162
|
+
DOC0021: {
|
|
163
|
+
why: (params) => params.code ? `Diagnostic "${params.code}" for rule "${params.ruleId}" is missing a fix.` : `Rule "${params.ruleId}" reported a diagnostic without a fix.`,
|
|
164
|
+
fix: "Provide actionable nostics fix text for every Doctor diagnostic."
|
|
165
|
+
}
|
|
166
|
+
} });
|
|
167
|
+
//#endregion
|
|
168
|
+
//#region src/core/diagnostic-constants.ts
|
|
125
169
|
const DOCTOR_DIAGNOSTICS_DOCS_BASE = "https://vite-doctor.onmax.me/diagnostics";
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/core/primitives.ts
|
|
126
172
|
function createRule(rule) {
|
|
127
173
|
return rule;
|
|
128
174
|
}
|
|
129
175
|
function defineRulePack(pack) {
|
|
130
|
-
if (!pack.presets?.recommended?.length) throw
|
|
176
|
+
if (!pack.presets?.recommended?.length) throw doctorInternalDiagnostics.DOC0015({ pack: pack.name });
|
|
131
177
|
return pack;
|
|
132
178
|
}
|
|
133
179
|
function defineDoctorExtension(extension) {
|
|
@@ -1022,13 +1068,20 @@ function resolveExtends(packs, options, project) {
|
|
|
1022
1068
|
const selected = /* @__PURE__ */ new Set();
|
|
1023
1069
|
for (const entry of requested) {
|
|
1024
1070
|
const slash = entry.lastIndexOf("/");
|
|
1025
|
-
if (slash === -1) throw
|
|
1071
|
+
if (slash === -1) throw doctorInternalDiagnostics.DOC0016({ entry });
|
|
1026
1072
|
const packKey = entry.slice(0, slash);
|
|
1027
1073
|
const presetName = entry.slice(slash + 1);
|
|
1028
1074
|
const pack = packs.find((item) => rulePackKey(item) === packKey || item.name === packKey);
|
|
1029
|
-
if (!pack) throw
|
|
1075
|
+
if (!pack) throw doctorInternalDiagnostics.DOC0017({
|
|
1076
|
+
entry,
|
|
1077
|
+
pack: packKey
|
|
1078
|
+
});
|
|
1030
1079
|
const preset = pack.presets[presetName];
|
|
1031
|
-
if (!preset) throw
|
|
1080
|
+
if (!preset) throw doctorInternalDiagnostics.DOC0018({
|
|
1081
|
+
entry,
|
|
1082
|
+
pack: pack.name,
|
|
1083
|
+
preset: presetName
|
|
1084
|
+
});
|
|
1032
1085
|
for (const ruleId of preset) selected.add(ruleId);
|
|
1033
1086
|
}
|
|
1034
1087
|
return selected;
|
|
@@ -1052,7 +1105,10 @@ function resolveRuleConfigs(config) {
|
|
|
1052
1105
|
}
|
|
1053
1106
|
if (Array.isArray(value)) {
|
|
1054
1107
|
const [severity, options] = value;
|
|
1055
|
-
if (!isSeverity(severity)) throw
|
|
1108
|
+
if (!isSeverity(severity)) throw doctorInternalDiagnostics.DOC0019({
|
|
1109
|
+
ruleId,
|
|
1110
|
+
severity: String(severity)
|
|
1111
|
+
});
|
|
1056
1112
|
resolved.set(ruleId, {
|
|
1057
1113
|
enabled: true,
|
|
1058
1114
|
severity,
|
|
@@ -1060,7 +1116,7 @@ function resolveRuleConfigs(config) {
|
|
|
1060
1116
|
});
|
|
1061
1117
|
continue;
|
|
1062
1118
|
}
|
|
1063
|
-
throw
|
|
1119
|
+
throw doctorInternalDiagnostics.DOC0020({ ruleId });
|
|
1064
1120
|
}
|
|
1065
1121
|
return resolved;
|
|
1066
1122
|
}
|
|
@@ -1523,7 +1579,7 @@ function createDoctorDiagnosticsHost() {
|
|
|
1523
1579
|
defineDiagnostics: defineDoctorDiagnostics,
|
|
1524
1580
|
register(registry) {
|
|
1525
1581
|
for (const [code, handle] of Object.entries(registry.diagnostics)) {
|
|
1526
|
-
if (logger[code]) throw
|
|
1582
|
+
if (logger[code]) throw doctorInternalDiagnostics.DOC0012({ code });
|
|
1527
1583
|
logger[code] = handle;
|
|
1528
1584
|
}
|
|
1529
1585
|
},
|
|
@@ -1531,6 +1587,12 @@ function createDoctorDiagnosticsHost() {
|
|
|
1531
1587
|
};
|
|
1532
1588
|
}
|
|
1533
1589
|
const doctorDiagnosticsHost = createDoctorDiagnosticsHost();
|
|
1590
|
+
function codeForRuleId(codesByRuleId, ruleId) {
|
|
1591
|
+
return codesByRuleId[ruleId];
|
|
1592
|
+
}
|
|
1593
|
+
function diagnosticForCode(diagnostics, code) {
|
|
1594
|
+
return code ? diagnostics[code] : void 0;
|
|
1595
|
+
}
|
|
1534
1596
|
function defineDoctorDiagnostics(entries) {
|
|
1535
1597
|
const codes = Object.fromEntries(entries.map((entry) => [entry.code, {
|
|
1536
1598
|
why: (params) => params.why,
|
|
@@ -1596,6 +1658,56 @@ const allDoctorDiagnosticRegistry = defineDoctorDiagnostics([
|
|
|
1596
1658
|
code: "DOC0011",
|
|
1597
1659
|
ruleId: "workspace/health/high-fan-out"
|
|
1598
1660
|
},
|
|
1661
|
+
{
|
|
1662
|
+
code: "DOC0012",
|
|
1663
|
+
ruleId: "doctor/internal/duplicate-diagnostic-code",
|
|
1664
|
+
docs: false
|
|
1665
|
+
},
|
|
1666
|
+
{
|
|
1667
|
+
code: "DOC0013",
|
|
1668
|
+
ruleId: "doctor/internal/missing-diagnostic-code",
|
|
1669
|
+
docs: false
|
|
1670
|
+
},
|
|
1671
|
+
{
|
|
1672
|
+
code: "DOC0014",
|
|
1673
|
+
ruleId: "doctor/internal/missing-diagnostic-name",
|
|
1674
|
+
docs: false
|
|
1675
|
+
},
|
|
1676
|
+
{
|
|
1677
|
+
code: "DOC0015",
|
|
1678
|
+
ruleId: "doctor/rule-pack/missing-recommended-preset",
|
|
1679
|
+
docs: false
|
|
1680
|
+
},
|
|
1681
|
+
{
|
|
1682
|
+
code: "DOC0016",
|
|
1683
|
+
ruleId: "doctor/config/invalid-extends-entry",
|
|
1684
|
+
docs: false
|
|
1685
|
+
},
|
|
1686
|
+
{
|
|
1687
|
+
code: "DOC0017",
|
|
1688
|
+
ruleId: "doctor/config/unknown-rule-pack",
|
|
1689
|
+
docs: false
|
|
1690
|
+
},
|
|
1691
|
+
{
|
|
1692
|
+
code: "DOC0018",
|
|
1693
|
+
ruleId: "doctor/config/unknown-preset",
|
|
1694
|
+
docs: false
|
|
1695
|
+
},
|
|
1696
|
+
{
|
|
1697
|
+
code: "DOC0019",
|
|
1698
|
+
ruleId: "doctor/config/invalid-rule-severity",
|
|
1699
|
+
docs: false
|
|
1700
|
+
},
|
|
1701
|
+
{
|
|
1702
|
+
code: "DOC0020",
|
|
1703
|
+
ruleId: "doctor/config/invalid-rule-config",
|
|
1704
|
+
docs: false
|
|
1705
|
+
},
|
|
1706
|
+
{
|
|
1707
|
+
code: "DOC0021",
|
|
1708
|
+
ruleId: "doctor/internal/missing-diagnostic-fix",
|
|
1709
|
+
docs: false
|
|
1710
|
+
},
|
|
1599
1711
|
{
|
|
1600
1712
|
code: "VUE0001",
|
|
1601
1713
|
ruleId: "vue/i18n/no-untranslated-text"
|
|
@@ -1824,6 +1936,10 @@ const allDoctorDiagnosticRegistry = defineDoctorDiagnostics([
|
|
|
1824
1936
|
code: "NITRO0011",
|
|
1825
1937
|
ruleId: "nitro/server/prefer-event-fetch"
|
|
1826
1938
|
},
|
|
1939
|
+
{
|
|
1940
|
+
code: "NITRO0012",
|
|
1941
|
+
ruleId: "nitro/request/prefer-route-method-suffix"
|
|
1942
|
+
},
|
|
1827
1943
|
{
|
|
1828
1944
|
code: "NUXT0001",
|
|
1829
1945
|
ruleId: "docus/appconfig/no-unknown-key"
|
|
@@ -2115,7 +2231,7 @@ const allDoctorDiagnosticRegistry = defineDoctorDiagnostics([
|
|
|
2115
2231
|
]);
|
|
2116
2232
|
const allDiagnosticCodesByRuleId = allDoctorDiagnosticRegistry.codesByRuleId;
|
|
2117
2233
|
doctorDiagnosticsHost.register(allDoctorDiagnosticRegistry);
|
|
2118
|
-
const allDiagnostics =
|
|
2234
|
+
const allDiagnostics = allDoctorDiagnosticRegistry.diagnostics;
|
|
2119
2235
|
//#endregion
|
|
2120
2236
|
//#region src/core/internal/diagnostics.ts
|
|
2121
2237
|
function applyRequestedFixes(session) {
|
|
@@ -2197,7 +2313,11 @@ function createDiagnosticFingerprint(root, diagnostic, file) {
|
|
|
2197
2313
|
function normalizeDiagnostic(input) {
|
|
2198
2314
|
const diagnostic = input.diagnostic;
|
|
2199
2315
|
const code = diagnostic.name;
|
|
2200
|
-
if (!code) throw
|
|
2316
|
+
if (!code) throw doctorInternalDiagnostics.DOC0014({ ruleId: input.ruleId });
|
|
2317
|
+
if (!diagnostic.fix) throw doctorInternalDiagnostics.DOC0021({
|
|
2318
|
+
ruleId: input.ruleId,
|
|
2319
|
+
code
|
|
2320
|
+
});
|
|
2201
2321
|
return {
|
|
2202
2322
|
...input,
|
|
2203
2323
|
diagnostic,
|
|
@@ -2210,15 +2330,22 @@ function normalizeDiagnostic(input) {
|
|
|
2210
2330
|
};
|
|
2211
2331
|
}
|
|
2212
2332
|
function normalizeDiagnosticFromRuleCode(input) {
|
|
2213
|
-
const code = input.code ?? allDiagnosticCodesByRuleId
|
|
2333
|
+
const code = input.code ?? codeForRuleId(allDiagnosticCodesByRuleId, input.ruleId) ?? "DOC9999";
|
|
2214
2334
|
const why = input.why ?? input.message ?? input.diagnostic?.why ?? "Doctor diagnostic";
|
|
2215
|
-
const fix = input.suggestion ?? input.diagnostic?.fix ?? input.fix?.message
|
|
2216
|
-
|
|
2335
|
+
const fix = input.suggestion ?? input.diagnostic?.fix ?? input.fix?.message;
|
|
2336
|
+
if (!fix) throw doctorInternalDiagnostics.DOC0021({
|
|
2337
|
+
ruleId: input.ruleId,
|
|
2338
|
+
code
|
|
2339
|
+
});
|
|
2340
|
+
const diagnostic = input.diagnostic ?? diagnosticForCode(allDiagnostics, code)?.({
|
|
2217
2341
|
why,
|
|
2218
2342
|
fix,
|
|
2219
2343
|
sources: input.sources
|
|
2220
2344
|
});
|
|
2221
|
-
if (!diagnostic) throw
|
|
2345
|
+
if (!diagnostic) throw doctorInternalDiagnostics.DOC0013({
|
|
2346
|
+
ruleId: input.ruleId,
|
|
2347
|
+
code
|
|
2348
|
+
});
|
|
2222
2349
|
return {
|
|
2223
2350
|
...input,
|
|
2224
2351
|
diagnostic,
|
|
@@ -2491,6 +2618,7 @@ function runDeadCodeRules(session, graph) {
|
|
|
2491
2618
|
severity: "error",
|
|
2492
2619
|
category: "dead-code",
|
|
2493
2620
|
message: `Import "${item.source}" could not be resolved.`,
|
|
2621
|
+
suggestion: "Fix the import specifier or add the missing source file.",
|
|
2494
2622
|
file: fact.path,
|
|
2495
2623
|
range: item.range,
|
|
2496
2624
|
confidence: "proven",
|
|
@@ -2507,6 +2635,7 @@ function runDeadCodeRules(session, graph) {
|
|
|
2507
2635
|
severity: "info",
|
|
2508
2636
|
category: "dead-code",
|
|
2509
2637
|
message: "File is not reachable from known package, framework, or manifest roots.",
|
|
2638
|
+
suggestion: "Remove the file or import it from a package, framework, or manifest root.",
|
|
2510
2639
|
file: fact.path,
|
|
2511
2640
|
confidence: "manifest-backed",
|
|
2512
2641
|
evidence: [{
|
|
@@ -2522,6 +2651,7 @@ function runDeadCodeRules(session, graph) {
|
|
|
2522
2651
|
severity: "info",
|
|
2523
2652
|
category: "dead-code",
|
|
2524
2653
|
message: `Export "${exp.name}" is not referenced by known imports or framework roots.`,
|
|
2654
|
+
suggestion: `Remove export "${exp.name}" or import it from reachable code.`,
|
|
2525
2655
|
file: fact.path,
|
|
2526
2656
|
range: exp.range,
|
|
2527
2657
|
confidence: exp.kind === "type" ? "type-backed" : "proven",
|
|
@@ -2538,6 +2668,7 @@ function runDeadCodeRules(session, graph) {
|
|
|
2538
2668
|
severity: "info",
|
|
2539
2669
|
category: "dead-code",
|
|
2540
2670
|
message: `Dependency "${dep}" is declared but was not imported by scanned source files.`,
|
|
2671
|
+
suggestion: `Remove "${dep}" from package.json or import it from scanned source code.`,
|
|
2541
2672
|
file: resolve(session.root, "package.json"),
|
|
2542
2673
|
confidence: "heuristic-medium",
|
|
2543
2674
|
evidence: [{
|
|
@@ -2551,6 +2682,7 @@ function runDeadCodeRules(session, graph) {
|
|
|
2551
2682
|
severity: "warn",
|
|
2552
2683
|
category: "dead-code",
|
|
2553
2684
|
message: `Package "${dep}" is imported but is not listed in package.json dependencies.`,
|
|
2685
|
+
suggestion: `Add "${dep}" to package.json dependencies or remove the import.`,
|
|
2554
2686
|
file: resolve(session.root, "package.json"),
|
|
2555
2687
|
confidence: "proven",
|
|
2556
2688
|
evidence: [{
|
|
@@ -2568,6 +2700,7 @@ function runCycleAndDuplicateExportRules(session, graph) {
|
|
|
2568
2700
|
severity: "warn",
|
|
2569
2701
|
category: "architecture",
|
|
2570
2702
|
message: `Circular dependency detected across ${files.length} files.`,
|
|
2703
|
+
suggestion: "Break the cycle by moving shared code into an acyclic module.",
|
|
2571
2704
|
file: files[0],
|
|
2572
2705
|
related: files.slice(1).map((file) => ({
|
|
2573
2706
|
file,
|
|
@@ -2589,6 +2722,7 @@ function runCycleAndDuplicateExportRules(session, graph) {
|
|
|
2589
2722
|
severity: "warn",
|
|
2590
2723
|
category: "architecture",
|
|
2591
2724
|
message: `Export name "${name}" appears in multiple files.`,
|
|
2725
|
+
suggestion: `Rename or consolidate duplicate export "${name}" so imports resolve unambiguously.`,
|
|
2592
2726
|
file: files[0],
|
|
2593
2727
|
related: files.slice(1).map((file) => ({
|
|
2594
2728
|
file,
|
|
@@ -2619,6 +2753,7 @@ function runDuplicationRules(session) {
|
|
|
2619
2753
|
severity: "info",
|
|
2620
2754
|
category: "duplication",
|
|
2621
2755
|
message: `Repeated token window detected in ${files.length} files.`,
|
|
2756
|
+
suggestion: "Extract the repeated code into a shared helper or keep one intentional copy.",
|
|
2622
2757
|
file: files[0],
|
|
2623
2758
|
related: files.slice(1).map((file) => ({
|
|
2624
2759
|
file,
|
|
@@ -2641,6 +2776,7 @@ function runHealthRules(session) {
|
|
|
2641
2776
|
severity: "warn",
|
|
2642
2777
|
category: "health",
|
|
2643
2778
|
message: `File has cyclomatic complexity ${fact.complexity.cyclomatic}.`,
|
|
2779
|
+
suggestion: "Split complex branches into smaller rules, helpers, or modules.",
|
|
2644
2780
|
file: fact.path,
|
|
2645
2781
|
confidence: "heuristic-high",
|
|
2646
2782
|
evidence: [{
|
|
@@ -2654,6 +2790,7 @@ function runHealthRules(session) {
|
|
|
2654
2790
|
severity: "info",
|
|
2655
2791
|
category: "health",
|
|
2656
2792
|
message: `File imports ${fact.imports.length} modules.`,
|
|
2793
|
+
suggestion: "Reduce fan-out by moving cohesive dependencies behind smaller modules.",
|
|
2657
2794
|
file: fact.path,
|
|
2658
2795
|
confidence: "heuristic-high",
|
|
2659
2796
|
evidence: [{
|
|
@@ -2918,9 +3055,6 @@ function createRuleContext(session, initialFile, rule, phase = "file") {
|
|
|
2918
3055
|
file = nextFile;
|
|
2919
3056
|
},
|
|
2920
3057
|
report(diagnostic, metadata) {
|
|
2921
|
-
const sources = diagnostic.sources ? [...diagnostic.sources] : rule.meta.docsUrl ? [rule.meta.docsUrl] : void 0;
|
|
2922
|
-
if (rule.meta.docsUrl && sources && !sources.includes(rule.meta.docsUrl)) sources.push(rule.meta.docsUrl);
|
|
2923
|
-
if (sources?.length) diagnostic.sources = sources;
|
|
2924
3058
|
const input = normalizeDiagnostic({
|
|
2925
3059
|
...metadata,
|
|
2926
3060
|
diagnostic,
|
|
@@ -3046,6 +3180,56 @@ const coreDiagnosticRegistry = defineDoctorDiagnostics([
|
|
|
3046
3180
|
{
|
|
3047
3181
|
code: "DOC0011",
|
|
3048
3182
|
ruleId: "workspace/health/high-fan-out"
|
|
3183
|
+
},
|
|
3184
|
+
{
|
|
3185
|
+
code: "DOC0012",
|
|
3186
|
+
ruleId: "doctor/internal/duplicate-diagnostic-code",
|
|
3187
|
+
docs: false
|
|
3188
|
+
},
|
|
3189
|
+
{
|
|
3190
|
+
code: "DOC0013",
|
|
3191
|
+
ruleId: "doctor/internal/missing-diagnostic-code",
|
|
3192
|
+
docs: false
|
|
3193
|
+
},
|
|
3194
|
+
{
|
|
3195
|
+
code: "DOC0014",
|
|
3196
|
+
ruleId: "doctor/internal/missing-diagnostic-name",
|
|
3197
|
+
docs: false
|
|
3198
|
+
},
|
|
3199
|
+
{
|
|
3200
|
+
code: "DOC0015",
|
|
3201
|
+
ruleId: "doctor/rule-pack/missing-recommended-preset",
|
|
3202
|
+
docs: false
|
|
3203
|
+
},
|
|
3204
|
+
{
|
|
3205
|
+
code: "DOC0016",
|
|
3206
|
+
ruleId: "doctor/config/invalid-extends-entry",
|
|
3207
|
+
docs: false
|
|
3208
|
+
},
|
|
3209
|
+
{
|
|
3210
|
+
code: "DOC0017",
|
|
3211
|
+
ruleId: "doctor/config/unknown-rule-pack",
|
|
3212
|
+
docs: false
|
|
3213
|
+
},
|
|
3214
|
+
{
|
|
3215
|
+
code: "DOC0018",
|
|
3216
|
+
ruleId: "doctor/config/unknown-preset",
|
|
3217
|
+
docs: false
|
|
3218
|
+
},
|
|
3219
|
+
{
|
|
3220
|
+
code: "DOC0019",
|
|
3221
|
+
ruleId: "doctor/config/invalid-rule-severity",
|
|
3222
|
+
docs: false
|
|
3223
|
+
},
|
|
3224
|
+
{
|
|
3225
|
+
code: "DOC0020",
|
|
3226
|
+
ruleId: "doctor/config/invalid-rule-config",
|
|
3227
|
+
docs: false
|
|
3228
|
+
},
|
|
3229
|
+
{
|
|
3230
|
+
code: "DOC0021",
|
|
3231
|
+
ruleId: "doctor/internal/missing-diagnostic-fix",
|
|
3232
|
+
docs: false
|
|
3049
3233
|
}
|
|
3050
3234
|
]);
|
|
3051
3235
|
coreDiagnosticRegistry.diagnostics;
|
|
@@ -3247,7 +3431,7 @@ function labelSeverity(severity) {
|
|
|
3247
3431
|
return severity === "blocker" ? "Blockers" : severity === "error" ? "Errors" : severity === "warn" ? "Warnings" : "Info";
|
|
3248
3432
|
}
|
|
3249
3433
|
function codeListForRule(ruleId) {
|
|
3250
|
-
const code = allDiagnosticCodesByRuleId
|
|
3434
|
+
const code = codeForRuleId(allDiagnosticCodesByRuleId, ruleId);
|
|
3251
3435
|
return code ? [code] : [];
|
|
3252
3436
|
}
|
|
3253
3437
|
function indent(value, prefix) {
|
|
@@ -3301,4 +3485,4 @@ async function runDoctor(options = {}) {
|
|
|
3301
3485
|
return result;
|
|
3302
3486
|
}
|
|
3303
3487
|
//#endregion
|
|
3304
|
-
export {
|
|
3488
|
+
export { codeForRuleId as a, cleanCache as c, defineRulePack as d, doctorInternalDiagnostics as f, explainRule as i, createRule as l, createReport as n, defineDoctorDiagnostics as o, createRulesReport as r, diagnosticForCode as s, runDoctor as t, defineDoctorExtension as u };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as nitroRulePack } from "./rules-
|
|
3
|
-
import "./nitro-
|
|
4
|
-
import { t as vueRulePack } from "./rules-
|
|
5
|
-
import { n as nuxtRulePacks, t as nuxtDoctorExtensions } from "./rules-
|
|
6
|
-
import { t as viteRulePack } from "./rules-
|
|
7
|
-
import "./rules-
|
|
1
|
+
import { t as runDoctor, u as defineDoctorExtension } from "./core-WTY_jAiL.mjs";
|
|
2
|
+
import { t as nitroRulePack } from "./rules-BDMsIiOi.mjs";
|
|
3
|
+
import "./nitro-D2XxIgEp.mjs";
|
|
4
|
+
import { t as vueRulePack } from "./rules-DBiaAWeX.mjs";
|
|
5
|
+
import { n as nuxtRulePacks, t as nuxtDoctorExtensions } from "./rules-M6yUv7EP.mjs";
|
|
6
|
+
import { t as viteRulePack } from "./rules-cyFhFs4w.mjs";
|
|
7
|
+
import "./rules-BGjZej-N.mjs";
|
|
8
8
|
import { join } from "pathe";
|
|
9
9
|
import { existsSync, readFileSync } from "node:fs";
|
|
10
10
|
//#region src/version.ts
|
|
@@ -30,10 +30,13 @@ declare const preferValidatedRouterParams: DoctorRule;
|
|
|
30
30
|
//#region src/rule-packs/nitro/rules/prefer-assert-method.d.ts
|
|
31
31
|
declare const preferAssertMethod: DoctorRule;
|
|
32
32
|
//#endregion
|
|
33
|
+
//#region src/rule-packs/nitro/rules/prefer-route-method-suffix.d.ts
|
|
34
|
+
declare const preferRouteMethodSuffix: DoctorRule;
|
|
35
|
+
//#endregion
|
|
33
36
|
//#region src/rule-packs/nitro/rules/prefer-get-request-ip.d.ts
|
|
34
37
|
declare const preferGetRequestIp: DoctorRule;
|
|
35
38
|
//#endregion
|
|
36
39
|
//#region src/rule-packs/nitro/rules/index.d.ts
|
|
37
40
|
declare const nitroRulePack: RulePack;
|
|
38
41
|
//#endregion
|
|
39
|
-
export {
|
|
42
|
+
export { preferValidatedRouterParams as a, noBrowserApiInServer as c, preferEventFetch as d, noNavigateToInNitro as f, preferAssertMethod as i, noClientComposablesInServer as l, preferGetRequestIp as n, preferValidatedQuery as o, noUseNuxtAppInNitro as p, preferRouteMethodSuffix as r, preferValidatedBody as s, nitroRulePack as t, requireEventRuntimeConfigInServer as u };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as shouldFailDoctorRun, t as runViteDoctor } from "./doctor-
|
|
1
|
+
import { n as createReport, u as defineDoctorExtension } from "./core-WTY_jAiL.mjs";
|
|
2
|
+
import { n as shouldFailDoctorRun, t as runViteDoctor } from "./doctor-DfkqNcNR.mjs";
|
|
3
3
|
import { resolve } from "pathe";
|
|
4
4
|
//#region src/plugin.ts
|
|
5
5
|
function doctor(options = {}) {
|
package/dist/plugin.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as doctor } from "./plugin-
|
|
1
|
+
import { t as doctor } from "./plugin-7rCuA-AZ.mjs";
|
|
2
2
|
export { doctor };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { nitroRulePack, noBrowserApiInServer, noClientComposablesInServer, noNavigateToInNitro, noUseNuxtAppInNitro, preferAssertMethod, preferEventFetch, preferGetRequestIp, preferValidatedBody, preferValidatedQuery, preferValidatedRouterParams, requireEventRuntimeConfigInServer };
|
|
1
|
+
import { a as preferValidatedRouterParams, c as noBrowserApiInServer, d as preferEventFetch, f as noNavigateToInNitro, i as preferAssertMethod, l as noClientComposablesInServer, n as preferGetRequestIp, o as preferValidatedQuery, p as noUseNuxtAppInNitro, r as preferRouteMethodSuffix, s as preferValidatedBody, t as nitroRulePack, u as requireEventRuntimeConfigInServer } from "../../index-CFlFH8Pi.mjs";
|
|
2
|
+
export { nitroRulePack, noBrowserApiInServer, noClientComposablesInServer, noNavigateToInNitro, noUseNuxtAppInNitro, preferAssertMethod, preferEventFetch, preferGetRequestIp, preferRouteMethodSuffix, preferValidatedBody, preferValidatedQuery, preferValidatedRouterParams, requireEventRuntimeConfigInServer };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import "../../nitro-
|
|
3
|
-
export { nitroRulePack, noBrowserApiInServer, noClientComposablesInServer, noNavigateToInNitro, noUseNuxtAppInNitro, preferAssertMethod, preferEventFetch, preferGetRequestIp, preferValidatedBody, preferValidatedQuery, preferValidatedRouterParams, requireEventRuntimeConfigInServer };
|
|
1
|
+
import { a as preferValidatedRouterParams, c as noBrowserApiInServer, d as preferEventFetch, f as noNavigateToInNitro, i as preferAssertMethod, l as noClientComposablesInServer, n as preferGetRequestIp, o as preferValidatedQuery, p as noUseNuxtAppInNitro, r as preferRouteMethodSuffix, s as preferValidatedBody, t as nitroRulePack, u as requireEventRuntimeConfigInServer } from "../../rules-BDMsIiOi.mjs";
|
|
2
|
+
import "../../nitro-D2XxIgEp.mjs";
|
|
3
|
+
export { nitroRulePack, noBrowserApiInServer, noClientComposablesInServer, noNavigateToInNitro, noUseNuxtAppInNitro, preferAssertMethod, preferEventFetch, preferGetRequestIp, preferRouteMethodSuffix, preferValidatedBody, preferValidatedQuery, preferValidatedRouterParams, requireEventRuntimeConfigInServer };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { nitroRulePack, noBrowserApiInServer, noClientComposablesInServer, noNavigateToInNitro, noUseNuxtAppInNitro, preferAssertMethod, preferEventFetch, preferGetRequestIp, preferValidatedBody, preferValidatedQuery, preferValidatedRouterParams, requireEventRuntimeConfigInServer };
|
|
1
|
+
import { a as preferValidatedRouterParams, c as noBrowserApiInServer, d as preferEventFetch, f as noNavigateToInNitro, i as preferAssertMethod, l as noClientComposablesInServer, n as preferGetRequestIp, o as preferValidatedQuery, p as noUseNuxtAppInNitro, r as preferRouteMethodSuffix, s as preferValidatedBody, t as nitroRulePack, u as requireEventRuntimeConfigInServer } from "../../index-CFlFH8Pi.mjs";
|
|
2
|
+
export { nitroRulePack, noBrowserApiInServer, noClientComposablesInServer, noNavigateToInNitro, noUseNuxtAppInNitro, preferAssertMethod, preferEventFetch, preferGetRequestIp, preferRouteMethodSuffix, preferValidatedBody, preferValidatedQuery, preferValidatedRouterParams, requireEventRuntimeConfigInServer };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { nitroRulePack, noBrowserApiInServer, noClientComposablesInServer, noNavigateToInNitro, noUseNuxtAppInNitro, preferAssertMethod, preferEventFetch, preferGetRequestIp, preferValidatedBody, preferValidatedQuery, preferValidatedRouterParams, requireEventRuntimeConfigInServer };
|
|
1
|
+
import { a as preferValidatedRouterParams, c as noBrowserApiInServer, d as preferEventFetch, f as noNavigateToInNitro, i as preferAssertMethod, l as noClientComposablesInServer, n as preferGetRequestIp, o as preferValidatedQuery, p as noUseNuxtAppInNitro, r as preferRouteMethodSuffix, s as preferValidatedBody, t as nitroRulePack, u as requireEventRuntimeConfigInServer } from "../../rules-BDMsIiOi.mjs";
|
|
2
|
+
export { nitroRulePack, noBrowserApiInServer, noClientComposablesInServer, noNavigateToInNitro, noUseNuxtAppInNitro, preferAssertMethod, preferEventFetch, preferGetRequestIp, preferRouteMethodSuffix, preferValidatedBody, preferValidatedQuery, preferValidatedRouterParams, requireEventRuntimeConfigInServer };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { o as RulePack, t as DoctorExtension } from "../../../primitives-mLCLAmZ3.mjs";
|
|
2
|
-
import { t as nitroRulePack } from "../../../index-
|
|
2
|
+
import { t as nitroRulePack } from "../../../index-CFlFH8Pi.mjs";
|
|
3
3
|
//#region src/rule-packs/nuxt/rules/nuxt/index.d.ts
|
|
4
4
|
declare const nuxtRulePack: RulePack;
|
|
5
5
|
//#endregion
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as nitroRulePack } from "../../../rules-
|
|
2
|
-
import { a as nuxtImageRulePack, c as nuxtScriptsRulePack, d as nuxtRulePack, i as nuxtHubRulePack, l as nuxtUiRulePack, n as nuxtRulePacks, o as nuxtBetterAuthRulePack, r as docusRulePack, s as vueUseRulePack, t as nuxtDoctorExtensions, u as nuxtContentRulePack } from "../../../rules-
|
|
1
|
+
import { t as nitroRulePack } from "../../../rules-BDMsIiOi.mjs";
|
|
2
|
+
import { a as nuxtImageRulePack, c as nuxtScriptsRulePack, d as nuxtRulePack, i as nuxtHubRulePack, l as nuxtUiRulePack, n as nuxtRulePacks, o as nuxtBetterAuthRulePack, r as docusRulePack, s as vueUseRulePack, t as nuxtDoctorExtensions, u as nuxtContentRulePack } from "../../../rules-M6yUv7EP.mjs";
|
|
3
3
|
export { docusRulePack, nitroRulePack, nuxtBetterAuthRulePack, nuxtContentRulePack, nuxtDoctorExtensions, nuxtHubRulePack, nuxtImageRulePack, nuxtRulePack, nuxtRulePacks, nuxtScriptsRulePack, nuxtUiRulePack, vueUseRulePack };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { S as noUnusedDefine, _ as noUntypedEnv, a as noBroadFsAllow, b as noSecretDefine, c as noDynamicWorkerUrl, d as noDynamicNewUrl, f as noPublicSrcImport, g as noEmptyEnvPrefix, h as noClientSecretPattern, i as requirePluginName, l as noNodeApiInWorker, m as noBroadEnvPrefix, n as preferTransformFilter, o as noDisabledFsStrict, p as noSrcAbsolutePublicUrl, r as requireDisposeForSideEffects, s as noBrowserGlobalInSsrEntry, t as viteRulePack, u as requireWorkerUrlPattern, v as preferDirectImportMetaEnvAccess, x as noUntypedDefine, y as noRuntimeObjectDefine } from "../../rules-
|
|
1
|
+
import { S as noUnusedDefine, _ as noUntypedEnv, a as noBroadFsAllow, b as noSecretDefine, c as noDynamicWorkerUrl, d as noDynamicNewUrl, f as noPublicSrcImport, g as noEmptyEnvPrefix, h as noClientSecretPattern, i as requirePluginName, l as noNodeApiInWorker, m as noBroadEnvPrefix, n as preferTransformFilter, o as noDisabledFsStrict, p as noSrcAbsolutePublicUrl, r as requireDisposeForSideEffects, s as noBrowserGlobalInSsrEntry, t as viteRulePack, u as requireWorkerUrlPattern, v as preferDirectImportMetaEnvAccess, x as noUntypedDefine, y as noRuntimeObjectDefine } from "../../rules-cyFhFs4w.mjs";
|
|
2
2
|
export { noBroadEnvPrefix, noBroadFsAllow, noBrowserGlobalInSsrEntry, noClientSecretPattern, noDisabledFsStrict, noDynamicNewUrl, noDynamicWorkerUrl, noEmptyEnvPrefix, noNodeApiInWorker, noPublicSrcImport, noRuntimeObjectDefine, noSecretDefine, noSrcAbsolutePublicUrl, noUntypedDefine, noUntypedEnv, noUnusedDefine, preferDirectImportMetaEnvAccess, preferTransformFilter, requireDisposeForSideEffects, requirePluginName, requireWorkerUrlPattern, viteRulePack };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { S as noUnusedDefine, _ as noUntypedEnv, a as noBroadFsAllow, b as noSecretDefine, c as noDynamicWorkerUrl, d as noDynamicNewUrl, f as noPublicSrcImport, g as noEmptyEnvPrefix, h as noClientSecretPattern, i as requirePluginName, l as noNodeApiInWorker, m as noBroadEnvPrefix, n as preferTransformFilter, o as noDisabledFsStrict, p as noSrcAbsolutePublicUrl, r as requireDisposeForSideEffects, s as noBrowserGlobalInSsrEntry, t as viteRulePack, u as requireWorkerUrlPattern, v as preferDirectImportMetaEnvAccess, x as noUntypedDefine, y as noRuntimeObjectDefine } from "../../../rules-
|
|
1
|
+
import { S as noUnusedDefine, _ as noUntypedEnv, a as noBroadFsAllow, b as noSecretDefine, c as noDynamicWorkerUrl, d as noDynamicNewUrl, f as noPublicSrcImport, g as noEmptyEnvPrefix, h as noClientSecretPattern, i as requirePluginName, l as noNodeApiInWorker, m as noBroadEnvPrefix, n as preferTransformFilter, o as noDisabledFsStrict, p as noSrcAbsolutePublicUrl, r as requireDisposeForSideEffects, s as noBrowserGlobalInSsrEntry, t as viteRulePack, u as requireWorkerUrlPattern, v as preferDirectImportMetaEnvAccess, x as noUntypedDefine, y as noRuntimeObjectDefine } from "../../../rules-cyFhFs4w.mjs";
|
|
2
2
|
export { viteRulePack as default, noBroadEnvPrefix, noBroadFsAllow, noBrowserGlobalInSsrEntry, noClientSecretPattern, noDisabledFsStrict, noDynamicNewUrl, noDynamicWorkerUrl, noEmptyEnvPrefix, noNodeApiInWorker, noPublicSrcImport, noRuntimeObjectDefine, noSecretDefine, noSrcAbsolutePublicUrl, noUntypedDefine, noUntypedEnv, noUnusedDefine, preferDirectImportMetaEnvAccess, preferTransformFilter, requireDisposeForSideEffects, requirePluginName, requireWorkerUrlPattern };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as htmlButtonHasType, E as definePropsWatchGetter, S as preferUseTemplateRef, T as noRefAsOperand, _ as noAsyncWatchEffectAfterAwaitRead, a as preferComposableRefReturn, b as noBrowserApiInSetup, c as preferDefineModel, d as preferUseIdForStableIds, f as requireLifecycleCleanup, g as requireWatcherCleanup, h as requirePostFlushForDomWatch, i as preferSameNamePropShorthand, l as dataAllowMismatchSurgical, m as preferUseEventListener, n as noUntranslatedText, o as preferTypeProps, p as noMutationInOnUpdated, r as noUnusedTranslations, s as preferPropsDestructureDefaults, t as vueRulePack, u as noRandomOrLocalTimeRender, v as noSetupPropsDestructure, w as noOnWatcherCleanupAfterAwait, x as preferTrueAttributeShorthand, y as restrictVHtml } from "../../rules-
|
|
1
|
+
import { C as htmlButtonHasType, E as definePropsWatchGetter, S as preferUseTemplateRef, T as noRefAsOperand, _ as noAsyncWatchEffectAfterAwaitRead, a as preferComposableRefReturn, b as noBrowserApiInSetup, c as preferDefineModel, d as preferUseIdForStableIds, f as requireLifecycleCleanup, g as requireWatcherCleanup, h as requirePostFlushForDomWatch, i as preferSameNamePropShorthand, l as dataAllowMismatchSurgical, m as preferUseEventListener, n as noUntranslatedText, o as preferTypeProps, p as noMutationInOnUpdated, r as noUnusedTranslations, s as preferPropsDestructureDefaults, t as vueRulePack, u as noRandomOrLocalTimeRender, v as noSetupPropsDestructure, w as noOnWatcherCleanupAfterAwait, x as preferTrueAttributeShorthand, y as restrictVHtml } from "../../rules-DBiaAWeX.mjs";
|
|
2
2
|
export { dataAllowMismatchSurgical, definePropsWatchGetter, htmlButtonHasType, noAsyncWatchEffectAfterAwaitRead, noBrowserApiInSetup, noMutationInOnUpdated, noOnWatcherCleanupAfterAwait, noRandomOrLocalTimeRender, noRefAsOperand, noSetupPropsDestructure, noUntranslatedText, noUnusedTranslations, preferComposableRefReturn, preferDefineModel, preferPropsDestructureDefaults, preferSameNamePropShorthand, preferTrueAttributeShorthand, preferTypeProps, preferUseEventListener, preferUseIdForStableIds, preferUseTemplateRef, requireLifecycleCleanup, requirePostFlushForDomWatch, requireWatcherCleanup, restrictVHtml, vueRulePack };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as htmlButtonHasType, E as definePropsWatchGetter, S as preferUseTemplateRef, T as noRefAsOperand, _ as noAsyncWatchEffectAfterAwaitRead, a as preferComposableRefReturn, b as noBrowserApiInSetup, c as preferDefineModel, d as preferUseIdForStableIds, f as requireLifecycleCleanup, g as requireWatcherCleanup, h as requirePostFlushForDomWatch, i as preferSameNamePropShorthand, l as dataAllowMismatchSurgical, m as preferUseEventListener, n as noUntranslatedText, o as preferTypeProps, p as noMutationInOnUpdated, r as noUnusedTranslations, s as preferPropsDestructureDefaults, t as vueRulePack, u as noRandomOrLocalTimeRender, v as noSetupPropsDestructure, w as noOnWatcherCleanupAfterAwait, x as preferTrueAttributeShorthand, y as restrictVHtml } from "../../rules-
|
|
1
|
+
import { C as htmlButtonHasType, E as definePropsWatchGetter, S as preferUseTemplateRef, T as noRefAsOperand, _ as noAsyncWatchEffectAfterAwaitRead, a as preferComposableRefReturn, b as noBrowserApiInSetup, c as preferDefineModel, d as preferUseIdForStableIds, f as requireLifecycleCleanup, g as requireWatcherCleanup, h as requirePostFlushForDomWatch, i as preferSameNamePropShorthand, l as dataAllowMismatchSurgical, m as preferUseEventListener, n as noUntranslatedText, o as preferTypeProps, p as noMutationInOnUpdated, r as noUnusedTranslations, s as preferPropsDestructureDefaults, t as vueRulePack, u as noRandomOrLocalTimeRender, v as noSetupPropsDestructure, w as noOnWatcherCleanupAfterAwait, x as preferTrueAttributeShorthand, y as restrictVHtml } from "../../rules-DBiaAWeX.mjs";
|
|
2
2
|
export { dataAllowMismatchSurgical, definePropsWatchGetter, htmlButtonHasType, noAsyncWatchEffectAfterAwaitRead, noBrowserApiInSetup, noMutationInOnUpdated, noOnWatcherCleanupAfterAwait, noRandomOrLocalTimeRender, noRefAsOperand, noSetupPropsDestructure, noUntranslatedText, noUnusedTranslations, preferComposableRefReturn, preferDefineModel, preferPropsDestructureDefaults, preferSameNamePropShorthand, preferTrueAttributeShorthand, preferTypeProps, preferUseEventListener, preferUseIdForStableIds, preferUseTemplateRef, requireLifecycleCleanup, requirePostFlushForDomWatch, requireWatcherCleanup, restrictVHtml, vueRulePack };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as codeForRuleId, d as defineRulePack, f as doctorInternalDiagnostics, l as createRule, o as defineDoctorDiagnostics, s as diagnosticForCode } from "./core-WTY_jAiL.mjs";
|
|
2
2
|
//#region src/rule-packs/nitro/diagnostics.ts
|
|
3
3
|
const nitroDiagnosticRegistry = defineDoctorDiagnostics([
|
|
4
4
|
{
|
|
@@ -44,6 +44,10 @@ const nitroDiagnosticRegistry = defineDoctorDiagnostics([
|
|
|
44
44
|
{
|
|
45
45
|
code: "NITRO0011",
|
|
46
46
|
ruleId: "nitro/server/prefer-event-fetch"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
code: "NITRO0012",
|
|
50
|
+
ruleId: "nitro/request/prefer-route-method-suffix"
|
|
47
51
|
}
|
|
48
52
|
]);
|
|
49
53
|
const diagnostics = nitroDiagnosticRegistry.diagnostics;
|
|
@@ -103,11 +107,16 @@ const BROWSER_GLOBALS = new Set([
|
|
|
103
107
|
"IntersectionObserver"
|
|
104
108
|
]);
|
|
105
109
|
function report(ctx, node, ruleId, severity, category, message, suggestion) {
|
|
106
|
-
const
|
|
107
|
-
if (!
|
|
110
|
+
const code = codeForRuleId(diagnosticCodesByRuleId, ruleId);
|
|
111
|
+
if (!code) throw doctorInternalDiagnostics.DOC0013({ ruleId });
|
|
112
|
+
const diagnostic = diagnosticForCode(diagnostics, code);
|
|
113
|
+
if (!diagnostic) throw doctorInternalDiagnostics.DOC0013({
|
|
114
|
+
ruleId,
|
|
115
|
+
code
|
|
116
|
+
});
|
|
108
117
|
ctx.helpers.report(ctx, node, diagnostic({
|
|
109
118
|
why: message,
|
|
110
|
-
fix: suggestion
|
|
119
|
+
fix: suggestion
|
|
111
120
|
}), {
|
|
112
121
|
ruleId,
|
|
113
122
|
severity,
|
|
@@ -138,7 +147,7 @@ const noUseNuxtAppInNitro = createRule({
|
|
|
138
147
|
create(ctx) {
|
|
139
148
|
if (!ctx.helpers.isNuxtServerFile(ctx.file.relativePath)) return;
|
|
140
149
|
return { ScriptNode(node) {
|
|
141
|
-
if (ctx.helpers.isCall(node, "useNuxtApp")) report(ctx, node, "nitro/context/no-usenuxtapp-in-nitro", "error", "server", "useNuxtApp() is an app runtime composable and is not available in Nitro handlers. Use event-aware server utilities instead.");
|
|
150
|
+
if (ctx.helpers.isCall(node, "useNuxtApp")) report(ctx, node, "nitro/context/no-usenuxtapp-in-nitro", "error", "server", "useNuxtApp() is an app runtime composable and is not available in Nitro handlers. Use event-aware server utilities instead.", "Replace useNuxtApp() with event-aware Nitro, h3, or server utilities.");
|
|
142
151
|
} };
|
|
143
152
|
}
|
|
144
153
|
});
|
|
@@ -162,7 +171,7 @@ const noNavigateToInNitro = createRule({
|
|
|
162
171
|
create(ctx) {
|
|
163
172
|
if (!ctx.helpers.isNuxtServerFile(ctx.file.relativePath)) return;
|
|
164
173
|
return { ScriptNode(node) {
|
|
165
|
-
if (ctx.helpers.isCall(node, "navigateTo")) report(ctx, node, "nitro/context/no-navigateto-in-nitro", "error", "server", "navigateTo() is for Nuxt app navigation. Use sendRedirect(event, path) in Nitro handlers.");
|
|
174
|
+
if (ctx.helpers.isCall(node, "navigateTo")) report(ctx, node, "nitro/context/no-navigateto-in-nitro", "error", "server", "navigateTo() is for Nuxt app navigation. Use sendRedirect(event, path) in Nitro handlers.", "Use sendRedirect(event, path) from the Nitro request handler.");
|
|
166
175
|
} };
|
|
167
176
|
}
|
|
168
177
|
});
|
|
@@ -354,17 +363,56 @@ function isRequestSensitiveUse(ctx, node) {
|
|
|
354
363
|
const text = sourceForNode(nearestFunctionOrProgram(node) ?? node, ctx.file.text);
|
|
355
364
|
return /\b(?:rateLimit|rateLimiter|ipLimit|throttle|ban|blockIp|allowIp|denyIp|ipAllow|ipDeny|ipBlock|ipBan|blacklist|whitelist)\b/i.test(text);
|
|
356
365
|
}
|
|
357
|
-
function
|
|
366
|
+
function singleMethodCheck(node, source, anchor = node) {
|
|
358
367
|
if (node.type !== "BinaryExpression") return null;
|
|
359
368
|
const operator = node.operator;
|
|
360
369
|
if (operator !== "===" && operator !== "==" && operator !== "!==" && operator !== "!=") return null;
|
|
361
|
-
const leftMethod = methodExpressionName(node.left, source);
|
|
362
|
-
const rightMethod = methodExpressionName(node.right, source);
|
|
370
|
+
const leftMethod = methodExpressionName(node.left, source, anchor);
|
|
371
|
+
const rightMethod = methodExpressionName(node.right, source, anchor);
|
|
363
372
|
const method = staticString(node.left, source) ?? staticString(node.right, source);
|
|
364
373
|
if (!method || !leftMethod && !rightMethod) return null;
|
|
365
374
|
const normalized = method.toUpperCase();
|
|
366
|
-
if (
|
|
367
|
-
return
|
|
375
|
+
if (!isHttpMethod(normalized)) return null;
|
|
376
|
+
return {
|
|
377
|
+
method: normalized,
|
|
378
|
+
operator,
|
|
379
|
+
isNegative: operator === "!==" || operator === "!="
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
function isSingleMethodCheck(node, source, anchor = node) {
|
|
383
|
+
return singleMethodCheck(node, source, anchor)?.method ?? null;
|
|
384
|
+
}
|
|
385
|
+
function methodChecks(node, source, anchor = node) {
|
|
386
|
+
const checks = /* @__PURE__ */ new Map();
|
|
387
|
+
walkScriptLocal(node, (child) => {
|
|
388
|
+
const check = singleMethodCheck(child, source, anchor);
|
|
389
|
+
if (check) checks.set(`${check.method}:${check.operator}`, check);
|
|
390
|
+
});
|
|
391
|
+
return [...checks.values()];
|
|
392
|
+
}
|
|
393
|
+
function isInIfStatementTest(node) {
|
|
394
|
+
let current = node;
|
|
395
|
+
while (current) {
|
|
396
|
+
const parent = current.__doctorParent;
|
|
397
|
+
if (!parent) return false;
|
|
398
|
+
if (parent.type === "IfStatement" && parent.test === current) return true;
|
|
399
|
+
current = parent;
|
|
400
|
+
}
|
|
401
|
+
return false;
|
|
402
|
+
}
|
|
403
|
+
function isNitroRouteFile(relativePath) {
|
|
404
|
+
const path = normalizePath(relativePath);
|
|
405
|
+
return /^(?:(?:app\/)?server\/)?(?:api|routes)\/.+\.[cm]?[jt]s$/.test(path);
|
|
406
|
+
}
|
|
407
|
+
function routeMethodSuffix(relativePath) {
|
|
408
|
+
const method = normalizePath(relativePath).match(/\.([a-z]+)(?:\.(?:dev|prod|prerender))?\.[cm]?[jt]s$/)?.[1]?.toUpperCase();
|
|
409
|
+
return method && isHttpMethod(method) ? method : null;
|
|
410
|
+
}
|
|
411
|
+
function routePathWithMethodSuffix(relativePath, suffix) {
|
|
412
|
+
const path = normalizePath(relativePath);
|
|
413
|
+
const existingMethod = routeMethodSuffix(path);
|
|
414
|
+
if (existingMethod) return path.replace(new RegExp(`\\.${existingMethod.toLowerCase()}(\\.(?:dev|prod|prerender))?(\\.[cm]?[jt]s)$`, "i"), `.${suffix}$1$2`);
|
|
415
|
+
return path.replace(/(\.(?:dev|prod|prerender))?(\.[cm]?[jt]s)$/, (_match, env = "", extension) => `.${suffix}${env}${extension}`);
|
|
368
416
|
}
|
|
369
417
|
function rawInputVariable(node, rawUtilities) {
|
|
370
418
|
if (node.type !== "VariableDeclarator" || node.id?.type !== "Identifier") return null;
|
|
@@ -396,10 +444,13 @@ function isSchemaMethodValidatorCall(node, variable, source) {
|
|
|
396
444
|
const callee = sourceForNode(node.callee, source);
|
|
397
445
|
return /\b(?:schema|validator|body|query|params|input|payload|zod|valibot|v|s)\w*\.(?:parse|safeParse|validate)$/.test(callee);
|
|
398
446
|
}
|
|
399
|
-
function methodExpressionName(node, source) {
|
|
447
|
+
function methodExpressionName(node, source, anchor, seen = /* @__PURE__ */ new Set()) {
|
|
400
448
|
if (node.type === "CallExpression" && calleeName(node) === "getMethod") return "getMethod";
|
|
401
449
|
const text = sourceForNode(node, source);
|
|
402
|
-
|
|
450
|
+
if (/\bevent\.(?:method|req\.method|node\.req\.method)\b/.test(text)) return text;
|
|
451
|
+
if (anchor && isMemberMethodRead(node, source, anchor, seen)) return text;
|
|
452
|
+
if (node.type === "Identifier" && anchor && !seen.has(node.name) && isMethodAlias(anchor, node.name, source, seen)) return node.name;
|
|
453
|
+
return null;
|
|
403
454
|
}
|
|
404
455
|
function staticString(node, source) {
|
|
405
456
|
if (!node) return null;
|
|
@@ -413,6 +464,68 @@ function unwrapAwait(node) {
|
|
|
413
464
|
function calleeName(node) {
|
|
414
465
|
return node?.callee?.type === "Identifier" ? node.callee.name : node?.callee?.property?.name ?? null;
|
|
415
466
|
}
|
|
467
|
+
function isMemberMethodRead(node, source, anchor, seen) {
|
|
468
|
+
if (!node || node.type !== "MemberExpression" && node.type !== "StaticMemberExpression") return false;
|
|
469
|
+
if (node.computed) return false;
|
|
470
|
+
if (node.property?.name !== "method") return false;
|
|
471
|
+
const object = node.object;
|
|
472
|
+
const objectText = sourceForNode(object, source);
|
|
473
|
+
if (/^event\.(?:req|node\.req)$/.test(objectText)) return true;
|
|
474
|
+
if (object?.type === "Identifier" && anchor) return isRequestAlias(anchor, object.name, source, seen);
|
|
475
|
+
return false;
|
|
476
|
+
}
|
|
477
|
+
function isRequestAlias(anchor, name, source, seen) {
|
|
478
|
+
const declaration = findVariableDeclarationBefore(anchor, name);
|
|
479
|
+
if (!declaration) return false;
|
|
480
|
+
const init = declaration.init;
|
|
481
|
+
if (!init) return false;
|
|
482
|
+
const text = sourceForNode(init, source);
|
|
483
|
+
if (/^event\.(?:req|node\.req)$/.test(text)) return true;
|
|
484
|
+
if (init?.type === "Identifier" && !seen.has(init.name)) {
|
|
485
|
+
seen.add(init.name);
|
|
486
|
+
return isRequestAlias(anchor, init.name, source, seen);
|
|
487
|
+
}
|
|
488
|
+
return false;
|
|
489
|
+
}
|
|
490
|
+
function isMethodAlias(anchor, name, source, seen) {
|
|
491
|
+
const declaration = findVariableDeclarationBefore(anchor, name);
|
|
492
|
+
if (!declaration?.init) return false;
|
|
493
|
+
seen.add(name);
|
|
494
|
+
return Boolean(methodExpressionName(declaration.init, source, anchor, seen));
|
|
495
|
+
}
|
|
496
|
+
function findVariableDeclarationBefore(anchor, name) {
|
|
497
|
+
let child = anchor;
|
|
498
|
+
let scope = child.__doctorParent;
|
|
499
|
+
while (scope) {
|
|
500
|
+
if (scope.type === "BlockStatement" || scope.type === "Program") {
|
|
501
|
+
const declaration = findDeclarationInScopeBefore(scope, child, name);
|
|
502
|
+
if (declaration) return declaration;
|
|
503
|
+
}
|
|
504
|
+
child = scope;
|
|
505
|
+
scope = scope.__doctorParent;
|
|
506
|
+
}
|
|
507
|
+
return null;
|
|
508
|
+
}
|
|
509
|
+
function findDeclarationInScopeBefore(scope, child, name) {
|
|
510
|
+
let match = null;
|
|
511
|
+
for (const statement of scope.body ?? []) {
|
|
512
|
+
if (statement === child) break;
|
|
513
|
+
if ((statement.start ?? statement.range?.[0] ?? 0) >= (child.start ?? child.range?.[0] ?? 0)) break;
|
|
514
|
+
const declaration = variableDeclarationFromStatement(statement, name);
|
|
515
|
+
if (declaration) match = declaration;
|
|
516
|
+
}
|
|
517
|
+
return match;
|
|
518
|
+
}
|
|
519
|
+
function variableDeclarationFromStatement(statement, name) {
|
|
520
|
+
if (statement.type !== "VariableDeclaration") return null;
|
|
521
|
+
return statement.declarations?.find((declaration) => declaration.id?.type === "Identifier" && declaration.id.name === name) ?? null;
|
|
522
|
+
}
|
|
523
|
+
function isHttpMethod(method) {
|
|
524
|
+
return /^(GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS|CONNECT|TRACE)$/.test(method);
|
|
525
|
+
}
|
|
526
|
+
function normalizePath(path) {
|
|
527
|
+
return path.replace(/\\/g, "/");
|
|
528
|
+
}
|
|
416
529
|
//#endregion
|
|
417
530
|
//#region src/rule-packs/nitro/rules/prefer-validated-body.ts
|
|
418
531
|
const preferValidatedBody = createValidatedInputRule({
|
|
@@ -468,6 +581,7 @@ const preferAssertMethod = createRule({
|
|
|
468
581
|
},
|
|
469
582
|
create(ctx) {
|
|
470
583
|
if (!ctx.helpers.isNuxtServerFile(ctx.file.relativePath)) return;
|
|
584
|
+
if (isNitroRouteFile(ctx.file.relativePath)) return;
|
|
471
585
|
return { ScriptNode(node) {
|
|
472
586
|
const method = isSingleMethodCheck(node, ctx.file.text);
|
|
473
587
|
if (!method) return;
|
|
@@ -476,6 +590,82 @@ const preferAssertMethod = createRule({
|
|
|
476
590
|
}
|
|
477
591
|
});
|
|
478
592
|
//#endregion
|
|
593
|
+
//#region src/rule-packs/nitro/rules/prefer-route-method-suffix.ts
|
|
594
|
+
const RULE_ID = "nitro/request/prefer-route-method-suffix";
|
|
595
|
+
const preferRouteMethodSuffix = createRule({
|
|
596
|
+
meta: {
|
|
597
|
+
id: RULE_ID,
|
|
598
|
+
title: "Use Nitro route method suffixes",
|
|
599
|
+
description: "File-routed Nitro handlers should use HTTP method filename suffixes instead of manual request method gates.",
|
|
600
|
+
why: "Nitro's file router can bind handlers to HTTP methods before user code runs, which keeps unsupported methods out of the handler and makes the route contract visible in the filesystem.",
|
|
601
|
+
recommendedReplacement: "Use route files such as server/api/user.get.ts or server/api/user.post.ts instead of checking request.method inside the handler.",
|
|
602
|
+
examples: [{
|
|
603
|
+
title: "Move method gates into the route filename",
|
|
604
|
+
language: "ts",
|
|
605
|
+
invalid: "export default defineEventHandler((event) => {\n if (getMethod(event) !== 'POST') throw createError({ statusCode: 405 })\n return createUser(event)\n})",
|
|
606
|
+
valid: "// server/api/user.post.ts\nexport default defineEventHandler((event) => {\n return createUser(event)\n})"
|
|
607
|
+
}],
|
|
608
|
+
category: "request",
|
|
609
|
+
severity: "warn",
|
|
610
|
+
fixable: "suggestion",
|
|
611
|
+
docsUrl: "https://nitro.build/docs/routing#specific-request-method",
|
|
612
|
+
requires: {
|
|
613
|
+
script: true,
|
|
614
|
+
nitro: true
|
|
615
|
+
}
|
|
616
|
+
},
|
|
617
|
+
create(ctx) {
|
|
618
|
+
if (!isNitroRouteFile(ctx.file.relativePath)) return;
|
|
619
|
+
return { ScriptNode(node) {
|
|
620
|
+
if (node.type === "IfStatement") {
|
|
621
|
+
const checks = methodChecks(node.test, ctx.file.text, node);
|
|
622
|
+
if (!checks.length) return;
|
|
623
|
+
reportMethodCheck(node.test ?? node, checks, wholeHandlerAllowed(node, checks));
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
if (node.type !== "BinaryExpression" || isInIfStatementTest(node)) return;
|
|
627
|
+
const check = singleMethodCheck(node, ctx.file.text, node);
|
|
628
|
+
if (!check) return;
|
|
629
|
+
reportMethodCheck(node, [check], false);
|
|
630
|
+
} };
|
|
631
|
+
function reportMethodCheck(node, checks, wholeHandler) {
|
|
632
|
+
const methods = methodsFromChecks(checks);
|
|
633
|
+
const suffix = routeMethodSuffix(ctx.file.relativePath);
|
|
634
|
+
const suggestion = suffix && isRedundantSuffix(suffix, methods) ? `Remove the manual method guard; .${suffix.toLowerCase()}.ts already constrains this route.` : methodSuffixSuggestion(ctx.file.relativePath, methods, wholeHandler);
|
|
635
|
+
report(ctx, node, RULE_ID, "warn", "request", `This file-routed Nitro handler checks ${formatMethods(methods)} manually.`, suggestion);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
});
|
|
639
|
+
function formatMethods(methods) {
|
|
640
|
+
return methods.length === 1 ? methods[0] : methods.join("/");
|
|
641
|
+
}
|
|
642
|
+
function isRedundantSuffix(suffix, methods) {
|
|
643
|
+
return methods.length === 1 && methods[0] === suffix;
|
|
644
|
+
}
|
|
645
|
+
function methodSuffixSuggestion(relativePath, methods, wholeHandler) {
|
|
646
|
+
const paths = methods.map((method) => routePathWithMethodSuffix(relativePath, method.toLowerCase()));
|
|
647
|
+
if (wholeHandler && paths.length === 1) return `Move this handler to ${paths[0]} and remove the manual method guard.`;
|
|
648
|
+
if (wholeHandler) return `Split this handler into ${formatList(paths)} and remove the manual method guard.`;
|
|
649
|
+
if (paths.length === 1) return `Move the ${methods[0]}-specific branch to ${paths[0]} and keep other method behavior in method-suffixed route files.`;
|
|
650
|
+
return `Move the method-specific branches to ${formatList(paths)} and keep other method behavior in method-suffixed route files.`;
|
|
651
|
+
}
|
|
652
|
+
function formatList(items) {
|
|
653
|
+
if (items.length <= 1) return items[0] ?? "";
|
|
654
|
+
return `${items.slice(0, -1).join(", ")} and ${items.at(-1)}`;
|
|
655
|
+
}
|
|
656
|
+
function methodsFromChecks(checks) {
|
|
657
|
+
return [...new Set(checks.map((check) => check.method))];
|
|
658
|
+
}
|
|
659
|
+
function wholeHandlerAllowed(node, checks) {
|
|
660
|
+
return checks.every((check) => check.isNegative) && branchExits(node.consequent);
|
|
661
|
+
}
|
|
662
|
+
function branchExits(node) {
|
|
663
|
+
if (!node) return false;
|
|
664
|
+
if (node.type === "ReturnStatement" || node.type === "ThrowStatement") return true;
|
|
665
|
+
if (node.type !== "BlockStatement") return false;
|
|
666
|
+
return branchExits(node.body?.at(-1));
|
|
667
|
+
}
|
|
668
|
+
//#endregion
|
|
479
669
|
//#region src/rule-packs/nitro/rules/prefer-get-request-ip.ts
|
|
480
670
|
const preferGetRequestIp = createRule({
|
|
481
671
|
meta: {
|
|
@@ -514,6 +704,7 @@ const rules = [
|
|
|
514
704
|
preferValidatedQuery,
|
|
515
705
|
preferValidatedRouterParams,
|
|
516
706
|
preferAssertMethod,
|
|
707
|
+
preferRouteMethodSuffix,
|
|
517
708
|
preferGetRequestIp
|
|
518
709
|
];
|
|
519
710
|
const nitroRulePack = defineRulePack({
|
|
@@ -526,4 +717,4 @@ const nitroRulePack = defineRulePack({
|
|
|
526
717
|
}
|
|
527
718
|
});
|
|
528
719
|
//#endregion
|
|
529
|
-
export {
|
|
720
|
+
export { walkScriptLocal as _, preferValidatedRouterParams as a, noBrowserApiInServer as c, preferEventFetch as d, noNavigateToInNitro as f, sourceForNode as g, nearestFunctionOrProgram as h, preferAssertMethod as i, noClientComposablesInServer as l, findAncestor as m, preferGetRequestIp as n, preferValidatedQuery as o, noUseNuxtAppInNitro as p, preferRouteMethodSuffix as r, preferValidatedBody as s, nitroRulePack as t, requireEventRuntimeConfigInServer as u };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as codeForRuleId, d as defineRulePack, f as doctorInternalDiagnostics, l as createRule, o as defineDoctorDiagnostics, s as diagnosticForCode } from "./core-WTY_jAiL.mjs";
|
|
2
2
|
import { dirname, relative, resolve } from "pathe";
|
|
3
3
|
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
4
4
|
import { parseSync } from "oxc-parser";
|
|
@@ -123,11 +123,16 @@ const BROWSER_GLOBALS = new Set([
|
|
|
123
123
|
const delegatedMessages = { "vue/reactivity/no-ref-as-operand": "Refs used as script operands must be unwrapped with .value." };
|
|
124
124
|
const delegatedSuggestions = { "vue/reactivity/no-ref-as-operand": "Use .value in script expressions." };
|
|
125
125
|
function report(ctx, node, ruleId, severity, category, message, suggestion) {
|
|
126
|
-
const
|
|
127
|
-
if (!
|
|
126
|
+
const code = codeForRuleId(diagnosticCodesByRuleId, ruleId);
|
|
127
|
+
if (!code) throw doctorInternalDiagnostics.DOC0013({ ruleId });
|
|
128
|
+
const diagnostic = diagnosticForCode(diagnostics, code);
|
|
129
|
+
if (!diagnostic) throw doctorInternalDiagnostics.DOC0013({
|
|
130
|
+
ruleId,
|
|
131
|
+
code
|
|
132
|
+
});
|
|
128
133
|
ctx.helpers.report(ctx, node, diagnostic({
|
|
129
134
|
why: message,
|
|
130
|
-
fix: suggestion
|
|
135
|
+
fix: suggestion
|
|
131
136
|
}), {
|
|
132
137
|
ruleId,
|
|
133
138
|
severity,
|
|
@@ -226,8 +231,13 @@ function createEslintVueRule(options) {
|
|
|
226
231
|
}], { filename: ctx.file.relativePath });
|
|
227
232
|
for (const message of messages) {
|
|
228
233
|
if (message.ruleId !== options.eslintId) continue;
|
|
229
|
-
const
|
|
230
|
-
if (!
|
|
234
|
+
const code = codeForRuleId(diagnosticCodesByRuleId, options.doctorId);
|
|
235
|
+
if (!code) throw doctorInternalDiagnostics.DOC0013({ ruleId: options.doctorId });
|
|
236
|
+
const diagnostic = diagnosticForCode(diagnostics, code);
|
|
237
|
+
if (!diagnostic) throw doctorInternalDiagnostics.DOC0013({
|
|
238
|
+
ruleId: options.doctorId,
|
|
239
|
+
code
|
|
240
|
+
});
|
|
231
241
|
ctx.report(diagnostic({
|
|
232
242
|
why: delegatedMessages[options.doctorId] ?? message.message,
|
|
233
243
|
fix: delegatedSuggestions[options.doctorId] ?? message.message
|
|
@@ -362,7 +372,7 @@ const noOnWatcherCleanupAfterAwait = createRule({
|
|
|
362
372
|
},
|
|
363
373
|
create(ctx) {
|
|
364
374
|
return { ScriptNode(node) {
|
|
365
|
-
if (ctx.helpers.isCall(node, "onWatcherCleanup") && isAfterAwaitInWatcherCallback(node)) report(ctx, node, "vue/watch/no-onwatchercleanup-after-await", "error", "watchers", "onWatcherCleanup() must be called synchronously before the first await in the watcher callback.");
|
|
375
|
+
if (ctx.helpers.isCall(node, "onWatcherCleanup") && isAfterAwaitInWatcherCallback(node)) report(ctx, node, "vue/watch/no-onwatchercleanup-after-await", "error", "watchers", "onWatcherCleanup() must be called synchronously before the first await in the watcher callback.", "Move onWatcherCleanup() before the first await in the watcher callback.");
|
|
366
376
|
} };
|
|
367
377
|
}
|
|
368
378
|
});
|
|
@@ -567,7 +577,7 @@ const noBrowserApiInSetup = createRule({
|
|
|
567
577
|
if (ctx.project.framework === "nuxt") return;
|
|
568
578
|
if (!ctx.project.ssr) return;
|
|
569
579
|
return { ScriptNode(node) {
|
|
570
|
-
if (node.type === "Identifier" && BROWSER_GLOBALS.has(node.name) && !ctx.file.relativePath.includes(".client.") && !ctx.helpers.isTypeOnlyContext(node) && !ctx.helpers.isTypeofOperand(node) && !ctx.helpers.hasLocalBindingBefore(node, ctx.file.text) && !ctx.helpers.isClientOnlyExecutionContext(node, ctx.file.text)) report(ctx, node, "vue/ssr/no-browser-api-in-setup", "error", "ssr", `${node.name} is a browser-only API. Access it inside onMounted(), a client-only plugin, or a guarded client branch.`);
|
|
580
|
+
if (node.type === "Identifier" && BROWSER_GLOBALS.has(node.name) && !ctx.file.relativePath.includes(".client.") && !ctx.helpers.isTypeOnlyContext(node) && !ctx.helpers.isTypeofOperand(node) && !ctx.helpers.hasLocalBindingBefore(node, ctx.file.text) && !ctx.helpers.isClientOnlyExecutionContext(node, ctx.file.text)) report(ctx, node, "vue/ssr/no-browser-api-in-setup", "error", "ssr", `${node.name} is a browser-only API. Access it inside onMounted(), a client-only plugin, or a guarded client branch.`, `Move ${node.name} access into onMounted(), a client-only plugin, or a guarded client branch.`);
|
|
571
581
|
} };
|
|
572
582
|
}
|
|
573
583
|
});
|
|
@@ -588,7 +598,7 @@ const restrictVHtml = createRule({
|
|
|
588
598
|
},
|
|
589
599
|
create(ctx) {
|
|
590
600
|
return { TemplateNode(node) {
|
|
591
|
-
if (node.type === "VElement" && ctx.helpers.hasVueDirective(node, "html")) report(ctx, node, "vue/security/restrict-v-html", "error", "security", "v-html can execute untrusted markup. Only render sanitized or trusted HTML here.");
|
|
601
|
+
if (node.type === "VElement" && ctx.helpers.hasVueDirective(node, "html")) report(ctx, node, "vue/security/restrict-v-html", "error", "security", "v-html can execute untrusted markup. Only render sanitized or trusted HTML here.", "Remove v-html or sanitize the HTML before rendering it.");
|
|
592
602
|
} };
|
|
593
603
|
}
|
|
594
604
|
});
|
|
@@ -971,7 +981,7 @@ const noMutationInOnUpdated = createRule({
|
|
|
971
981
|
if (!ctx.helpers.isCall(node, "onUpdated")) return;
|
|
972
982
|
const snippet = ctx.file.text.slice(node.start, node.end);
|
|
973
983
|
if (!/(\.value\s*=|\+\+|--|\.push\s*\(|\.splice\s*\(|=)/.test(snippet)) return;
|
|
974
|
-
report(ctx, node, "vue/lifecycle/no-mutation-in-onupdated", "error", "lifecycle", "Mutating reactive state in onUpdated can create update loops.", "Move the mutation to the event or
|
|
984
|
+
report(ctx, node, "vue/lifecycle/no-mutation-in-onupdated", "error", "lifecycle", "Mutating reactive state in onUpdated can create update loops.", "Move the reactive mutation to the event or state transition that owns it, or keep update bookkeeping in a non-reactive local.");
|
|
975
985
|
} };
|
|
976
986
|
}
|
|
977
987
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import {
|
|
3
|
-
import "./nitro-
|
|
4
|
-
import { t as vueRulePack } from "./rules-
|
|
1
|
+
import { a as codeForRuleId, d as defineRulePack, f as doctorInternalDiagnostics, l as createRule, o as defineDoctorDiagnostics, s as diagnosticForCode, u as defineDoctorExtension } from "./core-WTY_jAiL.mjs";
|
|
2
|
+
import { _ as walkScriptLocal, g as sourceForNode, h as nearestFunctionOrProgram, m as findAncestor, t as nitroRulePack } from "./rules-BDMsIiOi.mjs";
|
|
3
|
+
import "./nitro-D2XxIgEp.mjs";
|
|
4
|
+
import { t as vueRulePack } from "./rules-DBiaAWeX.mjs";
|
|
5
5
|
import { join, relative } from "pathe";
|
|
6
6
|
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
7
7
|
//#region src/rule-packs/nuxt/diagnostics.ts
|
|
@@ -692,11 +692,16 @@ const BROWSER_GLOBALS = new Set([
|
|
|
692
692
|
"IntersectionObserver"
|
|
693
693
|
]);
|
|
694
694
|
function report(ctx, node, ruleId, severity, category, message, suggestion) {
|
|
695
|
-
const
|
|
696
|
-
if (!
|
|
695
|
+
const code = codeForRuleId(diagnosticCodesByRuleId, ruleId);
|
|
696
|
+
if (!code) throw doctorInternalDiagnostics.DOC0013({ ruleId });
|
|
697
|
+
const diagnostic = diagnosticForCode(diagnostics, code);
|
|
698
|
+
if (!diagnostic) throw doctorInternalDiagnostics.DOC0013({
|
|
699
|
+
ruleId,
|
|
700
|
+
code
|
|
701
|
+
});
|
|
697
702
|
ctx.helpers.report(ctx, node, diagnostic({
|
|
698
703
|
why: message,
|
|
699
|
-
fix: suggestion
|
|
704
|
+
fix: suggestion
|
|
700
705
|
}), {
|
|
701
706
|
ruleId,
|
|
702
707
|
severity,
|
|
@@ -1601,7 +1606,7 @@ const noAwaitInsideCustomWrapper = createRule({
|
|
|
1601
1606
|
return { ScriptNode(node) {
|
|
1602
1607
|
if (node.type === "AwaitExpression" && ["useFetch", "useAsyncData"].includes(ctx.helpers.getCalleeName(node.argument) ?? "")) {
|
|
1603
1608
|
const text = ctx.file.text.slice(Math.max(0, node.start - 80), node.start);
|
|
1604
|
-
if (/function\s+use[A-Z]\w+|const\s+use[A-Z]\w+\s*=/.test(text)) report(ctx, node, "nuxt/fetch/no-await-inside-custom-wrapper", "error", "fetching", "Custom wrappers around useFetch/useAsyncData should return the composable directly. Awaiting inside the wrapper can break Nuxt async context behavior.");
|
|
1609
|
+
if (/function\s+use[A-Z]\w+|const\s+use[A-Z]\w+\s*=/.test(text)) report(ctx, node, "nuxt/fetch/no-await-inside-custom-wrapper", "error", "fetching", "Custom wrappers around useFetch/useAsyncData should return the composable directly. Awaiting inside the wrapper can break Nuxt async context behavior.", "Return the useFetch/useAsyncData promise directly from the custom wrapper.");
|
|
1605
1610
|
}
|
|
1606
1611
|
} };
|
|
1607
1612
|
}
|
|
@@ -1655,7 +1660,7 @@ const noUseRouteInMiddleware = createRule({
|
|
|
1655
1660
|
create(ctx) {
|
|
1656
1661
|
if (!ctx.file.relativePath.includes("/middleware/") && !ctx.file.relativePath.startsWith("middleware/") && !ctx.file.relativePath.startsWith("app/middleware/")) return;
|
|
1657
1662
|
return { ScriptNode(node) {
|
|
1658
|
-
if (ctx.helpers.isCall(node, "useRoute")) report(ctx, node, "nuxt/routing/no-useroute-in-middleware", "error", "routing", "Route middleware receives to/from route arguments. useRoute() can point at the previous route in this context.");
|
|
1663
|
+
if (ctx.helpers.isCall(node, "useRoute")) report(ctx, node, "nuxt/routing/no-useroute-in-middleware", "error", "routing", "Route middleware receives to/from route arguments. useRoute() can point at the previous route in this context.", "Read route data from the to/from middleware arguments instead of useRoute().");
|
|
1659
1664
|
} };
|
|
1660
1665
|
}
|
|
1661
1666
|
});
|
|
@@ -1772,7 +1777,7 @@ const noRouterNavigationInSetup = createRule({
|
|
|
1772
1777
|
if (!["router.push", "router.replace"].includes(ctx.helpers.getCalleeName(node) ?? "")) return;
|
|
1773
1778
|
if (ctx.helpers.isClientOnlyExecutionContext(node, ctx.file.text)) return;
|
|
1774
1779
|
if (evidence.isClientCallable(node)) return;
|
|
1775
|
-
if (ctx.file.isVueSfc && !ctx.helpers.isLikelyEventHandler(ctx.file.text, node.start)) report(ctx, node, "nuxt/routing/no-router-navigation-in-setup", "warn", "routing", `${ctx.helpers.getCalleeName(node)}() appears to run during setup. Trigger navigation from a client event/lifecycle guard, route middleware, or use navigateTo() in universal contexts
|
|
1780
|
+
if (ctx.file.isVueSfc && !ctx.helpers.isLikelyEventHandler(ctx.file.text, node.start)) report(ctx, node, "nuxt/routing/no-router-navigation-in-setup", "warn", "routing", `${ctx.helpers.getCalleeName(node)}() appears to run during setup. Trigger navigation from a client event/lifecycle guard, route middleware, or use navigateTo() in universal contexts.`, "Move navigation into a client event, lifecycle guard, route middleware, or navigateTo().");
|
|
1776
1781
|
} };
|
|
1777
1782
|
}
|
|
1778
1783
|
});
|
|
@@ -1797,7 +1802,7 @@ const noSecretInPublicConfig = createRule({
|
|
|
1797
1802
|
if (node.type !== "Property") return;
|
|
1798
1803
|
const key = node.key?.name ?? node.key?.value;
|
|
1799
1804
|
if (typeof key === "string" && /(secret|token|password|private|key)$/i.test(key)) {
|
|
1800
|
-
if (ctx.file.text.slice(Math.max(0, node.start - 120), node.start).includes("public")) report(ctx, node, "nuxt/runtime/no-secret-in-public-config", "error", "runtime-config", `runtimeConfig.public.${key} looks sensitive and will be exposed to the client. Move it to private runtimeConfig.`);
|
|
1805
|
+
if (ctx.file.text.slice(Math.max(0, node.start - 120), node.start).includes("public")) report(ctx, node, "nuxt/runtime/no-secret-in-public-config", "error", "runtime-config", `runtimeConfig.public.${key} looks sensitive and will be exposed to the client. Move it to private runtimeConfig.`, `Move runtimeConfig.public.${key} to private runtimeConfig or remove the secret.`);
|
|
1801
1806
|
}
|
|
1802
1807
|
} };
|
|
1803
1808
|
}
|
|
@@ -1824,7 +1829,7 @@ const noBrowserSideEffectsInSetup = createRule({
|
|
|
1824
1829
|
if (name && BROWSER_SIDE_EFFECTS.has(name)) {
|
|
1825
1830
|
if (ctx.helpers.isTypeOnlyContext(node)) return;
|
|
1826
1831
|
if (ctx.helpers.isClientOnlyExecutionContext(node, ctx.file.text)) return;
|
|
1827
|
-
report(ctx, node, "nuxt/hydration/no-browser-side-effects-in-setup", "error", "hydration", `${name} is a browser-only side effect in universal code. Move it to onMounted() or a client-only plugin.`);
|
|
1832
|
+
report(ctx, node, "nuxt/hydration/no-browser-side-effects-in-setup", "error", "hydration", `${name} is a browser-only side effect in universal code. Move it to onMounted() or a client-only plugin.`, `Move ${name} into onMounted(), a client-only plugin, or a client-only execution branch.`);
|
|
1828
1833
|
}
|
|
1829
1834
|
} };
|
|
1830
1835
|
}
|
|
@@ -2419,7 +2424,7 @@ const noNonSerializableUseState = createRule({
|
|
|
2419
2424
|
if (!ctx.helpers.isCall(node, "useState")) return;
|
|
2420
2425
|
if (!evidence.isPayloadSerialized(node)) return;
|
|
2421
2426
|
const init = node.arguments?.[1];
|
|
2422
|
-
if (init && hasNonSerializableUseStateValue(init, ctx.file.text)) report(ctx, node, "nuxt/state/no-nonserializable-usestate", "error", "hydration", "useState() is serialized between server and client. Do not store functions, sockets, classes, Map/Set, or other non-serializable values.");
|
|
2427
|
+
if (init && hasNonSerializableUseStateValue(init, ctx.file.text)) report(ctx, node, "nuxt/state/no-nonserializable-usestate", "error", "hydration", "useState() is serialized between server and client. Do not store functions, sockets, classes, Map/Set, or other non-serializable values.", "Store only JSON-serializable values in useState(), or keep live objects outside payload state.");
|
|
2423
2428
|
} };
|
|
2424
2429
|
}
|
|
2425
2430
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as defineRulePack, l as createRule, o as defineDoctorDiagnostics } from "./core-WTY_jAiL.mjs";
|
|
2
2
|
import { dirname, resolve } from "pathe";
|
|
3
3
|
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
4
4
|
import { glob } from "node:fs/promises";
|
package/dist/rules.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { S as noUnusedDefine, _ as noUntypedEnv, a as noBroadFsAllow, b as noSecretDefine, c as noDynamicWorkerUrl, d as noDynamicNewUrl, f as noPublicSrcImport, g as noEmptyEnvPrefix, h as noClientSecretPattern, i as requirePluginName, l as noNodeApiInWorker, m as noBroadEnvPrefix, n as preferTransformFilter, o as noDisabledFsStrict, p as noSrcAbsolutePublicUrl, r as requireDisposeForSideEffects, s as noBrowserGlobalInSsrEntry, t as viteRulePack, u as requireWorkerUrlPattern, v as preferDirectImportMetaEnvAccess, x as noUntypedDefine, y as noRuntimeObjectDefine } from "./rules-
|
|
2
|
-
import "./rules-
|
|
1
|
+
import { S as noUnusedDefine, _ as noUntypedEnv, a as noBroadFsAllow, b as noSecretDefine, c as noDynamicWorkerUrl, d as noDynamicNewUrl, f as noPublicSrcImport, g as noEmptyEnvPrefix, h as noClientSecretPattern, i as requirePluginName, l as noNodeApiInWorker, m as noBroadEnvPrefix, n as preferTransformFilter, o as noDisabledFsStrict, p as noSrcAbsolutePublicUrl, r as requireDisposeForSideEffects, s as noBrowserGlobalInSsrEntry, t as viteRulePack, u as requireWorkerUrlPattern, v as preferDirectImportMetaEnvAccess, x as noUntypedDefine, y as noRuntimeObjectDefine } from "./rules-cyFhFs4w.mjs";
|
|
2
|
+
import "./rules-BGjZej-N.mjs";
|
|
3
3
|
export { noBroadEnvPrefix, noBroadFsAllow, noBrowserGlobalInSsrEntry, noClientSecretPattern, noDisabledFsStrict, noDynamicNewUrl, noDynamicWorkerUrl, noEmptyEnvPrefix, noNodeApiInWorker, noPublicSrcImport, noRuntimeObjectDefine, noSecretDefine, noSrcAbsolutePublicUrl, noUntypedDefine, noUntypedEnv, noUnusedDefine, preferDirectImportMetaEnvAccess, preferTransformFilter, requireDisposeForSideEffects, requirePluginName, requireWorkerUrlPattern, viteRulePack };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-doctor",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Small Vite Doctor CLI for project diagnostics.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"eslint": "^10.4.1",
|
|
56
56
|
"eslint-plugin-vue": "^10.9.1",
|
|
57
57
|
"magic-string": "^0.30.21",
|
|
58
|
-
"nostics": "0.
|
|
58
|
+
"nostics": "0.5.0",
|
|
59
59
|
"oxc-parser": "^0.133.0",
|
|
60
60
|
"pathe": "^2.0.3",
|
|
61
61
|
"picocolors": "^1.1.1",
|
package/dist/nitro-CFxa1y5r.mjs
DELETED
package/dist/rules-8_T4dDGE.mjs
DELETED