Skip to content

core: add AST-based linter for undeclared state reads in function-bas…#656

Open
Smitaambiger wants to merge 2 commits intoapache:mainfrom
Smitaambiger:feature/action-reads-linter
Open

core: add AST-based linter for undeclared state reads in function-bas…#656
Smitaambiger wants to merge 2 commits intoapache:mainfrom
Smitaambiger:feature/action-reads-linter

Conversation

@Smitaambiger
Copy link

Closes #407

This PR adds AST-based validation for undeclared state reads in function-based actions.

What this does

  • Parses the originating function using inspect.getsource
  • Walks the AST to detect state["<literal>"] accesses
  • Compares detected keys with declared reads=[...]
  • Raises ValueError if undeclared keys are accessed
  • Skips validation when source is unavailable

Why

Prevents silent bugs caused by accessing state keys that were not declared in reads, enforcing stricter action correctness.

Tests

  • Added unit tests covering:
    • Valid declared reads
    • Undeclared read detection

@Smitaambiger
Copy link
Author

@elijahbenizzy

Initial implementation for AST-based undeclared state read validation.

Currently implemented as a hard ValueError at action construction time.

Happy to adjust:

  • validation timing (build-time vs decorator-time)
  • severity (warning vs error)

Looking forward to feedback.

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.

Linter for action reads in state, function-based-actions

1 participant