alexevanczuk / packs

A pure Rust implementation of packwerk, a gradual modularization tool for Ruby
MIT License
70 stars 7 forks source link

Packs doesn't detect reference when mixing constant references and method calls #215

Closed oleg-vinted closed 1 week ago

oleg-vinted commented 2 weeks ago

Here's an example, we have two files in two different packages, with no dependencies defined:

class Foo
  def foo
    # should be a violation, but isn't:
    Bar::ADAPTER['default']::INSTANCE
  end
end
# this file doesn't really matter, it's just some minimal
# implementation so that the code above makes sense

module Bar
  module DefaultAdapter
    INSTANCE = 'fake instance'
  end

  ADAPTER = {
    'default' => DefaultAdapter,
  }
end

Bar::ADAPTER should be a violation, but it's not detected by Packs. Packwerk does detect this violation.

Minimal reproduction repo: https://github.com/oleg-vinted/packs-repro.

alexevanczuk commented 2 weeks ago

Interesting, does this happen when you just reference ADAPTER alone? e.g.

class Foo
  def foo
    # should be a violation, but isn't:
    Bar::ADAPTER
  end
end

module Bar
  ADAPTER = 1
end
oleg-vinted commented 2 weeks ago

Both Bar::ADAPTER and Bar::ADAPTER['default'] are detected as violations by Packs. Only after adding ::INSTANCE on top of that Packs no longer can detect the violation.

alexevanczuk commented 2 weeks ago

Interesting – my guess is something in the reference collection logic isn't picking that up as a reference in that case. I could look into it at some point but also feel free to shoot a PR over and will look at it right away!