import-attributes: find the assert keyword, so the rule fires #4
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/import-attributes"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
The
import-attributesrule never fired. It checkedtext(with_clause.span).starts_with("assert"),but oxc's
WithClause.spanstarts at the{(the parser advances past the keyword beforerecording the start; see
parse_import_attributesin oxc_parser 0.156), so the text always beganwith
{.lints.rs: the keyword is now looked up between the end of the module specifier and the{,and the diagnostic and quick fix (Use
with) cover exactly theassertkeyword.export { x } from "./a.json" assert { … },export * from "./a.json" assert { … }), which hit the same problem.Why the tests didn't catch it
Nothing tested the rule. No fixture or fix test used
assert, and the rule page's examples wereplain
```tsblocks (not checked), becausescripts/docs-typecheck.mjscompiles everychecked block with tsc and TypeScript rejects
assert.To close that gap:
no-tscword (```ts bad import-attributes no-tsc).docs.rsstill checks it with safe-ts;
docs-typecheck.mjsleaves it out of the tsc compile.docs/rules/import-attributes.mdnow uses checked examples (the import and the re-export asbad,
withas good), and says what the rule can't see (dynamicimport(…, { assert: … })).tests/fixes.rs:import_assertions_become_import_attributeschecks the rule fires on import,export … fromandexport *withassert, not onwith, and checks the exact result ofthe fix.
Both new checks fail without the fix: the fix test fails its
assert_eq, and the docs testreports
rules/import-attributes.md:10 expected {"import-attributes"}, got {}.Tests
cargo nextest run: 95/96 pass. The one failure,fixtures_match_annotationson thefeaturesfixture (main.ts:55, unexpectedunhandled-failureforcreateDecipheriv()),also fails on unmodified
main(0e01fb3) and is unrelated.npm run test:docs(docs typecheck: 213 examples compile, wasm build, VitePress build): passes.Not covered
import("./x.json", { assert: { type: "json" } }). The rule page says so.🤖 Generated with Claude Code
assertkeyword, so the rule fires 23019a4a95oxc's `WithClause.span` starts at the `{`, after the keyword, so checking that the clause's text starts with "assert" never matched and the rule was dead. The keyword is now looked up between the module specifier and the brace, and re-exports (`export … from "./x.json" assert { … }`) are checked too. Nothing caught it because nothing tested it: no fixture or fix test used `assert`, and the rule page's examples were plain blocks, since tsc rejects the syntax. Doc blocks can now say `no-tsc` to stay checked by safe-ts but out of the tsc compile; the page uses that, and a fix test covers the quick fix. Co-Authored-By: Claude Opus 5.5 <[email protected]>