Refactor AbsentOrWrongFileLicense#8969
Merged
Merged
Conversation
e90215b to
a4db981
Compare
a4db981 to
ad02f37
Compare
ad02f37 to
2d22a70
Compare
2d22a70 to
f88f809
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8969 +/- ##
============================================
+ Coverage 85.00% 85.02% +0.02%
+ Complexity 4394 4377 -17
============================================
Files 570 569 -1
Lines 12290 12253 -37
Branches 2654 2643 -11
============================================
- Hits 10447 10418 -29
+ Misses 689 687 -2
+ Partials 1154 1148 -6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AbsentOrWrongFileLicenseis a bit strange. It is a rule that needs aFileProcessListenerto work. The reason for it is how the rule is configured. The configuration is not inside theyamlfile. In the yaml file the user writes a path and we check that the files had the same header as the content of the file in thatpath.The problem: the path needs to be relative (otherwise it wouldn't work on any computer). But relative to what? The rule doesn't know the "base" path to resolve that relative path. For that reason the implementation was using a
FileProcessListener. There we can check the absolute path of the config files (yamls).FileProcessListenertakes the absolute path of the lastyamlas the base path and the resolves the file location. That "last"yamlis also a bit strange. In general it works but it could generate problems.What this PR does is to remove that complexity away. Instead of using a relative path the user provides us with the header inside the
yamlso all those problems go away. yaml has a multiple ways to write multiline strings. For example:Context:
The initial reason for this change was to unblock: #8681 because to test the interaction between the
FileProcessListenerand the Rule it was using some functions provided by core throughdetekt-test. But I found another way to fix that problem. But when I realized this PR was ready to publish and I think that it is still beneficial.