fix(ruby-extractor): repair 7 Ruby FunctionExtractor extraction/classification bugs#86
Open
gadievron wants to merge 1 commit into
Conversation
…ification bugs
The Ruby tree-walk dispatched on only method/singleton_method/class/module nodes
and tracked no method visibility, so several real Ruby constructs were silently
dropped or mislabeled, degrading the function inventory and the call graph /
entry-point analysis built on it.
Fixes:
- Nested (`module Outer; module Inner`) and compact (`module Outer::Inner`) module
names were flattened/dropped — now read via the `name` field (handles constant +
scope_resolution) and concatenated as `Outer::Inner` instead of replaced, so
qualified calls resolve.
- `define_method(:sym)` do..end / { } class-body metaprogramming now emits method
units (parses as a `call` node).
- `alias_method :a, :b` (symbol + string forms) now extracted.
- `alias new old` keyword form (`alias` node) now extracted.
- Method visibility (private/protected/public) now threaded through the traversal
and stored on each unit; the arg-form `private :sym` is consumed without leaking
into the bare-marker toggle.
- Non-public controller methods (params helpers, before_action targets) classified
before the controller branch, so they are no longer over-flagged as route_handler
/ entry points; public actions unchanged.
- Top-level Sinatra route DSL (`get '/path' do..end`) now emits route_handler units.
Method-body calls are never traversed (no false positives); non-matching
top-level/class-body calls fall through to a normal child descent.
Scope / compatibility: adds a `visibility` field to emitted units (additive).
`unit_type` for controller non-public methods narrows from `route_handler` to
`private_method`/`protected_method` (correctness fix; removes the entry-point
over-claim). `_classify_function` and `_process_method_node` gained an optional
`visibility` parameter (default `public`); no public API signature break. The
arg-form `private :sym` targeted privatization is out of scope and left as a
documented no-op toggle.
Tests: tests/parsers/ruby/test_function_extractor.py. The test imports the Ruby
extractor package-qualified (from parsers.ruby.function_extractor import
FunctionExtractor) so it does not shadow the python/php modules of the same basename
in the shared pytest session. 9 failed pre-fix -> 9 passed after the fix (8 bug
tests + 1 arg-form visibility-leak regression guard). Full suite: 185 passed, 63
skipped, 0 failed. ruff clean.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
The Ruby tree-walk dispatched on only method/singleton_method/class/module nodes
and tracked no method visibility, so several real Ruby constructs were silently
dropped or mislabeled, degrading the function inventory and the call graph /
entry-point analysis built on it.
Fixes:
module Outer; module Inner) and compact (module Outer::Inner) modulenames were flattened/dropped — now read via the
namefield (handles constant +scope_resolution) and concatenated as
Outer::Innerinstead of replaced, soqualified calls resolve.
define_method(:sym)do..end / { } class-body metaprogramming now emits methodunits (parses as a
callnode).alias_method :a, :b(symbol + string forms) now extracted.alias new oldkeyword form (aliasnode) now extracted.and stored on each unit; the arg-form
private :symis consumed without leakinginto the bare-marker toggle.
before the controller branch, so they are no longer over-flagged as route_handler
/ entry points; public actions unchanged.
get '/path' do..end) now emits route_handler units.Method-body calls are never traversed (no false positives); non-matching
top-level/class-body calls fall through to a normal child descent.
Scope / compatibility: adds a
visibilityfield to emitted units (additive).unit_typefor controller non-public methods narrows fromroute_handlertoprivate_method/protected_method(correctness fix; removes the entry-pointover-claim).
_classify_functionand_process_method_nodegained an optionalvisibilityparameter (defaultpublic); no public API signature break. Thearg-form
private :symtargeted privatization is out of scope and left as adocumented no-op toggle.
Tests: tests/parsers/ruby/test_function_extractor.py. The test imports the Ruby
extractor package-qualified (from parsers.ruby.function_extractor import
FunctionExtractor) so it does not shadow the python/php modules of the same basename
in the shared pytest session. 9 failed pre-fix -> 9 passed after the fix (8 bug
tests + 1 arg-form visibility-leak regression guard). Full suite: 185 passed, 63
skipped, 0 failed. ruff clean.
Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com