archspec 1.2.0 → 1.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb5f7cda6a11326fedead006aa062155c7fdb2e1a3ea6e374d5cd1bca45d17e9
4
- data.tar.gz: 417ad99fbfc27aa871fcb0bd4ce3ced72d8c1aad3810d35f51722586a151bf81
3
+ metadata.gz: 54bf1c265b30d0ec084d11d8d180b166385d8fc3b1c12346f53d0263173d6cad
4
+ data.tar.gz: 7c2a96d714e2e6fc6dba89f2f9180691a6eba5c7a22037fbbce310976a8c5607
5
5
  SHA512:
6
- metadata.gz: 2dc335e5f43af785346921ca4b57e699a5b748d80e09441ac3abe6123ba7b17a730dba2a7c0f7c4c0c11b6288dc7e79ee87e95d8f9454a167df7d98a98de88d5
7
- data.tar.gz: 8b5736b3d23a1c053f8e158636a8582184c9c924ce478e1019818b527960ada6c8d5d7ab4e581849564978ae4c4f05d4238c0a571bf8d78ef479fb6242bc3868
6
+ metadata.gz: 933cfb16e9a7487086642883a16ed60ef357ccbdd67d02504c81f0c04ff910957e850e3419fb0ceb194c023cfb3eebe8e2a4782b29a8f56a83a7867edc28a93c
7
+ data.tar.gz: 6885261d3c5c6253a11a0816e278ed6667106f4dabc4d2927a6a5dc0fae0da7ce4154f8e130c162a6b4b2b3089d378636e74f7f1eb5072731e92a5249050237b
@@ -162,7 +162,7 @@ module ArchSpec
162
162
  :dynamic_superclass
163
163
  )
164
164
  MethodFallback = Data.define(:path, :owner, :name, :scope, :location, :visibility, :signatures)
165
- MixinFallback = Data.define(:path, :owner, :message, :target, :location, :nesting)
165
+ MixinFallback = Data.define(:path, :owner, :receiver, :message, :target, :location, :nesting)
166
166
 
167
167
  DYNAMIC_MESSAGES = %i[
168
168
  class_eval
@@ -272,7 +272,7 @@ module ArchSpec
272
272
  apply_generated_methods(graph)
273
273
  @extra_edges.each { |edge| graph.add_edge(**edge) }
274
274
  call_sites.each do |site|
275
- resolution = call_resolutions[site]
275
+ resolution = call_resolutions[site] || undeclared_receiver(graph, site)
276
276
  resolved_method = graph.resolve_method_alias(resolution.receiver, site.name, resolution.scope) if resolution
277
277
  graph.add_edge(
278
278
  type: :calls_named_method,
@@ -288,6 +288,18 @@ module ArchSpec
288
288
  end
289
289
  end
290
290
 
291
+ # A constant the index can't resolve, such as a gem's, is still the
292
+ # receiver its name says: a nested constant of that name if the graph has
293
+ # one, otherwise the name as written.
294
+ def undeclared_receiver(graph, site)
295
+ return unless site.receiver_name
296
+
297
+ name = site.receiver_name
298
+ receiver = name.start_with?('::') ? name.delete_prefix('::') :
299
+ graph.resolve_constant_reference(name, site.owner, lexical_nesting: site.nesting)
300
+ CallResolution.new(receiver, :class)
301
+ end
302
+
291
303
  def declaration_kind(name, path)
292
304
  @declaration_kinds[[normalize(name), path]]
293
305
  end
@@ -755,11 +767,17 @@ module ArchSpec
755
767
  @generated_methods << GeneratedMethod.new(path, owner, message, node, location, visibility, scope)
756
768
  end
757
769
 
770
+ # Worker.prepend(Poller) mixes Poller into Worker, not into the class
771
+ # whose body makes the call. A receiver that isn't a constant, such as
772
+ # tool.class.prepend(Guard), names nothing we can record it on.
758
773
  def record_mixin_fallback(path, node, message, owner, location, nesting)
759
774
  return unless MIXIN_EDGE_TYPES.key?(message)
760
775
 
776
+ receiver = constant_reference_name(node.receiver)
777
+ return unless receiver_kind(node) == :none || receiver
778
+
761
779
  constant_arguments(node).each do |target|
762
- @mixin_fallbacks << MixinFallback.new(path, owner, message, target, location, nesting)
780
+ @mixin_fallbacks << MixinFallback.new(path, owner, receiver, message, target, location, nesting)
763
781
  end
764
782
  end
765
783
 
@@ -826,17 +844,20 @@ module ArchSpec
826
844
  def apply_mixin_fallbacks(graph)
827
845
  @mixin_fallbacks.each do |fallback|
828
846
  type = MIXIN_EDGE_TYPES.fetch(fallback.message)
847
+ owner = mixin_owner(graph, fallback)
829
848
  next if graph.edges.any? do |edge|
830
- edge.type == type && edge.from_path == fallback.path && edge.from_constant == fallback.owner &&
849
+ edge.type == type && edge.from_path == fallback.path && edge.from_constant == owner &&
831
850
  edge.to == fallback.target
832
851
  end
833
852
 
834
- constant = graph.constants_named(fallback.owner).find { |candidate| candidate.path == fallback.path }
835
- constant&.add_mixin(fallback.message, fallback.target)
853
+ nodes = graph.constants_named(owner)
854
+ constant = nodes.find { |candidate| candidate.path == fallback.path } ||
855
+ (nodes.find { |candidate| !candidate.namespace_only } if fallback.receiver)
856
+ constant&.add_mixin(fallback.message, mixin_target(graph, fallback))
836
857
  graph.add_edge(
837
858
  type: type,
838
859
  from_path: fallback.path,
839
- from_constant: fallback.owner,
860
+ from_constant: owner,
840
861
  to: fallback.target,
841
862
  location: fallback.location,
842
863
  lexical_nesting: fallback.nesting
@@ -844,6 +865,21 @@ module ArchSpec
844
865
  end
845
866
  end
846
867
 
868
+ def mixin_owner(graph, fallback)
869
+ return fallback.owner unless fallback.receiver
870
+
871
+ graph.resolve_constant_reference(fallback.receiver, fallback.owner, lexical_nesting: fallback.nesting)
872
+ end
873
+
874
+ # The receiver's own node resolves its mixins from its own scope, so a
875
+ # module named from another class's body is recorded by its full name.
876
+ def mixin_target(graph, fallback)
877
+ return fallback.target unless fallback.receiver
878
+
879
+ resolved = graph.resolve_constant_reference(fallback.target, fallback.owner, lexical_nesting: fallback.nesting)
880
+ graph.constants_named(resolved).any? ? "::#{resolved}" : fallback.target
881
+ end
882
+
847
883
  def set_fallback_visibility(path, owner, names, scope, visibility)
848
884
  method_names = names.map { |name| name.unescaped.to_sym }
849
885
  @method_fallbacks.map! do |fallback|
@@ -35,9 +35,7 @@ module ArchSpec
35
35
  next if consumers.empty?
36
36
 
37
37
  target = graph.resolve_edge_constant(edge)
38
- owner = [edge.from_constant, *consumers]
39
- .select { |namespace| within_namespace?(target, namespace) }
40
- .max_by(&:length)
38
+ owner = definer(graph, target)
41
39
  next unless consumers.include?(owner)
42
40
 
43
41
  Diagnostic.new(
@@ -51,8 +49,16 @@ module ArchSpec
51
49
 
52
50
  private
53
51
 
54
- def within_namespace?(constant, namespace)
55
- constant == namespace || constant.start_with?("#{namespace}::")
52
+ # The class or module a reference reaches: the constant itself when it
53
+ # names one, or the namespace whose body defines a value constant.
54
+ # Chat::Interruptions::GRACE belongs to the concern Chat::Interruptions,
55
+ # and Chat::Closure is a class of its own, so neither names the includer
56
+ # Chat; Chat::LIMIT does.
57
+ def definer(graph, constant)
58
+ return constant if graph.constants_named(constant).any? { |node| node.class? || node.module? }
59
+
60
+ namespace, separator, = constant.rpartition('::')
61
+ separator.empty? ? constant : namespace
56
62
  end
57
63
 
58
64
  # Maps each mixed-in module to the set of constants that mix it in.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ArchSpec
4
- VERSION = '1.2.0'
4
+ VERSION = '1.2.2'
5
5
  end
metadata CHANGED
@@ -1,49 +1,48 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: archspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carmine Paolino
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2026-11-01 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: herb
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - "~>"
16
+ - - ">="
18
17
  - !ruby/object:Gem::Version
19
18
  version: 0.11.0
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: 0.11.2
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
23
25
  requirements:
24
- - - "~>"
26
+ - - ">="
25
27
  - !ruby/object:Gem::Version
26
28
  version: 0.11.0
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: 0.11.2
27
32
  - !ruby/object:Gem::Dependency
28
33
  name: prism
29
34
  requirement: !ruby/object:Gem::Requirement
30
35
  requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '1.0'
34
- - - "<"
36
+ - - "~>"
35
37
  - !ruby/object:Gem::Version
36
- version: '2'
38
+ version: 1.9.0
37
39
  type: :runtime
38
40
  prerelease: false
39
41
  version_requirements: !ruby/object:Gem::Requirement
40
42
  requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- version: '1.0'
44
- - - "<"
43
+ - - "~>"
45
44
  - !ruby/object:Gem::Version
46
- version: '2'
45
+ version: 1.9.0
47
46
  - !ruby/object:Gem::Dependency
48
47
  name: rubydex
49
48
  requirement: !ruby/object:Gem::Requirement
@@ -208,7 +207,6 @@ metadata:
208
207
  documentation_uri: https://archspecrb.dev/getting-started/
209
208
  bug_tracker_uri: https://github.com/crmne/archspec/issues
210
209
  rubygems_mfa_required: 'true'
211
- post_install_message:
212
210
  rdoc_options: []
213
211
  require_paths:
214
212
  - lib
@@ -223,8 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
221
  - !ruby/object:Gem::Version
224
222
  version: '0'
225
223
  requirements: []
226
- rubygems_version: 3.5.22
227
- signing_key:
224
+ rubygems_version: 3.6.9
228
225
  specification_version: 4
229
226
  summary: Architecture linter for Ruby and Rails.
230
227
  test_files: []