spotless
spotless copied to clipboard
Add support for a file name field in license headers
It would be useful if there was a field in the license header template called $FILE
, $file.fileName
, or similar that would be replaced with the name of the file the header is being applied to.
For example, I could write something like:
/*
* Copyright (c) 2021 OxygenCobalt
* $file.fileName is part of Foo.
*/
And it would end up resolving to:
/*
* Copyright (c) 2021 OxygenCobalt
* Bar.kt is part of Foo.
*/
I'm mostly drawing this idea from IntelliJ's Copyright Notice format.
Happy to take a PR for this.
Well, I'm not too familiar with spotless's codebase, but I can try to take a crack at it.
I stumbled upon this issue when I was attempting to setup Spotless for my Android project whose copyright header template is:
/*
* $file.fileName
* Module: $module.name
* Project: $project.name
* Copyright © $year, My Company. All rights reserved.
*/
I did upvote this. AFAIK, the Spotless license header check is language/platform/IDE agnostic and most of these variables are injected by Android Studio. So not sure whether this is a legible feature request.
Just wondering, as a stop-gap solution, whether we could put support for Regex in licenseHeaderFile
?
Ex:
/*
* "\([A-z]*.kt)\"
* Module: "\([A-z\.]*)\"
* Project: "\([A-z]*)\"
* Copyright © $year, My Company. All rights reserved.
*/
For substitutions that have constant values (e.g. Module and Project) you can do this already via replaceRegex
.
To inject something dynamic like the filename or author, you'll have to create a custom step, and it's pretty straightforward to modify the LicenseStep to do this.
Thanks, @nedtwigg for the help and for pointing me in the right direction. Will have a look into this. Module
is dynamic. But based on what you suggested, I feel I should be able to validate the general structure of the license header.
Honestly, I'd be willing to add most of the copyright notice format to the license header functionality in a PR. I feel like that would definitely help people trying to migrate from the somewhat unreliable IntelliJ plugin to spotless without issue. The only issue is that I'm quite busy right now, so I won't be able to get to it immediately.
Hey, I was looking for the ability to add the file path in the license header and fell into this issue. Any updates @OxygenCobalt ? Do you have started something?
Published in plugin-maven 2.35.0
and plugin-gradle 6.17.0
thanks to @STAR-ZERO.