-
Notifications
You must be signed in to change notification settings - Fork 461
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
Support license header with shebang #496
Comments
Can you provide an example? spotless {...} # EXAMPLE SCRIPT:
# ACTUAL OUTPUT:
# DESIRED OUTPUT: |
@irrandon , you might want to give https://github.com/autostyle/autostyle a try It supports Shell (e.g. Samples: apache/jmeter#549, apache/calcite#1682 |
We have a temporary solution with a python script but a support via spotless would be nice :) Here an example: spotless{
format('python') {
licenseHeaderFile 'com/company/gradle/hash.license', '(import |""")'
target '**/*.py'
}
} (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:#!/usr/bin/env python3
import sys
print("Hello world") ACTUAL OUTPUT:#==========================================================================
# 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.
#==========================================================================
import sys
print("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.
#==========================================================================
import sys
print("Hello world") |
An easy workaround is to put the |
The problem is that this only works, when you have the same shebang for all python files. |
(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
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. |
…yle. Makes it clear that an inner class ought to be used in the future, especially to support diffplug#496.
I think this is supported now with #1441. |
Thanks @abelk2! Relevant example: format "licenseHeaderSh", {
target "*.sh"
licenseHeaderFile(file("$rootDir/config/license/sh.txt"), "^(?!##).+")
.skipLinesMatching("^#!.+?\$")
// license header MUST start with ##
} |
Hi,
for the license header step to work for linux script files correct handling of shebang lines is required.
Currently it is not handled correctly.
The text was updated successfully, but these errors were encountered: