Skip to content

Refactor AbsentOrWrongFileLicense#8969

Merged
BraisGabin merged 1 commit into
mainfrom
move-header-to-config
Jan 17, 2026
Merged

Refactor AbsentOrWrongFileLicense#8969
BraisGabin merged 1 commit into
mainfrom
move-header-to-config

Conversation

@BraisGabin
Copy link
Copy Markdown
Member

AbsentOrWrongFileLicense is a bit strange. It is a rule that needs a FileProcessListener to work. The reason for it is how the rule is configured. The configuration is not inside the yaml file. 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 that path.

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). FileProcessListener takes the absolute path of the last yaml as the base path and the resolves the file location. That "last" yaml is 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 yaml so all those problems go away. yaml has a multiple ways to write multiline strings. For example:

comments:
  AbsentOrWrongFileLicense:
    licenseTemplate: |
      /* Your lincense
       * Here
       */
    licenseTemplate: false

Context:

The initial reason for this change was to unblock: #8681 because to test the interaction between the FileProcessListener and the Rule it was using some functions provided by core through detekt-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.

@BraisGabin BraisGabin force-pushed the move-header-to-config branch from 2d22a70 to f88f809 Compare January 16, 2026 11:03
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.02%. Comparing base (cfe38a0) to head (f88f809).
⚠️ Report is 4 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@schalkms schalkms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Top 👍

@schalkms schalkms added this to the 2.0.0 milestone Jan 16, 2026
@BraisGabin BraisGabin merged commit d4618bf into main Jan 17, 2026
21 checks passed
@BraisGabin BraisGabin deleted the move-header-to-config branch January 17, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Marker for breaking changes which should be highlighted in the changelog rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants