check: JSON imports are data, not modules #2

Merged
sionzee merged 1 commit from fix/json-imports into main 2026-11-03 21:45:45 +01:00
Owner

What

safe-ts check <entry> reported a parse-error inside any .json file the program imports
(import data from "./x.json" with { type: "json" }): the module graph resolved the import to the
file and parsed it as TypeScript.

Project::resolve now only returns code files (ts, tsx, mts, cts, js, jsx, mjs,
cjs, vue). JSON modules and other assets (CSS, images) are treated as data: they aren't
analyzed or followed. That one function is used by the module graph, the editor path's lazy
loading, import resolution and type lookups, so all of them skip the file. Dependency inference
(infer.rs) already filtered by extension the same way.

Tests

  • New fixture crates/safe_ts_core/tests/fixtures/json_imports (imports data.json with
    with { type: "json" }, expects no diagnostics). Before the fix it fails with
    data.json:1 parse-error; after the fix it passes.
  • ./target/release/safe-ts check crates/safe_ts_core/tests/fixtures/json_imports/main.ts:
    before, 1 problem (the parse-error); after, no problems.
  • cargo nextest run: 94/95 pass. The one failure, fixtures_match_annotations on the
    features fixture (main.ts:55, unexpected unhandled-failure for createDecipheriv()),
    also fails on unmodified main (0e01fb3) and has nothing to do with this change.
  • npm run test:vite: passes.
  • npm run test:std: 115/116. The one failure, every Node callable is mapped exactly once, also
    fails on main here (local Node is v26.13.0, so the API list differs) and is unrelated.

Not covered

  • Names imported from a JSON module are now unknown to the checker (as before for anything it
    couldn't resolve). They are plain data and can't fail, so nothing is lost there.

🤖 Generated with Claude Code

## What `safe-ts check <entry>` reported a `parse-error` inside any `.json` file the program imports (`import data from "./x.json" with { type: "json" }`): the module graph resolved the import to the file and parsed it as TypeScript. `Project::resolve` now only returns code files (`ts`, `tsx`, `mts`, `cts`, `js`, `jsx`, `mjs`, `cjs`, `vue`). JSON modules and other assets (CSS, images) are treated as data: they aren't analyzed or followed. That one function is used by the module graph, the editor path's lazy loading, import resolution and type lookups, so all of them skip the file. Dependency inference (`infer.rs`) already filtered by extension the same way. ## Tests - New fixture `crates/safe_ts_core/tests/fixtures/json_imports` (imports `data.json` with `with { type: "json" }`, expects no diagnostics). Before the fix it fails with `data.json:1 parse-error`; after the fix it passes. - `./target/release/safe-ts check crates/safe_ts_core/tests/fixtures/json_imports/main.ts`: before, 1 problem (the parse-error); after, no problems. - `cargo nextest run`: 94/95 pass. The one failure, `fixtures_match_annotations` on the **`features`** fixture (`main.ts:55`, unexpected `unhandled-failure` for `createDecipheriv()`), also fails on unmodified `main` (0e01fb3) and has nothing to do with this change. - `npm run test:vite`: passes. - `npm run test:std`: 115/116. The one failure, `every Node callable is mapped exactly once`, also fails on `main` here (local Node is v26.13.0, so the API list differs) and is unrelated. ## Not covered - Names imported from a JSON module are now unknown to the checker (as before for anything it couldn't resolve). They are plain data and can't fail, so nothing is lost there. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
`safe-ts check` followed `import data from "./x.json" with { type: "json" }`
into the JSON file and parsed it as TypeScript, which reported a parse-error
in every imported .json. The project resolver now only hands back code files
(ts/tsx/mts/cts/js/jsx/mjs/cjs/vue); JSON, stylesheets and other assets are
neither analyzed nor followed. The `json_imports` fixture reproduces it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
sionzee deleted branch fix/json-imports 2026-11-03 21:45:45 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Evobug/Safe-Ts!2
No description provided.