feat: format queries with @matdata/sparql-formatter (SPARQL 1.2) - #190
Conversation
Replace sparql-formatter with @matdata/sparql-formatter, which supports SPARQL 1.2 and keeps comments where they are (sparqling/sparql-formatter#30). The package is a drop-in replacement (same spfmt.format API) and ships its own types, so the local type declaration is removed. The stored formatter setting value stays "sparql-formatter"; only its label changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KSjgmmKydVPHYWjYDZgvQP
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
It swaps a user-facing feature to a brand-new external @matdata/sparql-formatter@1.0.0 with a hand-edited lockfile, and browser-bundle compatibility plus npm ci validation cannot be verified offline and warrant human confirmation.
Review effort: Balanced
Findings: None
What changed in this PR
This PR switches the SPARQL query formatter in @matdata/yasqe from the SPARQL 1.1-only sparql-formatter package to the SPARQL 1.2-capable @matdata/sparql-formatter. This improves the editor's formatting feature so SPARQL 1.2 constructs (triple terms, reifiers, annotations, VERSION, base direction) are formatted properly instead of falling back to the legacy formatter, and comments retain their position. The new package exposes the same spfmt.format(...) API, so the code impact is limited to a single import line plus dependency, settings-label, docs, and test updates.
Changes:
- Replace
sparql-formatter@^1.0.2with@matdata/sparql-formatter@^1.0.0(dependency + import) and delete the now-unneeded localsparql-formatter.d.ts(the new package ships its own types). - Relabel the settings option to "SPARQL 1.2 Formatter" while keeping the stored value
sparql-formatterfor backward compatibility; update user guide and add a changeset. - Add a browser test asserting exact SPARQL 1.2 formatting output including a comment preserved inside an empty
GRAPHblock, and prune the old package's 22 transitive deps from the lockfile.
| File | Description |
|---|---|
| packages/yasqe/src/index.ts | Import spfmt from @matdata/sparql-formatter; only spfmt.format is used. |
| packages/yasqe/src/sparql-formatter.d.ts | Removed local type declaration; types now ship with the new package. |
| packages/yasqe/package.json | Swap dependency to @matdata/sparql-formatter@^1.0.0. |
| packages/yasgui/src/TabSettingsModal.ts | Relabel formatter option to "SPARQL 1.2 Formatter"; stored value unchanged. |
| package-lock.json | Add new package, remove old package and its transitive deps; retained/dev flags are consistent. |
| docs/user-guide.md | Update formatter description to reference the new package and SPARQL 1.2 support. |
| .changeset/sparql-1-2-formatter.md | Changeset: @matdata/yasqe minor, @matdata/yasgui patch. |
| test/run.ts | New E2E test asserting exact SPARQL 1.2 formatting output with preserved comment. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Switches the query formatter from
sparql-formatter(SPARQL 1.1) to@matdata/sparql-formatter(SPARQL 1.2).Why
sparql-formattercan't parse SPARQL 1.2, soVERSION, triple terms<<( … )>>, reified triples<< … ~ r >>, reifiers and annotations{| … |}and base direction"x"@ar--rtlall fell back to the legacy formatter. They are now formatted properly.GRAPH ?g { }(sparqling/sparql-formatter#30).Changes
@matdata/yasqe: dependencysparql-formatter→@matdata/sparql-formatter@^1.0.0. The code change is one import line: the package exports the samespfmt.format(query, mode, indent)API.packages/yasqe/src/sparql-formatter.d.ts, since the new package ships its own types.sparql-formatter, so saved user settings keep working.package-lock.json: removedsparql-formatterand the 22 packages only it used (commander,csv-write-stream,ls,through2, …), and added@matdata/sparql-formatter, which has no runtime dependencies.@matdata/yasqeminor).GRAPHblock and checks the exact output.Syntax errors still fall back to the legacy formatter, as before.
Note on the lockfile
The lockfile was edited by hand because npm wasn't available where this PR was made. CI runs
npm ci, which will catch any mismatch. Runningnpm installlocally should give no further changes.🤖 Generated with Claude Code
https://claude.ai/code/session_01KSjgmmKydVPHYWjYDZgvQP
Generated by Claude Code