Lucas-C/pre-commit-hooks

insert-license should not add a LF at the end of the license header file if it does not have one, to prevent an ugly empty separator line

vorburger opened this issue · 2 comments

Salut! I ❤️ LOVE insert-license - this is GREAT! I just have 1 very small gripe with... 😃 I wish it wouldn't insert a new line! Details:

  - repo: https://github.com/Lucas-C/pre-commit-hooks
    rev: v1.4.2
    hooks:
      - id: insert-license
        files: \.java$
        args:
          - --comment-style
          - /*| *| */
          - --license-filepath
          - LICENSE-header.txt
          - --fuzzy-match-generates-todo
          - --use-current-year

That LICENSE-header.txt file DOES NOT end with a LF (e.g. perl -p -i -e 'chomp if eof' LICENSE-header.txt; and I've double-checked with hexedit that the last byte is not a 0A (LF), but a 2E for .). The *.java files which do not contain a license header will be updated to like this by insert-license:

...

 * limitations under the License.
 */

package dev.enola.k8s;

The empty line after */ before package bothers me (yeah, I know, hair splitting; sorry!) - and seems to be added by insert-license? Would it be possible to avoid it doing that, if the given file does not end in a newline?

I'm currently working around this by removing that separator line (and that's kept and not put back), but I wish it wouldn't add it in the first place...

Thank You again for insert-license!

Staring at the source code, I've just noticed that there is an --no-extra-eol... I'll try that out - and contrib a PR to update the README doc!

Staring at the source code, I've just noticed that there is an --no-extra-eol... I'll try that out - and contrib a PR to update the README doc!

Yes, --no-extra-eol should be the solution!

A PR to update the README.md would be welcome for sure 😊