-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added feature to detect stale violations in packwerk via command 'pac…
…kwerk detect-stale violations
- Loading branch information
1 parent
cb64151
commit 063d616
Showing
5 changed files
with
212 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
require "packwerk/cache_deprecated_references" | ||
|
||
module Packwerk | ||
class DetectStaleDeprecatedReferences < CacheDeprecatedReferences | ||
def stale_violations? | ||
@deprecated_references.values.any?(&:stale_violations?) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# typed: false | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
require "packwerk/detect_stale_deprecated_references" | ||
require "byebug" | ||
|
||
module Packwerk | ||
class DetectStaleDeprecatedReferencesTest < Minitest::Test | ||
setup do | ||
package = Package.new(name: "buyers", config: {}) | ||
violated_reference = | ||
Reference.new( | ||
nil, | ||
"orders/app/jobs/orders/sweepers/purge_old_document_rows_task.rb", | ||
ConstantDiscovery::ConstantContext.new( | ||
"::Buyers::Document", | ||
"autoload/buyers/document.rb", | ||
package, | ||
false | ||
) | ||
) | ||
deprecated_reference = DeprecatedReferences.new(package, "test/fixtures/deprecated_references.yml") | ||
deprecated_reference.add_entries(violated_reference, "dependency") | ||
@detect_stale_deprecated_references = DetectStaleDeprecatedReferences.new( | ||
".", | ||
{ package.name => deprecated_reference } | ||
) | ||
end | ||
|
||
test "#stale_violations? returns true if there are stale violations" do | ||
Packwerk::DeprecatedReferences.any_instance | ||
.expects(:stale_violations?) | ||
.returns(true) | ||
|
||
assert @detect_stale_deprecated_references.stale_violations? | ||
end | ||
|
||
test "#stale_violations? returns false if no stale violations" do | ||
Packwerk::DeprecatedReferences.any_instance | ||
.expects(:stale_violations?) | ||
.returns(false) | ||
|
||
refute @detect_stale_deprecated_references.stale_violations? | ||
end | ||
end | ||
end |