New feature: replace already existing license header based on pattern#98
New feature: replace already existing license header based on pattern#98kezhenxu94 merged 8 commits intoapache:mainfrom halacs:existing-header
Conversation
|
CI fails, please fix. |
|
Hi @wu-sheng, |
|
@halacs It is due to the fact that you're a newcomer to this repository, CI will be automatically run in your next contribution after this merges. :) |
|
@Superskyyy I see :) I extended the tests a bit but I'm finished for sure now. |
kezhenxu94
left a comment
There was a problem hiding this comment.
Hi @halacs , thanks! I prefer to add a CLI option in license-eye header fix such as --replace or similar names, so that when users don't have a pattern configured they can keep the original file headers to avoid too many changes, what do you think?
|
Hi @kezhenxu94, actually my change won't cause more file changes. My code just avoid duplicated headers. The way how we decide if a file needs to be updated remained the same. If a file header needs to be added, I check if there is an old header we need to remove first right before the new header would be added. Or maybe I don't understand something about the |
|
Hi, @halacs , the config |
|
Hi @kezhenxu94 ,
This means is expected license header is there file won't be updated so If I'm wrong please share where |
Can you show me a case of the duplicated headers, I think that should not happen. If I understand correctly, this PR is to fix the problem above? Here is what I think: if the previous header satisfies the // Remove previous license header version to allow update it
if licensePattern != nil {
content = licensePattern.ReplaceAll(content, []byte(""))
} |
|
hi @kezhenxu94, This PR is to make license update easier. Think of the case when a few words, such as year range (e.g. 2016-2022) needs to be updated (e.g. to 2016-2023). We need to detect there is the license already but it is outdated so needs to be removed first. In this case Until However, if By the way, |
|
Hi @halacs thanks for elaborating, that totally makes sense to me now.
This must be bug when I was reorganizing the configurations, can you please also update the codes below to - pattern := config.Pattern
+ pattern := config.License.Patternand remove the unused Thanks!!! I think the goal of this PR is clear now and I can merge it |
|
Hi @kezhenxu94, I just added the change you requested. I could run the Thanks for your effort! |
kezhenxu94
left a comment
There was a problem hiding this comment.
LGTM, thank you @halacs for the patience and explanation of the use case
Example config snippet: