Skip to content

[lint] Add support for querying contracts#601

Open
turbolent wants to merge 1 commit intomasterfrom
bastian/lint-query
Open

[lint] Add support for querying contracts#601
turbolent wants to merge 1 commit intomasterfrom
bastian/lint-query

Conversation

@turbolent
Copy link
Copy Markdown
Member

@turbolent turbolent commented Mar 11, 2026

Description

Add support for running queries (JQ-based) against analyzed contracts.

For example, the command line option -query '.. | select(.Type? == "CastingExpression" and (.Operation == "as!" or .Operation == "as?") and .SourceType == "AnyStruct") finds all failable casts and force casts from AnyStruct.

The implementation is an extended version of the query feature in the parse tool in Cadence (https://github.com/onflow/cadence/blob/master/cmd/parse/main.go#L48):

  • Translate the AST to JSON
  • Add type info from the elaboration to the JSON
  • Run the JQ query against the JSON

For now, start small and only provide support for casting expressions and force expressions to demonstrate the feature. We can extend support for the other expression types and other node kinds (declarations and statements) in future PRs.


  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • Code follows the standards mentioned here
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

@turbolent turbolent self-assigned this Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant