Skip to content

feat(cimvocabcheck): warn on unused SPARQL variables (GH-23)#39

Open
spah-soptim wants to merge 2 commits into
mainfrom
feature/GH-23-unused-variable-warning
Open

feat(cimvocabcheck): warn on unused SPARQL variables (GH-23)#39
spah-soptim wants to merge 2 commits into
mainfrom
feature/GH-23-unused-variable-warning

Conversation

@spah-soptim

@spah-soptim spah-soptim commented Jul 8, 2026

Copy link
Copy Markdown
Member
  • 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

Closes #23

- 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 spah-soptim added this to the CIMVocabCheck v1.1.0 milestone Jul 8, 2026
@spah-soptim spah-soptim self-assigned this Jul 8, 2026
@spah-soptim spah-soptim added enhancement New feature or request cimvocabcheck CIMVocabCheck Library labels Jul 8, 2026
@spah-soptim
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cimvocabcheck CIMVocabCheck Library enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CIMVocabCheck: warn on unused SPARQL variables

1 participant