[GH-7682] Add ExpressionDeclaration, AssignmentsProvider, and new call-site API to eliminate raw AST usage in existing lint rules#34
Open
Bastian (bkoell) wants to merge 1 commit into
Conversation
…l-site API to eliminate raw AST usage in existing lint rules
There was a problem hiding this comment.
Pull request overview
This PR expands Rubyzen’s AST-wrapping API to reduce (or eliminate) raw RuboCop AST usage in lint rules by introducing first-class “value expression” and “assignment” primitives, plus new call-site convenience APIs. It also updates the sample project with new lint rules demonstrating the new APIs and bumps the gem version to 0.3.0.
Changes:
- Add
ExpressionDeclaration(+ExpressionsCollection) to model receivers/arguments/return values with kind predicates (constant/constructor/local var/hash literal/etc.). - Add
AssignmentDeclaration(+AssignmentsProvider/AssignmentsCollection) andReturnExpressionsProviderwith collection bridges on methods/blocks. - Extend
CallSiteDeclarationwith#arguments,#receiver_expression, and#enclosing_blocks, and add sample lint rules exercising these APIs.
Reviewed changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| spec/declarations/expression_declaration_spec.rb | Adds specs for expression predicates and call-site receiver/argument expression modeling. |
| spec/declarations/call_site_declaration_spec.rb | Adds specs for #receiver_expression, #arguments, and #enclosing_blocks. |
| spec/declarations/assignment_declaration_spec.rb | Adds specs for assignment name/value expression behavior (including masgn targets). |
| spec/collections/expressions_collection_spec.rb | Adds specs for expression collection filters and type-preserving filters. |
| spec/collections/assignments_collection_spec.rb | Adds specs for assignments collection name filtering and type preservation. |
| sample_project/src/tests/stubbing_test.rb | Adds sample “violation” source for stubbing Repos constants. |
| sample_project/src/tests/admin_flow_test.rb | Adds sample “violation” source for admin calls without context wrapper. |
| sample_project/src/serializers/user_serializer.rb | Adds sample class for “hash literal return” lint rule. |
| sample_project/src/questions/profile_status.rb | Adds sample class for “no side effects in questions” lint rule. |
| sample_project/spec/tests/no_stubbing_repos_lint_spec.rb | Adds lint rule using CallSiteDeclaration#arguments + ExpressionDeclaration#constant_name. |
| sample_project/spec/tests/admin_calls_use_with_admin_context_lint_spec.rb | Adds lint rule using CallSiteDeclaration#enclosing_blocks. |
| sample_project/spec/spec_helper.rb | Adds questions collection helper for question lint rules. |
| sample_project/spec/questions/no_side_effects_in_questions_lint_spec.rb | Adds lint rule using #receiver_expression + method #assignments to detect repo writes. |
| sample_project/spec/core/data_methods_return_data_objects_lint_spec.rb | Adds lint rule using #return_expressions.hash_literals. |
| lib/rubyzen/version.rb | Bumps gem version to 0.3.0. |
| lib/rubyzen/providers/return_expressions_provider.rb | Introduces provider for method/block return expressions. |
| lib/rubyzen/providers/enclosing_blocks_provider.rb | Introduces provider for retrieving enclosing blocks for a declaration. |
| lib/rubyzen/providers/assignments_provider.rb | Introduces provider for collecting local variable assignments. |
| lib/rubyzen/providers/arguments_provider.rb | Introduces provider for modeling call-site arguments as expressions. |
| lib/rubyzen/declarations/method_declaration.rb | Mixes in ReturnExpressionsProvider and AssignmentsProvider. |
| lib/rubyzen/declarations/expression_declaration.rb | Adds the new expression wrapper declaration and predicates/accessors. |
| lib/rubyzen/declarations/call_site_declaration.rb | Adds new call-site APIs and includes new providers. |
| lib/rubyzen/declarations/block_declaration.rb | Mixes in ReturnExpressionsProvider and AssignmentsProvider. |
| lib/rubyzen/declarations/assignment_declaration.rb | Adds the new assignment wrapper declaration. |
| lib/rubyzen/collections/methods_collection.rb | Adds collection bridges for return_expressions and assignments. |
| lib/rubyzen/collections/expressions_collection.rb | Adds expression collection filters (hash_literals, constants). |
| lib/rubyzen/collections/blocks_collection.rb | Adds collection bridges for return_expressions and assignments. |
| lib/rubyzen/collections/assignments_collection.rb | Adds the assignments collection type. |
| CLAUDE.md | Updates architecture docs with new APIs and data-flow. |
| CHANGELOG.md | Documents the 0.3.0 additions. |
Comment on lines
+8
to
+13
| nodes = [] | ||
| body = node.body | ||
| nodes << (body.begin_type? ? body.children.last : body) unless body.nil? | ||
| node.each_descendant(:return).each do |return_node| | ||
| nodes << return_node.children.first | ||
| end |
Comment on lines
+18
to
+23
| # Filters to only constant (or constructor-of-constant) expressions. | ||
| # | ||
| # @return [ExpressionsCollection] | ||
| def constants | ||
| filter(&:constant?) | ||
| end |
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.
What changed and why
Checklist
bundle exec rakepasses locally (runs both the RSpec and Minitest suites)