Environment
wormajs@0.2.5
- macOS (also reproducible on Linux)
- Using
alova() plugin with swagger() input, typescript template
Steps to reproduce
- Start a backend that serves an OpenAPI 3.1 spec at
http://localhost:3000/openapi.json
- Run
npx wormajs gen -p . with output src/api/generated
- Run
vue-tsc --noEmit (or tsc --noEmit) against the generated code
Expected behavior
Generated .ts files use LF line endings, and JSDoc comments contain no characters that trip the TypeScript lexer. TypeScript compilation should pass cleanly.
Actual behavior
Generated .ts files contain \r\n (CRLF) line endings. Combined with the alova's apostrophe in the JSDoc header:
* NOTE: This file is auto generated by the alova's vscode plugin.
vue-tsc reports errors like:
src/api/generated/services/ping.ts(11,8): error TS1005: ';' expected.
src/api/generated/services/ping.ts(11,67): error TS1002: Unterminated string literal.
src/api/generated/services/ping.ts(13,2): error TS1109: Expression expected.
Root cause analysis
Two separate issues that compound each other:
1. CRLF from endOfLine: 'auto' in utils/format.js
// utils/format.js:51
endOfLine: 'auto',
When prettier's endOfLine is set to 'auto', and the template content or runtime environment triggers CRLF detection, generated files contain \r\n. The TypeScript compiler and vue-tsc handle CRLF inconsistently when mixed with certain characters in JSDoc.
Notably, /core/loader/callingCodeLoader/index.js:31 already uses endOfLine: 'lf' — this should be the default everywhere for code generation output.
2. Apostrophe in comment.handlebars
<!-- template/presets/alova/partials/comment.handlebars:14 -->
* NOTE: This file is auto generated by the alova's vscode plugin.
The alova's apostrophe, when inside a multi-line JSDoc comment with CRLF line endings, causes the TypeScript lexer to go into an error state (it appears to interpret the ' as a string delimiter).
The same apostrophe appears in other preset partials (alova-globals, fetch, axios, ky).
Proposed fix
Fix 1 — utils/format.js
Change endOfLine: 'auto' → endOfLine: 'lf'
This forces all generated code to use consistent LF line endings regardless of OS.
Fix 2 — comment.handlebars (all presets)
Change the alova's vscode plugin → the alova team (https://alova.js.org) or simply remove the apostrophe:
- * NOTE: This file is auto generated by the alova's vscode plugin.
+ * NOTE: This file is auto generated by the alova team (https://alova.js.org).
This is cleaner and avoids the apostrophe entirely. It also keeps the attribution while using a URL users can actually visit (the current text references "vscode plugin" which doesn't tell users where to find more info).
Affected files
packages/wormajs/src/utils/format.ts (source) → dist/utils/format.js
packages/wormajs/src/template/presets/alova/partials/comment.handlebars
packages/wormajs/src/template/presets/alova-globals/partials/comment.handlebars
packages/wormajs/src/template/presets/fetch/partials/comment.handlebars
packages/wormajs/src/template/presets/axios/partials/comment.handlebars
packages/wormajs/src/template/presets/ky/partials/comment.handlebars
Happy to submit a PR for both fixes.
Environment
wormajs@0.2.5alova()plugin withswagger()input,typescripttemplateSteps to reproduce
http://localhost:3000/openapi.jsonnpx wormajs gen -p .with outputsrc/api/generatedvue-tsc --noEmit(ortsc --noEmit) against the generated codeExpected behavior
Generated
.tsfiles use LF line endings, and JSDoc comments contain no characters that trip the TypeScript lexer. TypeScript compilation should pass cleanly.Actual behavior
Generated
.tsfiles contain\r\n(CRLF) line endings. Combined with thealova'sapostrophe in the JSDoc header:vue-tsc reports errors like:
Root cause analysis
Two separate issues that compound each other:
1. CRLF from
endOfLine: 'auto'inutils/format.jsWhen prettier's
endOfLineis set to'auto', and the template content or runtime environment triggers CRLF detection, generated files contain\r\n. The TypeScript compiler and vue-tsc handle CRLF inconsistently when mixed with certain characters in JSDoc.Notably,
/core/loader/callingCodeLoader/index.js:31already usesendOfLine: 'lf'— this should be the default everywhere for code generation output.2. Apostrophe in
comment.handlebars<!-- template/presets/alova/partials/comment.handlebars:14 --> * NOTE: This file is auto generated by the alova's vscode plugin.The
alova'sapostrophe, when inside a multi-line JSDoc comment with CRLF line endings, causes the TypeScript lexer to go into an error state (it appears to interpret the'as a string delimiter).The same apostrophe appears in other preset partials (alova-globals, fetch, axios, ky).
Proposed fix
Fix 1 —
utils/format.jsChange
endOfLine: 'auto'→endOfLine: 'lf'This forces all generated code to use consistent LF line endings regardless of OS.
Fix 2 —
comment.handlebars(all presets)Change
the alova's vscode plugin→the alova team (https://alova.js.org)or simply remove the apostrophe:This is cleaner and avoids the apostrophe entirely. It also keeps the attribution while using a URL users can actually visit (the current text references "vscode plugin" which doesn't tell users where to find more info).
Affected files
packages/wormajs/src/utils/format.ts(source) →dist/utils/format.jspackages/wormajs/src/template/presets/alova/partials/comment.handlebarspackages/wormajs/src/template/presets/alova-globals/partials/comment.handlebarspackages/wormajs/src/template/presets/fetch/partials/comment.handlebarspackages/wormajs/src/template/presets/axios/partials/comment.handlebarspackages/wormajs/src/template/presets/ky/partials/comment.handlebarsHappy to submit a PR for both fixes.