Shopify/packwerk

Packwerk thinks that `app/helpers/foobar_fizz.rb` is in the package `app/helpers/foobar` and not `app/helpers`

andrewhamon opened this issue · 2 comments

Description
When a file has a prefix that matches an adjacent folder with a package in that folder, Packwerk thinks that the file belongs to the wrong package.

Directory layout:

app/helpers
├── package.yml
├── foobar_fizz.rb     # class FoobarFizz, depends on Meow::Woof. NOT part of the app/helpers/foobar package
├── foobar
│   ├── package.yml
│   └── subclass.rb    # class Foobar::Subclass
└── meow
    ├── package.yml
    └── woof.rb        # class Meow::Woof

foobar_fizz.rb is in the directory/package app/helpers. It depends on the package app/helpers/meow. Packwerk wants that dependency declared in app/helpers/foobar rather than app/helpers.

To Reproduce
Minimal reproduction: https://github.com/andrewhamon/packwerk-reproduction#readme

In the repo, run:

bundle install
bundle exec packwerk check

Expected Behaviour
There should be no error, as the dependency was declared in the correct package. If the package app/helpers/foobar (which is uninvolved) is removed, the errors go away, which is very surprising.

Version Information

  • Packwerk: 2.2.2
  • Ruby: 3.1.2

I can reproduce this on packwerk 3.2.0. I assume there's a / missing in some string comparison (we probably shouldn't do string comparison for this anyway...)

yeah it is this

path.start_with?(@name)