Skip to content

[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
mainfrom
7682-eliminate-raw-ast-usage-in-existing-rubyzen-lint-rules-in-husband-redis
Open

[GH-7682] Add ExpressionDeclaration, AssignmentsProvider, and new call-site API to eliminate raw AST usage in existing lint rules#34
Bastian (bkoell) wants to merge 1 commit into
mainfrom
7682-eliminate-raw-ast-usage-in-existing-rubyzen-lint-rules-in-husband-redis

Conversation

@bkoell

Copy link
Copy Markdown
Member

What changed and why

Checklist

  • Tests are added or updated for the changes
  • YARD docs are added or updated for the changes
  • bundle exec rake passes locally (runs both the RSpec and Minitest suites)

…l-site API to eliminate raw AST usage in existing lint rules

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) and ReturnExpressionsProvider with collection bridges on methods/blocks.
  • Extend CallSiteDeclaration with #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
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.

2 participants