-
-
Notifications
You must be signed in to change notification settings - Fork 784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow using regular expressions when defining license header templates #3486
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3486 +/- ##
============================================
+ Coverage 80.06% 80.09% +0.02%
- Complexity 2864 2868 +4
============================================
Files 458 458
Lines 8584 8596 +12
Branches 1663 1666 +3
============================================
+ Hits 6873 6885 +12
Misses 794 794
Partials 917 917
Continue to review full report at Codecov.
|
771515f
to
7aaf36c
Compare
Problem: different projects might impose different rules on license headers. It's not uncommon, for example, that a year in the license header is the year when the source file was created. This leads to a situation when different source files have different license headers (at least some parts of them differ) making it impossible to use a single static license header template to match against. This change makes it possible to define license header templates as regexps. An example of such template is: \/\/ Copyright 20[0-9]{2} Artur Bosch & Contributors which would match both // Copyright 2020 Artur Bosch & Contributors and // Copyright 2021 Artur Bosch & Contributors The way `AbsentOrWrongFileLicense` works now is controlled by the new configuration option `licenseTemplateIsRegex`: when `licenseTemplateIsRegex` is false the template is considered to be static and the old matching rules apply. If `licenseTemplateIsRegex` is set to true the new regexp based logic kicks in. To avoid breakage of existing projects, the added configuration option `licenseTemplateIsRegex` is disabled by default. This commit implements a feature requested here detekt#3100.
7aaf36c
to
6a6a755
Compare
@BraisGabin @arturbosch can you please advice me what I should do with the test coverage? Codecov marks red the lines that I haven't touched. Or maybe I'm reading its report wrong? |
I would say let's ignore the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contributing this rule! Great job! 😀
I have 1 remaining question. I think this ready to be merged.
.../main/kotlin/io/gitlab/arturbosch/detekt/rules/documentation/LicenceHeaderLoaderExtension.kt
Show resolved
Hide resolved
It could be replaced by `AbsentOrWrongFileLicense` in the previous commit, because the rule supports regular expressions since detekt 1.16.0 [1]. [1] detekt/detekt#3486 Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@here.com>
It could be replaced by `AbsentOrWrongFileLicense` in the previous commit, because the rule supports regular expressions since detekt 1.16.0 [1]. [1] detekt/detekt#3486 Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@here.com>
Problem: different projects might impose different rules on license headers.
It's not uncommon, for example, that a year in the license header is the year when the source
file was created. This leads to a situation when different source files have different license
headers (at least some parts of them differ) making it impossible to use a single static
license header template to match against.
This change makes it possible to define license header templates as regexps.
An example of such template is:
// Copyright 20[0-9]{2} Artur Bosch & Contributors
which would match both
\ Copyright 2020 Artur Bosch & Contributors
and
\ Copyright 2021 Artur Bosch & Contributors
The way
AbsentOrWrongFileLicense
works now is controlledby the new configuration option
licenseTemplateIsRegex
:when
licenseTemplateIsRegex
is false the template is considered to be staticand the old matching rules apply.
If
licenseTemplateIsRegex
is set to true the new regexp based logic kicks in.To avoid breakage of existing projects, the added configuration option
licenseTemplateIsRegex
is disabled by default.This commit implements a feature requested here #3100.
A similar PR may already be submitted!
Please search among the Pull requests before creating one.
Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. Link to relevant issues if possible.
For more information, see the CONTRIBUTING guide.