rubydex 0.2.9 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +110 -6
- data/THIRD_PARTY_LICENSES.html +271 -2
- data/exe/rdx +2 -73
- data/ext/rubydex/config.c +140 -0
- data/ext/rubydex/config.h +16 -0
- data/ext/rubydex/declaration.c +1 -1
- data/ext/rubydex/definition.c +32 -4
- data/ext/rubydex/diagnostic.c +75 -1
- data/ext/rubydex/diagnostic.h +2 -0
- data/ext/rubydex/graph.c +27 -48
- data/ext/rubydex/graph.h +6 -0
- data/ext/rubydex/query.c +487 -0
- data/ext/rubydex/query.h +8 -0
- data/ext/rubydex/reference.c +60 -0
- data/ext/rubydex/rubydex.c +4 -0
- data/ext/rubydex/utils.c +23 -4
- data/ext/rubydex/utils.h +5 -0
- data/lib/ruby_lsp/rubydex/addon.rb +211 -0
- data/lib/rubydex/cli/command/console.rb +55 -0
- data/lib/rubydex/cli/command/lint/explain.rb +74 -0
- data/lib/rubydex/cli/command/lint.rb +202 -0
- data/lib/rubydex/cli/command/mcp.rb +30 -0
- data/lib/rubydex/cli/command/query.rb +70 -0
- data/lib/rubydex/cli/command/skill.rb +69 -0
- data/lib/rubydex/cli/command.rb +168 -0
- data/lib/rubydex/cli.rb +93 -0
- data/lib/rubydex/config.rb +59 -0
- data/lib/rubydex/diagnostic.rb +12 -3
- data/lib/rubydex/errors.rb +42 -1
- data/lib/rubydex/graph.rb +10 -3
- data/lib/rubydex/linter/custom_rule.rb +97 -0
- data/lib/rubydex/linter/helpers/path_helpers.rb +78 -0
- data/lib/rubydex/linter/helpers/source_access_helpers.rb +31 -0
- data/lib/rubydex/linter/rule_loader.rb +36 -0
- data/lib/rubydex/linter/rule_test_case.rb +343 -0
- data/lib/rubydex/linter/runner.rb +56 -0
- data/lib/rubydex/linter.rb +19 -0
- data/lib/rubydex/location.rb +3 -0
- data/lib/rubydex/mcp_server.rb +1 -2
- data/lib/rubydex/related_information.rb +17 -0
- data/lib/rubydex/rule.rb +33 -0
- data/lib/rubydex/severity.rb +70 -0
- data/lib/rubydex/skill.rb +88 -0
- data/lib/rubydex/skill_registry.rb +62 -0
- data/lib/rubydex/version.rb +1 -1
- data/lib/rubydex.rb +6 -0
- data/lib/rubydex_linter/rules/rule_structure.rb +125 -0
- data/rbi/rubydex.rbi +578 -15
- data/rust/Cargo.lock +7 -0
- data/rust/rubydex/Cargo.toml +1 -0
- data/rust/rubydex/benches/graph_memory.rs +20 -4
- data/rust/rubydex/src/compile_assertions.rs +15 -0
- data/rust/rubydex/src/config.rs +538 -157
- data/rust/rubydex/src/diagnostic.rs +66 -40
- data/rust/rubydex/src/errors.rs +0 -1
- data/rust/rubydex/src/indexing/local_graph.rs +6 -5
- data/rust/rubydex/src/indexing/rbs_indexer.rs +284 -8
- data/rust/rubydex/src/indexing/ruby_indexer.rs +59 -70
- data/rust/rubydex/src/indexing/ruby_indexer_tests.rs +195 -86
- data/rust/rubydex/src/lib.rs +1 -0
- data/rust/rubydex/src/listing.rs +26 -1
- data/rust/rubydex/src/main.rs +9 -128
- data/rust/rubydex/src/model/declaration.rs +301 -229
- data/rust/rubydex/src/model/definitions.rs +27 -26
- data/rust/rubydex/src/model/document.rs +43 -7
- data/rust/rubydex/src/model/graph.rs +67 -68
- data/rust/rubydex/src/model/id.rs +55 -0
- data/rust/rubydex/src/model/ids.rs +21 -9
- data/rust/rubydex/src/model/name.rs +88 -19
- data/rust/rubydex/src/model/references.rs +16 -13
- data/rust/rubydex/src/operation/ruby_builder.rs +78 -104
- data/rust/rubydex/src/path_helpers.rs +77 -0
- data/rust/rubydex/src/query/cypher/schema.rs +853 -0
- data/rust/rubydex/src/query/cypher/schema_info.rs +161 -0
- data/rust/rubydex/src/query/cypher/tests.rs +253 -0
- data/rust/rubydex/src/query/cypher.rs +54 -0
- data/rust/rubydex/src/query.rs +125 -43
- data/rust/rubydex/src/resolution.rs +368 -395
- data/rust/rubydex/src/resolution_tests.rs +504 -78
- data/rust/rubydex/src/test_utils/context.rs +2 -1
- data/rust/rubydex/src/test_utils/graph_test.rs +26 -12
- data/rust/rubydex/src/test_utils/local_graph_test.rs +19 -0
- data/rust/rubydex/tests/cli.rs +4 -4
- data/rust/rubydex-sys/src/config_api.rs +205 -0
- data/rust/rubydex-sys/src/cypher_api.rs +791 -0
- data/rust/rubydex-sys/src/declaration_api.rs +6 -3
- data/rust/rubydex-sys/src/definition_api.rs +27 -7
- data/rust/rubydex-sys/src/diagnostic_api.rs +77 -8
- data/rust/rubydex-sys/src/graph_api.rs +31 -68
- data/rust/rubydex-sys/src/lib.rs +2 -0
- data/rust/rubydex-sys/src/name_api.rs +2 -6
- data/rust/rubydex-sys/src/reference_api.rs +58 -12
- data/rust/rubydex-sys/src/utils.rs +37 -0
- data/skills/send-private-method/SKILL.md +133 -0
- metadata +37 -2
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: send-private-method
|
|
3
|
+
description: Remediate a `send`/`__send__` call that reaches a private method, restoring a real public seam instead of bypassing visibility. Use when send is being used to invoke private functionality in a class.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Send Private Method
|
|
7
|
+
|
|
8
|
+
A test calls `obj.send(:some_private_method)` (or `__send__`) to invoke a method Ruby's visibility system would otherwise forbid. `send` deliberately bypasses encapsulation. `__send__` behaves identically and is the conventional spelling when a class defines its own `send`; Ruby warns when you redefine `__send__`, but it is not un-overridable. Remediation is the same for both. The smell is not "you used `send`" — it is "the test reaches past the public API into an implementation detail," which breaks the moment the private method is renamed, reorganized, or removed even though the public contract is unchanged.
|
|
9
|
+
|
|
10
|
+
## Confirm the receiver and the method
|
|
11
|
+
|
|
12
|
+
You have a call site: a file path and a line number. Before changing anything, answer two questions:
|
|
13
|
+
|
|
14
|
+
1. **What is the receiver's real type?** Trace the receiver expression at the flagged line back to its class. If it is a local/ivar, find where it is assigned (a `let`, `setup`, factory, or constructor).
|
|
15
|
+
2. **Where is the private method defined?** Search the workspace for `def <method_name>` (and `define_method :<method_name>`). Confirm the definition is under `private` (or `private :<method_name>`). Note its enclosing class/module and read the method body — you cannot decide the fix without knowing what the method does.
|
|
16
|
+
|
|
17
|
+
A name-based search matches by method *name* across the whole workspace, so a public method and a private method sharing the same unqualified name on different classes can produce a false positive. If the receiver's type has a *public* method of that name, this is not the smell — stop here.
|
|
18
|
+
|
|
19
|
+
## Decide which situation you are in
|
|
20
|
+
|
|
21
|
+
Read the method body and the test. Exactly one of these applies:
|
|
22
|
+
|
|
23
|
+
- **The caller needs behavior that should be public.** The private method does something the application legitimately depends on, and there is no public entry point that exposes it. The encapsulation boundary was drawn too tightly.
|
|
24
|
+
- **The caller is a test reaching past an existing public API.** A public method already wraps or drives this private one; the test bypassed it to assert on an intermediate result instead of the observable outcome. If the public outcome is already tested elsewhere, the private-method test is redundant — delete it rather than rewriting it.
|
|
25
|
+
- **The private method is the wrong home for the logic.** The behavior is genuinely useful to more than one caller, but it lives tucked away inside one class's private section. Both production and tests want it.
|
|
26
|
+
|
|
27
|
+
## Fix per situation
|
|
28
|
+
|
|
29
|
+
### 1. Promote to public (or `protected`)
|
|
30
|
+
|
|
31
|
+
If the behavior is part of the object's real contract, make it public and document it as API. Use `protected` only when every legitimate caller is an instance inside the same class hierarchy as the class that defines the method — never to paper over a single test's reach-in.
|
|
32
|
+
|
|
33
|
+
Before:
|
|
34
|
+
```ruby
|
|
35
|
+
class Foo
|
|
36
|
+
def bar = qux.sum
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
def qux
|
|
41
|
+
@items.reject(&:voided?).map { |i| i.baz - i.discount }
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
# test
|
|
45
|
+
foo.send(:qux)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
After:
|
|
49
|
+
```ruby
|
|
50
|
+
class Foo
|
|
51
|
+
def bar = qux.sum
|
|
52
|
+
|
|
53
|
+
# Public: items with discounts applied, voided items excluded.
|
|
54
|
+
# Used by reporting and by #bar's total.
|
|
55
|
+
def qux
|
|
56
|
+
@items.reject(&:voided?).map { |i| i.baz - i.discount }
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
# test
|
|
60
|
+
foo.qux
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 2. Drive the public entry point, assert on the observable outcome
|
|
64
|
+
|
|
65
|
+
If a public method already exercises the private one, call the public method and assert on what it produces — not on the private intermediate.
|
|
66
|
+
|
|
67
|
+
Before:
|
|
68
|
+
```ruby
|
|
69
|
+
class Foo
|
|
70
|
+
def bar(baz) = Receipt.new(tax: baz.amount * qux(baz.quux))
|
|
71
|
+
|
|
72
|
+
private
|
|
73
|
+
|
|
74
|
+
def qux(quux) = RATES.fetch(quux)
|
|
75
|
+
end
|
|
76
|
+
# test
|
|
77
|
+
foo.send(:qux, "CA") # => 0.05
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
After:
|
|
81
|
+
```ruby
|
|
82
|
+
# test — assert on the observable result of the public API
|
|
83
|
+
result = foo.bar(baz_with(quux: "CA", amount: 100))
|
|
84
|
+
assert_equal 5.0, result.tax
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 3. Extract to its own object/module
|
|
88
|
+
|
|
89
|
+
When the logic serves multiple callers but is trapped in one class's private section, move it to a dedicated object or module with a public interface both callers can use.
|
|
90
|
+
|
|
91
|
+
Before:
|
|
92
|
+
```ruby
|
|
93
|
+
class Foo
|
|
94
|
+
private
|
|
95
|
+
|
|
96
|
+
def bar(raw) = raw.transform_keys(&:to_s).compact
|
|
97
|
+
end
|
|
98
|
+
# test
|
|
99
|
+
foo.send(:bar, { baz: "Q" })
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
After:
|
|
103
|
+
```ruby
|
|
104
|
+
class Bar
|
|
105
|
+
def call(raw) = raw.transform_keys(&:to_s).compact
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
class Foo
|
|
109
|
+
def initialize(bar: Bar.new) = @bar = bar
|
|
110
|
+
def baz(raw) = @bar.call(raw)
|
|
111
|
+
end
|
|
112
|
+
# test
|
|
113
|
+
assert_equal({ "baz" => "Q" }, Bar.new.call({ baz: "Q" }))
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Private class methods and `module_function`
|
|
117
|
+
|
|
118
|
+
The three situations above cover instance methods. Two related visibility forms need special handling:
|
|
119
|
+
|
|
120
|
+
- **Private class methods** (`private_class_method :bar`, or a `def bar` under `private` inside `class << self`). A bare `private` does **not** apply to `def self.bar`: that singleton method stays public wherever it sits relative to the `private` line, so a public `def self.bar` under `private` is not this smell. A `send` like `Foo.send(:bar)` reaches a genuinely private singleton method. The remediation mirrors instance methods — promote with `public_class_method :bar` (or drop the `private_class_method :bar` call), drive an existing public class method, or extract. Do not use the instance-method patterns verbatim; the fix targets the singleton class.
|
|
121
|
+
- **`module_function`**. `module_function :foo` creates a public singleton method and a private instance method. If the test calls `instance.send(:foo)` on the private instance side, the public entry point already exists: call `MyModule.foo` directly. This is situation 2 — drive the public singleton method, do not promote the instance method.
|
|
122
|
+
|
|
123
|
+
## Legitimate exceptions — and what to do about them
|
|
124
|
+
|
|
125
|
+
Not every `send` to a private name is a smell to remove. Handle these deliberately:
|
|
126
|
+
|
|
127
|
+
- **Dynamic dispatch over a validated allowlist.** The method name is genuinely computed (`send(action)`), and the action set is bounded and checked. Constrain it: define an `ALLOWED_ACTIONS = %i[...].freeze` constant, guard with `raise unless ALLOWED_ACTIONS.include?(action)`, and call `public_send(action)` so the visibility system still applies. If every allowed action is public, the smell is gone.
|
|
128
|
+
- **Framework or DSL callbacks.** Some libraries require `send` to reach hooks they themselves marked private. If the method name is dictated by the framework contract, leave the call but add a one-line comment naming the framework and the callback it satisfies.
|
|
129
|
+
- **Third-party code you cannot change.** The private method belongs to a gem or an owned-elsewhere class you must not edit. Wrap the reach-in behind a single named adapter method in your own code with a comment stating why (e.g. `# Sends :bar to avoid the gem's private API; remove when upstream exposes a public hook.`). The adapter localizes the violation so it is auditable and removable in one place.
|
|
130
|
+
|
|
131
|
+
## What does NOT fix it
|
|
132
|
+
|
|
133
|
+
Switching `send` to `public_send` on a method that is *still private* does not fix anything — it just moves the failure from "silently bypassed encapsulation" to a `NoMethodError` at runtime. Answer the encapsulation question first; only then choose `public_send` (for dynamic dispatch over public methods) or a direct call (once promoted).
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubydex
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shopify
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-08-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A high-performance static analysis suite for Ruby, built in Rust with
|
|
14
14
|
Ruby APIs
|
|
@@ -24,6 +24,8 @@ files:
|
|
|
24
24
|
- README.md
|
|
25
25
|
- THIRD_PARTY_LICENSES.html
|
|
26
26
|
- exe/rdx
|
|
27
|
+
- ext/rubydex/config.c
|
|
28
|
+
- ext/rubydex/config.h
|
|
27
29
|
- ext/rubydex/declaration.c
|
|
28
30
|
- ext/rubydex/declaration.h
|
|
29
31
|
- ext/rubydex/definition.c
|
|
@@ -38,6 +40,8 @@ files:
|
|
|
38
40
|
- ext/rubydex/handle.h
|
|
39
41
|
- ext/rubydex/location.c
|
|
40
42
|
- ext/rubydex/location.h
|
|
43
|
+
- ext/rubydex/query.c
|
|
44
|
+
- ext/rubydex/query.h
|
|
41
45
|
- ext/rubydex/reference.c
|
|
42
46
|
- ext/rubydex/reference.h
|
|
43
47
|
- ext/rubydex/rubydex.c
|
|
@@ -45,8 +49,18 @@ files:
|
|
|
45
49
|
- ext/rubydex/signature.h
|
|
46
50
|
- ext/rubydex/utils.c
|
|
47
51
|
- ext/rubydex/utils.h
|
|
52
|
+
- lib/ruby_lsp/rubydex/addon.rb
|
|
48
53
|
- lib/rubydex.rb
|
|
54
|
+
- lib/rubydex/cli.rb
|
|
55
|
+
- lib/rubydex/cli/command.rb
|
|
56
|
+
- lib/rubydex/cli/command/console.rb
|
|
57
|
+
- lib/rubydex/cli/command/lint.rb
|
|
58
|
+
- lib/rubydex/cli/command/lint/explain.rb
|
|
59
|
+
- lib/rubydex/cli/command/mcp.rb
|
|
60
|
+
- lib/rubydex/cli/command/query.rb
|
|
61
|
+
- lib/rubydex/cli/command/skill.rb
|
|
49
62
|
- lib/rubydex/comment.rb
|
|
63
|
+
- lib/rubydex/config.rb
|
|
50
64
|
- lib/rubydex/declaration.rb
|
|
51
65
|
- lib/rubydex/diagnostic.rb
|
|
52
66
|
- lib/rubydex/errors.rb
|
|
@@ -54,6 +68,13 @@ files:
|
|
|
54
68
|
- lib/rubydex/graph.rb
|
|
55
69
|
- lib/rubydex/keyword.rb
|
|
56
70
|
- lib/rubydex/keyword_parameter.rb
|
|
71
|
+
- lib/rubydex/linter.rb
|
|
72
|
+
- lib/rubydex/linter/custom_rule.rb
|
|
73
|
+
- lib/rubydex/linter/helpers/path_helpers.rb
|
|
74
|
+
- lib/rubydex/linter/helpers/source_access_helpers.rb
|
|
75
|
+
- lib/rubydex/linter/rule_loader.rb
|
|
76
|
+
- lib/rubydex/linter/rule_test_case.rb
|
|
77
|
+
- lib/rubydex/linter/runner.rb
|
|
57
78
|
- lib/rubydex/location.rb
|
|
58
79
|
- lib/rubydex/mcp_server.rb
|
|
59
80
|
- lib/rubydex/mcp_server/protocol.rb
|
|
@@ -66,8 +87,14 @@ files:
|
|
|
66
87
|
- lib/rubydex/mcp_server/tools/search_declarations_tool.rb
|
|
67
88
|
- lib/rubydex/mixin.rb
|
|
68
89
|
- lib/rubydex/reference.rb
|
|
90
|
+
- lib/rubydex/related_information.rb
|
|
91
|
+
- lib/rubydex/rule.rb
|
|
92
|
+
- lib/rubydex/severity.rb
|
|
69
93
|
- lib/rubydex/signature.rb
|
|
94
|
+
- lib/rubydex/skill.rb
|
|
95
|
+
- lib/rubydex/skill_registry.rb
|
|
70
96
|
- lib/rubydex/version.rb
|
|
97
|
+
- lib/rubydex_linter/rules/rule_structure.rb
|
|
71
98
|
- rbi/rubydex.rbi
|
|
72
99
|
- rust/Cargo.lock
|
|
73
100
|
- rust/Cargo.toml
|
|
@@ -77,6 +104,8 @@ files:
|
|
|
77
104
|
- rust/rubydex-sys/Cargo.toml
|
|
78
105
|
- rust/rubydex-sys/build.rs
|
|
79
106
|
- rust/rubydex-sys/cbindgen.toml
|
|
107
|
+
- rust/rubydex-sys/src/config_api.rs
|
|
108
|
+
- rust/rubydex-sys/src/cypher_api.rs
|
|
80
109
|
- rust/rubydex-sys/src/declaration_api.rs
|
|
81
110
|
- rust/rubydex-sys/src/definition_api.rs
|
|
82
111
|
- rust/rubydex-sys/src/diagnostic_api.rs
|
|
@@ -126,8 +155,13 @@ files:
|
|
|
126
155
|
- rust/rubydex/src/operation/mod.rs
|
|
127
156
|
- rust/rubydex/src/operation/printer.rs
|
|
128
157
|
- rust/rubydex/src/operation/ruby_builder.rs
|
|
158
|
+
- rust/rubydex/src/path_helpers.rs
|
|
129
159
|
- rust/rubydex/src/position.rs
|
|
130
160
|
- rust/rubydex/src/query.rs
|
|
161
|
+
- rust/rubydex/src/query/cypher.rs
|
|
162
|
+
- rust/rubydex/src/query/cypher/schema.rs
|
|
163
|
+
- rust/rubydex/src/query/cypher/schema_info.rs
|
|
164
|
+
- rust/rubydex/src/query/cypher/tests.rs
|
|
131
165
|
- rust/rubydex/src/resolution.rs
|
|
132
166
|
- rust/rubydex/src/resolution_tests.rs
|
|
133
167
|
- rust/rubydex/src/stats.rs
|
|
@@ -140,6 +174,7 @@ files:
|
|
|
140
174
|
- rust/rubydex/src/test_utils/local_graph_test.rs
|
|
141
175
|
- rust/rubydex/tests/cli.rs
|
|
142
176
|
- rust/rustfmt.toml
|
|
177
|
+
- skills/send-private-method/SKILL.md
|
|
143
178
|
homepage: https://github.com/Shopify/rubydex
|
|
144
179
|
licenses:
|
|
145
180
|
- MIT
|