fix: read the oxlint config, and run the rule it declares - #2432
fix: read the oxlint config, and run the rule it declares#2432mhalikosen wants to merge 2 commits into
Conversation
oxlint auto-discovers .oxlintrc.json, .oxlintrc.jsonc, oxlint.config.ts and oxlint.config.mts. It does not look for oxlint.json, so the file this repository ships, both at its own root and into every generated project, is never read: a rule added to it changes nothing and reports no error. Renaming it is the whole fix, and nestjs/nest already uses .oxlintrc.json. The build needs no change, since cpx already copies dotfiles under files/ for .prettierrc. no-floating-promises needs a second fix on top of that. It is a type-aware rule, oxlint reads types only through oxlint-tsgolint, and neither that package nor --type-aware was present, so the rule was skipped in silence. Both are added here, and the level moves from warn to error, because oxlint exits 0 on warnings and a warn-level rule cannot fail the script it is declared in. $schema pointed at crates/oxc_linter/src/rules.rs, a Rust source file rather than a JSON schema, and now points at ./node_modules/oxlint/configuration_schema.json, which is what the oxlint documentation and nestjs/nest both use. Rule names take oxlint's own typescript/ prefix with it. Verified against a project generated from this branch, with an unawaited bootstrap() in main.ts: npm run lint exits 0 and prints nothing on master, exits 0 with the config renamed but no type information available, and exits 1 naming main.ts:8 once both halves are in place.
Raising no-floating-promises to error is only honest if the code this schematic writes can pass it, and the CommonJS main.ts could not: it ends in a bare bootstrap(), which is the exact call the rule exists to catch. Generated as it stood, npm run lint failed on an untouched project. void is the fix rather than .catch(console.error), and the difference matters. void changes nothing at runtime; it is the acknowledgement the rule asks for, and a rejected bootstrap still takes the process down. A catch handler would swallow that and leave a half-started application running, which is the objection raised against exactly that suggestion in nestjs/nest#14965. The ESM template already passes, because top-level await let it write await bootstrap(). This gives the CommonJS one the same property by the only means it has. Verified by generating both, installing, and linting: cjs and esm each exit 0 with nothing reported.
|
Pushed a second commit, because the first one had a hole I only found afterwards. Raising The CommonJS template now writes
That issue is worth reading next to this PR, since it is the same rule and the same line. In April 2025 someone reported that Both templates now generate, install and lint clean:
If you would rather leave |
PR Checklist
The existing tests in
application.factory.test.tsalready assert the generated file list and read the config back, so they cover the rename; they are updated to the new name rather than duplicated.PR Type
What is the current behavior?
Issue Number: #2431
oxlint.jsonis never read. oxlint auto-discovers.oxlintrc.json,.oxlintrc.jsonc,oxlint.config.tsandoxlint.config.mts;oxlint.jsonis not one of them, and the generatedlintscript passes no-c. Every generated project therefore ships a lint config with no effect, and so does this repository at its own root.no-floating-promisescould not run even if the file were read: it is type-aware, oxlint reads types only throughoxlint-tsgolint, and neither that package nor--type-awarewas present.$schemapointed at a Rust source file rather than a JSON schema.What is the new behavior?
oxlint.jsonbecomes.oxlintrc.json, in the two application templates and at this repository's root.$schemabecomes./node_modules/oxlint/configuration_schema.json, and rule names take oxlint's owntypescript/prefix. Both matchnestjs/nest's own.oxlintrc.json.oxlint-tsgolintis added to the templates'devDependenciesandlintbecomesoxlint --type-aware src/ test/, which is what makesno-floating-promisesactually run.warntoerror. oxlint exits 0 on warnings, so atwarnit would report an unawaitedbootstrap()and still leave the command green.The build is untouched:
copy:libalready copies dotfiles underfiles/, which is how.prettierrcreaches generated projects today. Confirmed indistafternpm run build.If you would rather not add a dependency, the other coherent option is to drop
no-floating-promisesfrom the template, which is whatnestjs/nestdoes for itself. I kept it because it is the only mistake the scaffold currently claims to catch, but say the word and I will cut that half; the rename stands on its own either way.Does this PR introduce a breaking change?
Existing projects are untouched. A project generated after this change gets a config that works, where before it got one that did nothing.
Other information
Verified on oxlint 1.80.0 against a project generated from this branch, with an unawaited
bootstrap()inmain.ts:npm run lintsrc/main.ts:8:1 error typescript(no-floating-promises)The middle row is why both halves are here; neither alone changes the outcome.
npm run lint,npm run typecheckandnpm testall pass on this branch, 730 tests in 42 files. Node 24.18.0, macOS.