nedbat / scriv

Changelog management tool

Home Page:https://scriv.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Final newline stripped from fragment template

SpecLad opened this issue · comments

When a custom new fragment template is used, scriv strips the final newline from it when it creates the fragment. For example, create the following scriv.ini:

[tool.scriv]
new_fragment_template = file: fragment.j2

Then create fragment.j2 as follows:

$ echo foobar > changelog.d/fragment.j2
00000000: 666f 6f62 6172 0a                        foobar. <-- note that the file ends with a newline

Now create a fragment and examine it:

$ scriv create
Creating changelog.d/20231004_201751_roman.rst
$ xxd changelog.d/20231004_201751_roman.rst
00000000: 666f 6f62 6172                           foobar <-- newline is gone!

This is mildly annoying, as I'd like all my text files to end with a newline.

The following is not a solution, but a general tip to enforce styles and preferences on projects.

To enforce this across all files -- regardless of what tool or generates the file -- you can use the "end-of-file-fixer" pre-commit hook to ensure that all text files end with a newline, a la:

repos:
  - repo: "https://github.com/pre-commit/pre-commit-hooks"
    rev: "v4.5.0"
    hooks:
      - id: "end-of-file-fixer"

That fixer will enforce that all files end with a newline before they can be committed to the repo.