Add File Header Management (License / Copyright)#5264
Add File Header Management (License / Copyright)#5264arashi01 wants to merge 3 commits intoscalameta:mainfrom
Conversation
|
@arashi01 thank you for your contribution. unfortunately, this is not at all how i think it should be done. if you are inclined to pursue this further, please let me know, and we can brainstorm ways to design it. |
# Conflicts: # scalafmt-core/shared/src/main/scala/org/scalafmt/config/ScalafmtConfig.scala
|
@kitbellew Happy to do so. Let me know your preferred approach |
|
the preferred approach is to do nothing and direct people to dedicated tools like https://github.com/sbt/sbt-header. Happy to consider adding logic to scalafmt that avoids formatting comment if it's the first token on the file. |
|
So what you are saying is that there is no approach that you would find acceptable incorporating header formatting into a formatting tool? |
why is it needed here if there's a dedicated tool? adding unrelated disclaimers is not formatting. |
|
to be more precise: i would be ok with the following:
Here's the tricky part: the change should only apply to files which have changed, so you can conceivably do it in CLI since you know if the tool was called with a |
|
@kitbellew thanks for your feedback.
My thoughts on this:
This is already the case no? When the header is correct,
Happy to drop the SPDX templates and require the full header text in config.
I went with the pre-format text approach because headers are not AST constructs. |
I should clarify. What you are describing is These headers frequently include some reference to a year, and that year presumably changes as files get updated; if one file says "Copyright 1970-2025", I don't see a reason to update that line in 2026 unless the file has changed materially in other ways. Thus, scalafmt should not change the year in a file which wasn't modified, thus it needs to know which files are modified.
P.S. Did you write the code yourself? :) |
That's fairly easy to address.
If providing the header as static text in config then that is feasible. With the current flexibility and config less so.
Very much so. Why, is it that terrible? 😂 |
Adds copyright/header management. Revisits #705
Whilst this issue was brought up previously, hopefully it can be reconsidered. In my view, a formatter/linter enforces canonical source file form. Headers are part of that form. With header management in the build tool (
sbt-header), identical source files under identical.scalafmt.confproduce different results depending on whether the project uses sbt, Mill, Gradle, scala-cli, Maven etc. Moving this to the formatter guarantees uniform sources regardless of build toolchain - the same guarantee scalafmt already provides for indentation, line endings, and import order.This is one possible take at the problem
Scalafmt.doFormat, beforedoFormatOne) since:--checkworks with no additional codefileHeaderconfig section.yeardefaults to current calendar year but can be pinned explicitly in configsincesets range start:since = 2020with current year 2026 produces2020-2026Example config: