From ca7ae0d14bd0d79689a50100f4557ff94b62db99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20M=C3=BCller?= Date: Tue, 19 Mar 2024 16:31:50 +0000 Subject: [PATCH] don't associate a file with a different package that matches a prefix --- lib/packwerk/package.rb | 2 +- test/unit/packwerk/package_test.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/packwerk/package.rb b/lib/packwerk/package.rb index 95988aa57..47d253938 100644 --- a/lib/packwerk/package.rb +++ b/lib/packwerk/package.rb @@ -42,7 +42,7 @@ def dependency?(package) def package_path?(path) return true if root? - path.start_with?(@name) + path.start_with?(@name + "/") end sig { params(other: T.untyped).returns(T.nilable(Integer)) } diff --git a/test/unit/packwerk/package_test.rb b/test/unit/packwerk/package_test.rb index 083916b6d..e32710f9b 100644 --- a/test/unit/packwerk/package_test.rb +++ b/test/unit/packwerk/package_test.rb @@ -22,6 +22,10 @@ class PackageTest < Minitest::Test assert_equal(true, root_package.package_path?("components/unknown")) end + test "#package_path? returns false for different path with matching prefix" do + assert_equal(false, @package.package_path?("components/timeline_ui/something.rb")) + end + test "#<=> compares against name" do assert_equal(-1, @package <=> Package.new(name: "components/xyz", config: {})) assert_equal(0, @package <=> Package.new(name: "components/timeline", config: {}))