feat(cimvocabcheck): warn on unused SPARQL variables (GH-23)#39
Open
spah-soptim wants to merge 2 commits into
Open
feat(cimvocabcheck): warn on unused SPARQL variables (GH-23)#39spah-soptim wants to merge 2 commits into
spah-soptim wants to merge 2 commits into
Conversation
- new schema-independent UnusedVariableCheck over the parsed syntax tree, reporting two WARN codes: PROJECTED_VARIABLE_UNBOUND (SELECT list / CONSTRUCT template / DESCRIBE variable that appears nowhere in the query body) and UNUSED_VARIABLE (variable bound in a triple pattern, BIND or VALUES that occurs exactly once in its scope) - quiet on idiomatic SPARQL: SELECT */DESCRIBE * and ASK bodies, single-use variables inside EXISTS/NOT EXISTS/MINUS, variable predicates, GRAPH/ SERVICE names, sub-SELECT projections; per-SELECT-scope analysis; unknown syntax forms skip the check instead of risking false positives - runs in schema-aware validation and in the checkSyntaxOnly fallback; SPARQL Update requests are not checked - SHACL embedded SPARQL: pre-bound variables ($this, ?value, $PATH, $shapesGraph, $currentShape) are exempted in both the schema-aware and syntax-only paths - SourceLocator.locateVariable finds the ?name/$name token for positions - docs: new "Unused-variable checks" section in validation-checks.md Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
spah-soptim
marked this pull request as ready for review
July 9, 2026 07:20
…rs from unused-variable check (GH-23) $this/?value/etc. were exempt via a fixed name list, but SHACL-SPARQL constraint components can declare arbitrary pre-bound parameters via sh:parameter [ sh:path ex:foo ] -> $foo (SHACL-SPARQL §5.3). A pattern like `$myList (rdf:rest*)/rdf:first ?path .` was flagged UNUSED_VARIABLE on $myList even though it's legitimately pre-bound, not unused. ShaclSparqlExtractor.collectConstraintParameterNames() now scans the shapes graph for declared sh:parameter local names, and both SHACL suppression call sites (validateShacl, checkShaclSyntaxOnly) merge them with the fixed pre-bound set before filtering. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #23