You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(If you add the shebang to the delimiter regex, it push the shebang under the license header, what would be invalid.)
hash.license:
#==========================================================================
# Copyright (c) Awesome Corp., 1980-2020.
#
# All rights reserved. All hardware and software names used are registered
# trade names and/or registered trademarks of the respective manufacturers.
#
# The user of this computer program acknowledges that the above copyright
# notice, which constitutes the Universal Copyright Convention, will be
# attached at the position in the function of the computer program which the
# author has deemed to sufficiently express the reservation of copyright.
# It is prohibited for customers, users and/or third parties to remove,
# modify or move this copyright notice.
#==========================================================================
#==========================================================================# Copyright (c) Awesome Corp., 1980-2020.## All rights reserved. All hardware and software names used are registered# trade names and/or registered trademarks of the respective manufacturers.## The user of this computer program acknowledges that the above copyright# notice, which constitutes the Universal Copyright Convention, will be# attached at the position in the function of the computer program which the# author has deemed to sufficiently express the reservation of copyright.# It is prohibited for customers, users and/or third parties to remove,# modify or move this copyright notice.#==========================================================================importsysprint("Hello world")
DESIRED OUTPUT:
#!/usr/bin/env python3#==========================================================================# Copyright (c) Awesome Corp., 1980-2020.## All rights reserved. All hardware and software names used are registered# trade names and/or registered trademarks of the respective manufacturers.## The user of this computer program acknowledges that the above copyright# notice, which constitutes the Universal Copyright Convention, will be# attached at the position in the function of the computer program which the# author has deemed to sufficiently express the reservation of copyright.# It is prohibited for customers, users and/or third parties to remove,# modify or move this copyright notice.#==========================================================================importsysprint("Hello world")
The problem is that this only works, when you have the same shebang for all python files.
But we also have #!/usr/bin/env python2. The same problem is there with linux script files.(#!/usr/bin/env sh | #!/usr/bin/env bash)
(comment deletions just to remove off-topic discussion and condense on the feature request)
Aha! This is a good feature request. It's tricky - the license step has so far had a very simple model: find the "top" of the file with regex Y, and then add header X. Solving this issue will require complicating the model somewhat.
A simple way to do this would be to allow something like $FIRST_LINE within the replacement text. So your hash.license could be
$FIRST_LINE
#==========================================================================
# Copyright (c) Awesome Corp., 1980-2020.
#
# All rights reserved. All hardware and software names used are registered
# trade names and/or registered trademarks of the respective manufacturers.
The other option would be to make the license step generally more powerful and context-sensitive, as @vlsi has done in his fork, linked above. I would definitely merge a PR to add support for $FIRST_LINE, since it is so simple. I'm also open to a more powerful context-sensitive option, but backwards compatibility and long-term maintenance burden would be an important challenge to keep in mind.
Activity
nedtwigg commentedon Dec 26, 2019
Can you provide an example?
vlsi commentedon Dec 28, 2019
@irrandon , you might want to give https://github.com/autostyle/autostyle a try
It supports Shell (e.g.
#!/), Batch (e.g.@echo off), XML (e.g.<?..?>), Java (includingpackage-info.javaandmodule-info.java), and Gradle (Kotlin / Gradle scripts) automatically.Samples: apache/jmeter#549, apache/calcite#1682
irrandon commentedon Jan 8, 2020
We have a temporary solution with a python script but a support via spotless would be nice :)
Here an example:
(If you add the shebang to the delimiter regex, it push the shebang under the license header, what would be invalid.)
hash.license:
EXAMPLE SCRIPT:
ACTUAL OUTPUT:
DESIRED OUTPUT:
nedtwigg commentedon Jan 8, 2020
An easy workaround is to put the
#!/usr/bin ...inside the license that you give to Spotless. Any problems with that?irrandon commentedon Jan 9, 2020
The problem is that this only works, when you have the same shebang for all python files.
But we also have #!/usr/bin/env python2. The same problem is there with linux script files.(#!/usr/bin/env sh | #!/usr/bin/env bash)
nedtwigg commentedon Jan 10, 2020
(comment deletions just to remove off-topic discussion and condense on the feature request)
Aha! This is a good feature request. It's tricky - the license step has so far had a very simple model: find the "top" of the file with regex Y, and then add header X. Solving this issue will require complicating the model somewhat.
A simple way to do this would be to allow something like
$FIRST_LINEwithin the replacement text. So yourhash.licensecould beThe other option would be to make the license step generally more powerful and context-sensitive, as @vlsi has done in his fork, linked above. I would definitely merge a PR to add support for $FIRST_LINE, since it is so simple. I'm also open to a more powerful context-sensitive option, but backwards compatibility and long-term maintenance burden would be an important challenge to keep in mind.
Minor refactor to LicenseHeaderStep to a more functional/immutable st…
abelk2 commentedon May 18, 2023
I think this is supported now with #1441.
nedtwigg commentedon May 22, 2023
Thanks @abelk2! Relevant example: