Skip to content

feat: format queries with @matdata/sparql-formatter (SPARQL 1.2) - #190

Merged
MathiasVDA merged 2 commits into
mainfrom
feat/sparql-12-formatter
Sep 30, 2026
Merged

MathiasVDA merged 2 commits into
mainfrom
feat/sparql-12-formatter

Conversation

@MathiasVDA

Copy link
Copy Markdown
Collaborator

Switches the query formatter from sparql-formatter (SPARQL 1.1) to @matdata/sparql-formatter (SPARQL 1.2).

Why

  • SPARQL 1.2: sparql-formatter can't parse SPARQL 1.2, so VERSION, triple terms <<( … )>>, reified triples << … ~ r >>, reifiers and annotations {| … |} and base direction "x"@ar--rtl all fell back to the legacy formatter. They are now formatted properly.
  • Comments stay in place: comments no longer move when formatting, for example a comment inside an empty GRAPH ?g { } (sparqling/sparql-formatter#30).

Changes

  • @matdata/yasqe: dependency sparql-formatter → @matdata/sparql-formatter@^1.0.0. The code change is one import line: the package exports the same spfmt.format(query, mode, indent) API.
  • Removed packages/yasqe/src/sparql-formatter.d.ts, since the new package ships its own types.
  • Settings: the option is now labelled "SPARQL 1.2 Formatter". The stored value is still sparql-formatter, so saved user settings keep working.
  • package-lock.json: removed sparql-formatter and the 22 packages only it used (commander, csv-write-stream, ls, through2, …), and added @matdata/sparql-formatter, which has no runtime dependencies.
  • User guide and a changeset (@matdata/yasqe minor).
  • New browser test: formats a SPARQL 1.2 query with a comment inside an empty GRAPH block 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. Running npm install locally should give no further changes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KSjgmmKydVPHYWjYDZgvQP


Generated by Claude Code

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.2 with @matdata/sparql-formatter@^1.0.0 (dependency + import) and delete the now-unneeded local sparql-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-formatter for 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 GRAPH block, 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.

@MathiasVDA
MathiasVDA merged commit 1719850 into main Sep 30, 2026
2 checks passed
@MathiasVDA
MathiasVDA deleted the feat/sparql-12-formatter branch September 30, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants