@nifrajs/cli 5.6.0 → 5.7.0
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/CHANGELOG.md +159 -0
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +4 -0
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan.d.ts +6 -0
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +1 -30
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +35 -12
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts +4 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +53 -5
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts +5 -0
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +18 -6
- package/dist/command-catalog.js.map +1 -1
- package/dist/contracts.d.ts +42 -4
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +288 -9
- package/dist/contracts.js.map +1 -1
- package/dist/doctor.d.ts +6 -4
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +20 -6
- package/dist/doctor.js.map +1 -1
- package/dist/internal/git-ignored.d.ts +12 -0
- package/dist/internal/git-ignored.d.ts.map +1 -0
- package/dist/internal/git-ignored.js +49 -0
- package/dist/internal/git-ignored.js.map +1 -0
- package/dist/internal/source-facts.d.ts +29 -0
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +160 -0
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/load.d.ts +4 -1
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +10 -0
- package/dist/load.js.map +1 -1
- package/dist/local-cli.d.ts +15 -0
- package/dist/local-cli.d.ts.map +1 -0
- package/dist/local-cli.js +74 -0
- package/dist/local-cli.js.map +1 -0
- package/dist/lock-links.d.ts +0 -7
- package/dist/lock-links.d.ts.map +1 -1
- package/dist/lock-links.js +5 -44
- package/dist/lock-links.js.map +1 -1
- package/dist/mcp-delegate.d.ts +13 -5
- package/dist/mcp-delegate.d.ts.map +1 -1
- package/dist/mcp-delegate.js +24 -8
- package/dist/mcp-delegate.js.map +1 -1
- package/dist/mcp-http.js +1 -1
- package/dist/openapi-types.d.ts.map +1 -1
- package/dist/openapi-types.js +45 -2
- package/dist/openapi-types.js.map +1 -1
- package/dist/recipes/5.7.0.d.ts +12 -0
- package/dist/recipes/5.7.0.d.ts.map +1 -0
- package/dist/recipes/5.7.0.js +70 -0
- package/dist/recipes/5.7.0.js.map +1 -0
- package/dist/recipes/index.d.ts +13 -0
- package/dist/recipes/index.d.ts.map +1 -1
- package/dist/recipes/index.js +2 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +2 -0
- package/dist/review.js.map +1 -1
- package/dist/rules/codes.d.ts +2 -0
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +2 -0
- package/dist/rules/codes.js.map +1 -1
- package/dist/rules/explanations.d.ts.map +1 -1
- package/dist/rules/explanations.js +13 -3
- package/dist/rules/explanations.js.map +1 -1
- package/dist/rules/legacy.js +1 -1
- package/dist/rules/legacy.js.map +1 -1
- package/dist/rules/text-slot-boolean.d.ts +8 -0
- package/dist/rules/text-slot-boolean.d.ts.map +1 -0
- package/dist/rules/text-slot-boolean.js +57 -0
- package/dist/rules/text-slot-boolean.js.map +1 -0
- package/dist/rules/undeclared-response.d.ts +9 -0
- package/dist/rules/undeclared-response.d.ts.map +1 -0
- package/dist/rules/undeclared-response.js +93 -0
- package/dist/rules/undeclared-response.js.map +1 -0
- package/dist/upgrade.d.ts +34 -8
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +197 -25
- package/dist/upgrade.js.map +1 -1
- package/dist/version-drift.js +1 -1
- package/dist/version-drift.js.map +1 -1
- package/dist/web-app-options.d.ts +1 -1
- package/dist/web-app-options.d.ts.map +1 -1
- package/dist/web-app-options.js.map +1 -1
- package/docs/examples.json +7 -1
- package/docs/llms-full.txt +441 -105
- package/docs/types.json +164 -43
- package/package.json +11 -11
- package/src/check-diagnostics.ts +4 -0
- package/src/check-scan.ts +1 -29
- package/src/check.ts +32 -10
- package/src/cli.ts +58 -5
- package/src/command-catalog.ts +23 -6
- package/src/contracts.ts +348 -14
- package/src/doctor.ts +28 -12
- package/src/internal/git-ignored.ts +47 -0
- package/src/internal/source-facts.ts +198 -0
- package/src/load.ts +16 -0
- package/src/local-cli.ts +83 -0
- package/src/lock-links.ts +5 -43
- package/src/mcp-delegate.ts +30 -9
- package/src/mcp-http.ts +1 -1
- package/src/openapi-types.ts +43 -2
- package/src/recipes/5.7.0.ts +72 -0
- package/src/recipes/index.ts +16 -0
- package/src/review.ts +2 -0
- package/src/rules/codes.ts +2 -0
- package/src/rules/explanations.ts +13 -3
- package/src/rules/legacy.ts +1 -1
- package/src/rules/text-slot-boolean.ts +56 -0
- package/src/rules/undeclared-response.ts +92 -0
- package/src/upgrade.ts +229 -33
- package/src/version-drift.ts +1 -1
- package/src/web-app-options.ts +1 -0
package/src/recipes/index.ts
CHANGED
|
@@ -18,6 +18,7 @@ import { recipe as v5_3_0 } from "./5.3.0.ts"
|
|
|
18
18
|
import { recipe as v5_4_0 } from "./5.4.0.ts"
|
|
19
19
|
import { recipe as v5_5_0 } from "./5.5.0.ts"
|
|
20
20
|
import { recipe as v5_6_0 } from "./5.6.0.ts"
|
|
21
|
+
import { recipe as v5_7_0 } from "./5.7.0.ts"
|
|
21
22
|
|
|
22
23
|
/** A pin rule: every dependency whose name starts with `match` is set to version `to`. */
|
|
23
24
|
export interface PinRule {
|
|
@@ -34,6 +35,19 @@ export interface DependencyMove {
|
|
|
34
35
|
readonly toVersion: string
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
/**
|
|
39
|
+
* A package an import needs that a project may only have had through another package. When a source
|
|
40
|
+
* file imports one of `imports`, or a subpath of one, and the nearest package.json lists `add` in no
|
|
41
|
+
* dependency field, the upgrade adds it at the target version beside the imported package, or beside
|
|
42
|
+
* one of `beside` when the imported package is not listed there.
|
|
43
|
+
*/
|
|
44
|
+
export interface DependencyAdd {
|
|
45
|
+
/** Import specifiers, matched after the release's import moves. */
|
|
46
|
+
readonly imports: readonly string[]
|
|
47
|
+
readonly add: string
|
|
48
|
+
readonly beside?: readonly string[]
|
|
49
|
+
}
|
|
50
|
+
|
|
37
51
|
/** An exact import-specifier rewrite (string-level, not AST): `from` → `to`. */
|
|
38
52
|
export interface ImportMove {
|
|
39
53
|
readonly from: string
|
|
@@ -52,6 +66,7 @@ export interface UpgradeRecipe {
|
|
|
52
66
|
readonly pins: readonly PinRule[]
|
|
53
67
|
readonly dependencyMoves?: readonly DependencyMove[]
|
|
54
68
|
readonly importMoves: readonly ImportMove[]
|
|
69
|
+
readonly dependencyAdds?: readonly DependencyAdd[]
|
|
55
70
|
readonly retiredMarkers?: readonly RetiredMarker[]
|
|
56
71
|
/** Human notes printed after the plan - e.g. structural changes the runner deliberately can't do. */
|
|
57
72
|
readonly notes?: readonly string[]
|
|
@@ -76,6 +91,7 @@ const RECIPES: Record<string, UpgradeRecipe> = {
|
|
|
76
91
|
[v5_4_0.version]: v5_4_0,
|
|
77
92
|
[v5_5_0.version]: v5_5_0,
|
|
78
93
|
[v5_6_0.version]: v5_6_0,
|
|
94
|
+
[v5_7_0.version]: v5_7_0,
|
|
79
95
|
}
|
|
80
96
|
|
|
81
97
|
export function getRecipe(version: string): UpgradeRecipe | undefined {
|
package/src/review.ts
CHANGED
|
@@ -162,6 +162,8 @@ export const CHECK_CODES: Readonly<Record<string, ReviewCheckId>> = {
|
|
|
162
162
|
"NF-C043": "security",
|
|
163
163
|
"NF-C044": "route-boundary",
|
|
164
164
|
"NF-C045": "typed-client",
|
|
165
|
+
"NF-C054": "typed-client",
|
|
166
|
+
"NF-C055": "route-boundary",
|
|
165
167
|
"NF-C046": "dependency",
|
|
166
168
|
"NF-D001": "dependency",
|
|
167
169
|
"NF-D002": "dependency",
|
package/src/rules/codes.ts
CHANGED
|
@@ -52,6 +52,8 @@ export const RULE_CODES = Object.freeze({
|
|
|
52
52
|
"NF-C051": "Slot content is not its slot() alone",
|
|
53
53
|
"NF-C052": "Swap URL's page renders no such slot",
|
|
54
54
|
"NF-C053": "Partially prerendered page reads the request",
|
|
55
|
+
"NF-C054": "Route without a response schema in a published document",
|
|
56
|
+
"NF-C055": "zod coerce.boolean() reads request text",
|
|
55
57
|
"NF-D001": "Doctor check",
|
|
56
58
|
"NF-D002": "Mixed nifra versions",
|
|
57
59
|
"NF-D003": "Stale file: dependencies in bun.lock",
|
|
@@ -46,7 +46,7 @@ export const RULE_EXPLANATIONS: Readonly<Record<BuiltInCode, RuleExplanation>> =
|
|
|
46
46
|
},
|
|
47
47
|
"NF-C007": {
|
|
48
48
|
why: "A route handler returns a raw Response, so the typed client infers `data: never` and drift detection is lost for that route.",
|
|
49
|
-
fix: "Return a plain object (set status, headers and cookies on c.set), use app.sse() for a stream, or declare `{ response: t.... }
|
|
49
|
+
fix: "Return a plain object (set status, headers and cookies on c.set), use app.sse() for a stream, `bytes()` from @nifrajs/core/binary for a file or other binary body, or `raw<T>(response)` from the same module for a hand-built JSON Response; or declare `{ response: t.... }`. Mark an intended redirect with `// nifra-expect NF-C007: <reason>`.",
|
|
50
50
|
docs: "/docs/api",
|
|
51
51
|
},
|
|
52
52
|
"NF-C008": {
|
|
@@ -279,6 +279,16 @@ export const RULE_EXPLANATIONS: Readonly<Record<BuiltInCode, RuleExplanation>> =
|
|
|
279
279
|
command: "nifra fix --code NF-C053",
|
|
280
280
|
docs: "/docs/partial-prerendering",
|
|
281
281
|
},
|
|
282
|
+
"NF-C054": {
|
|
283
|
+
why: "The project builds an OpenAPI document from its running routes (openapi(), buildOpenApiDocument or toOpenAPI), and a route declares no response schema. The document can only say it answers 200, so a client generated from it, in any language, has no type for the body. nifra's typed client is unaffected: it reads the handler's TypeScript type.",
|
|
284
|
+
fix: "Declare `{ response: ... }` on the route, or build the document with `nifra openapi`, which reads each handler's return type. A route kept out on purpose takes `// nifra-expect NF-C054: <reason>` above the registration.",
|
|
285
|
+
docs: "/docs/api",
|
|
286
|
+
},
|
|
287
|
+
"NF-C055": {
|
|
288
|
+
why: "zod's `z.coerce.boolean()` is `Boolean(value)`. A query, header or cookie value always arrives as text, so every non-empty value reads as true: `?archived=false` and `?archived=0` both do.",
|
|
289
|
+
fix: "Use `z.stringbool()`, which reads `true`/`1`/`yes`/`on` as true, `false`/`0`/`no`/`off` as false, and refuses other text. A use kept on purpose takes `// nifra-expect NF-C055: <reason>` above the call.",
|
|
290
|
+
docs: "/docs/api",
|
|
291
|
+
},
|
|
282
292
|
"NF-D001": {
|
|
283
293
|
why: "The doctor gate of `nifra assure` found an undeclared import or a package installed more than once.",
|
|
284
294
|
fix: "Run `nifra doctor` for the details and the fix of each finding.",
|
|
@@ -291,8 +301,8 @@ export const RULE_EXPLANATIONS: Readonly<Record<BuiltInCode, RuleExplanation>> =
|
|
|
291
301
|
docs: "/docs/troubleshooting#mixed-versions",
|
|
292
302
|
},
|
|
293
303
|
"NF-D003": {
|
|
294
|
-
why: "bun.lock records dependencies a file: package no longer declares. Bun never reads that package.json again, so it installs the recorded versions beside the declared ones.",
|
|
295
|
-
fix: "Run `bun update <package>` for each package the finding names
|
|
304
|
+
why: "bun.lock records dependencies a file: package no longer declares. Bun 1.4.2 never reads that package.json again, so it installs the recorded versions beside the declared ones.",
|
|
305
|
+
fix: "Run `bun update <package>` for each package the finding names: it refreshes those entries and keeps every other pin. Deleting an entry by hand makes the next install re-resolve the whole lock.",
|
|
296
306
|
docs: "/docs/troubleshooting#stale-file-links",
|
|
297
307
|
},
|
|
298
308
|
"NF-A001": {
|
package/src/rules/legacy.ts
CHANGED
|
@@ -104,7 +104,7 @@ const STREAM_HINT =
|
|
|
104
104
|
const SERVER_IMPORT_HINT =
|
|
105
105
|
"server-only code in browser code (a route's frontend half, frontend/ or shared/) - reach it from the route's backend half (x.backend.ts) or a *.fn.ts server function; a dynamic import() is bundled too"
|
|
106
106
|
const RESPONSE_ROUTE_HINT =
|
|
107
|
-
"route handler returns a raw Response - the typed client infers `data: never`, so drift detection is lost for this route. Return a plain object (it's serialized for you); for a stream use a typed SSE route (`app.sse(...)`), which keeps typed events; or,
|
|
107
|
+
"route handler returns a raw Response - the typed client infers `data: never`, so drift detection is lost for this route. Return a plain object (it's serialized for you); for a stream use a typed SSE route (`app.sse(...)`), which keeps typed events; for a file or other binary body return `bytes(body, { type, filename })` from @nifrajs/core/binary (the client reads it as a Blob); for a Response you must build yourself, wrap it as `raw<T>(response)` from the same module to keep `data` typed. For a redirect, add `{ response: t.… }` or a `// nifra-expect NF-C007: <reason>` comment to mark it and silence this"
|
|
108
108
|
const PIPELINE_DOC_HINT =
|
|
109
109
|
"nifra runs one bundler per phase - `vitePlugins` feed Vite, `clientPlugins`/`serverPlugins` feed Bun, and the file `nifra build` imports the adapter from is bundled into the server. See the Gotchas section of the Dev & HMR guide."
|
|
110
110
|
const UNDECLARED_DEP_HINT =
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type Diagnostic, diagnostic } from "../diagnostics.ts"
|
|
2
|
+
import { createSourceFacts } from "../internal/source-facts.ts"
|
|
3
|
+
import { commentBlockExpectation } from "./comment-markers.ts"
|
|
4
|
+
import type { CheckRule } from "./index.ts"
|
|
5
|
+
import { loadRuleTypeScript } from "./typescript.ts"
|
|
6
|
+
|
|
7
|
+
const TEXT_SLOT_BOOLEAN_EXPECTATION = ["NF-C055", "text-slot-boolean"]
|
|
8
|
+
const ZOD_IMPORT = /from\s+["']zod(?:\/v4)?(?:\/mini)?["']/
|
|
9
|
+
const VALUE_IN = { query: "query", headers: "header", cookies: "cookie" } as const
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* NF-C055: a zod `z.coerce.boolean()` in a route's `query`, `headers` or `cookies` schema. It is
|
|
13
|
+
* `Boolean(value)`, and those values always arrive as text, so every non-empty value reads as `true`:
|
|
14
|
+
* `?archived=false` and `?archived=0` both do. `z.stringbool()` reads the words a request sends.
|
|
15
|
+
*/
|
|
16
|
+
export const textSlotBooleanRule: CheckRule = {
|
|
17
|
+
code: "NF-C055",
|
|
18
|
+
title: "zod coerce.boolean() reads request text",
|
|
19
|
+
async scan(ctx) {
|
|
20
|
+
const loaded = await loadRuleTypeScript(ctx)
|
|
21
|
+
if (loaded.diagnostics !== undefined) return loaded.diagnostics
|
|
22
|
+
const ts = loaded.compiler
|
|
23
|
+
if (ts === undefined) return []
|
|
24
|
+
const facts = createSourceFacts(ts)
|
|
25
|
+
const findings: Diagnostic[] = []
|
|
26
|
+
for (const file of ctx.project.source.files) {
|
|
27
|
+
if (!/\.[cm]?tsx?$/.test(file)) continue
|
|
28
|
+
const text = ctx.project.source.read(file)
|
|
29
|
+
if (text === undefined || !text.includes("coerce") || !ZOD_IMPORT.test(text)) continue
|
|
30
|
+
const tree = facts.parse(file, text)
|
|
31
|
+
if (tree === undefined) continue
|
|
32
|
+
const lines = text.split("\n")
|
|
33
|
+
for (const found of facts.textSlotBooleanCoercions(tree)) {
|
|
34
|
+
const line = tree.getLineAndCharacterOfPosition(found.position).line + 1
|
|
35
|
+
if (commentBlockExpectation(lines, line, TEXT_SLOT_BOOLEAN_EXPECTATION) !== undefined)
|
|
36
|
+
continue
|
|
37
|
+
findings.push(
|
|
38
|
+
diagnostic({
|
|
39
|
+
code: "NF-C055",
|
|
40
|
+
severity: "warn",
|
|
41
|
+
file,
|
|
42
|
+
line,
|
|
43
|
+
message: `\`coerce.boolean()\` in the \`${found.slot}\` schema of ${found.method} ${found.path} reads every non-empty value as true, "false" and "0" included: a ${VALUE_IN[found.slot]} value is always text. Use \`z.stringbool()\`, which reads "false", "0", "no" and "off" as false and refuses text it does not know.`,
|
|
44
|
+
evidence: [
|
|
45
|
+
"zod's coerce.boolean() is Boolean(value): any non-empty string is true",
|
|
46
|
+
`${found.slot} values arrive as text, so "false" never reaches the schema as false`,
|
|
47
|
+
"a use kept on purpose: `// nifra-expect NF-C055: <reason>` above the call",
|
|
48
|
+
],
|
|
49
|
+
verify: "nifra check",
|
|
50
|
+
}),
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return findings
|
|
55
|
+
},
|
|
56
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type * as TSApi from "typescript"
|
|
2
|
+
import { type Diagnostic, diagnostic } from "../diagnostics.ts"
|
|
3
|
+
import { createSourceFacts } from "../internal/source-facts.ts"
|
|
4
|
+
import type { TypeScriptApi } from "../internal/typescript-import.ts"
|
|
5
|
+
import { commentBlockExpectation } from "./comment-markers.ts"
|
|
6
|
+
import type { CheckRule } from "./index.ts"
|
|
7
|
+
import { loadRuleTypeScript } from "./typescript.ts"
|
|
8
|
+
|
|
9
|
+
const UNDECLARED_RESPONSE_EXPECTATION = ["NF-C054", "undeclared-response"]
|
|
10
|
+
const SERVER_FACTORY = /(?<![.\w$])(?:server|createWebApp)\s*\(/
|
|
11
|
+
|
|
12
|
+
/** The imports that build an OpenAPI document from the running routes, by module. */
|
|
13
|
+
const DOCUMENT_BUILDERS: ReadonlyMap<string, ReadonlySet<string>> = new Map([
|
|
14
|
+
["@nifrajs/middleware", new Set(["openapi", "buildOpenApiDocument"])],
|
|
15
|
+
["@nifrajs/schema", new Set(["toOpenAPI", "toOpenAPIFromEvidence"])],
|
|
16
|
+
["@nifrajs/schema/openapi", new Set(["toOpenAPI", "toOpenAPIFromEvidence"])],
|
|
17
|
+
])
|
|
18
|
+
|
|
19
|
+
/** The first value import in `tree` of a builder in {@link DOCUMENT_BUILDERS}, as `name` from `module`. */
|
|
20
|
+
function documentBuilder(ts: TypeScriptApi, tree: TSApi.SourceFile): string | undefined {
|
|
21
|
+
for (const statement of tree.statements) {
|
|
22
|
+
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier))
|
|
23
|
+
continue
|
|
24
|
+
const names = DOCUMENT_BUILDERS.get(statement.moduleSpecifier.text)
|
|
25
|
+
const clause = statement.importClause
|
|
26
|
+
const bindings = clause?.namedBindings
|
|
27
|
+
if (names === undefined || clause?.isTypeOnly === true || bindings === undefined) continue
|
|
28
|
+
if (!ts.isNamedImports(bindings)) continue
|
|
29
|
+
for (const element of bindings.elements) {
|
|
30
|
+
const name = (element.propertyName ?? element.name).text
|
|
31
|
+
if (!element.isTypeOnly && names.has(name))
|
|
32
|
+
return `\`${name}\` from ${statement.moduleSpecifier.text}`
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return undefined
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* NF-C054: in a project that builds its OpenAPI document from the running routes (`openapi()`,
|
|
40
|
+
* `buildOpenApiDocument`, `toOpenAPI`), a route registered without a `response` schema. The document
|
|
41
|
+
* can only say such a route answers a generic `200`, so a client generated from it, in any language,
|
|
42
|
+
* gets no type for the body. The typed client is unaffected: it reads the handler's TypeScript type.
|
|
43
|
+
*/
|
|
44
|
+
export const undeclaredResponseRule: CheckRule = {
|
|
45
|
+
code: "NF-C054",
|
|
46
|
+
title: "Route without a response schema in a published document",
|
|
47
|
+
async scan(ctx) {
|
|
48
|
+
const loaded = await loadRuleTypeScript(ctx)
|
|
49
|
+
if (loaded.diagnostics !== undefined) return loaded.diagnostics
|
|
50
|
+
const ts = loaded.compiler
|
|
51
|
+
if (ts === undefined) return []
|
|
52
|
+
const facts = createSourceFacts(ts)
|
|
53
|
+
const sources: { file: string; text: string; tree: TSApi.SourceFile }[] = []
|
|
54
|
+
let builder: string | undefined
|
|
55
|
+
for (const file of ctx.project.source.files) {
|
|
56
|
+
if (!/\.[cm]?tsx?$/.test(file)) continue
|
|
57
|
+
const text = ctx.project.source.read(file)
|
|
58
|
+
const serves = text !== undefined && SERVER_FACTORY.test(text)
|
|
59
|
+
if (text === undefined || (!serves && !text.includes("@nifrajs/"))) continue
|
|
60
|
+
const tree = facts.parse(file, text)
|
|
61
|
+
if (tree === undefined) continue
|
|
62
|
+
builder ??= documentBuilder(ts, tree)
|
|
63
|
+
if (serves) sources.push({ file, text, tree })
|
|
64
|
+
}
|
|
65
|
+
if (builder === undefined) return []
|
|
66
|
+
const findings: Diagnostic[] = []
|
|
67
|
+
for (const { file, text, tree } of sources) {
|
|
68
|
+
const lines = text.split("\n")
|
|
69
|
+
for (const route of facts.undeclaredResponseRoutes(tree)) {
|
|
70
|
+
const line = tree.getLineAndCharacterOfPosition(route.position).line + 1
|
|
71
|
+
if (commentBlockExpectation(lines, line, UNDECLARED_RESPONSE_EXPECTATION) !== undefined)
|
|
72
|
+
continue
|
|
73
|
+
findings.push(
|
|
74
|
+
diagnostic({
|
|
75
|
+
code: "NF-C054",
|
|
76
|
+
severity: "info",
|
|
77
|
+
file,
|
|
78
|
+
line,
|
|
79
|
+
message: `${route.method} ${route.path} declares no \`response\` schema, so the OpenAPI document this project builds says only that it answers 200: a client generated from it gets no type for the body. Declare \`{ response: ... }\`, or generate the document with \`nifra openapi\`, which reads the handler's return type.`,
|
|
80
|
+
evidence: [
|
|
81
|
+
`the project builds its document from the running routes with ${builder}`,
|
|
82
|
+
"a route without a response schema is documented as a 200 with no body type",
|
|
83
|
+
"a route left out on purpose: `// nifra-expect NF-C054: <reason>` above the registration",
|
|
84
|
+
],
|
|
85
|
+
verify: "nifra check",
|
|
86
|
+
}),
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return findings
|
|
91
|
+
},
|
|
92
|
+
}
|