Ensure single trailing newline in source files - #6782
Conversation
|
This is if we want to go all in with ensuring source files (not only installer and generator templates, as in #6781) follow the UNIX convention. The two PRs are complementary, not mutually exclusive. The But it has one caveat: the |
7849f1b to
fbaf32c
Compare
Reduce future code churn by gating source files with a test that ensures
tracked text files in the repository end with a single trailing newline
(UNIX convention).
Alternatives to enforce this without a test:
An .editorconfig file at the root of the repository makes most editors
automatically insert a final newline and trim trailing whitespace on
save, preventing the problem at the source:
root = true
[*]
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
charset = utf-8
A .gitattributes file makes Git itself flag whitespace issues in diffs,
on apply, and on merge:
* text=auto eol=lf whitespace=blank-at-eol,blank-at-eof
Both files support per-path exceptions. In .editorconfig, a section like
[*.png] can override any setting. In .gitattributes, paths can opt out
with -whitespace or be marked as binary (e.g. "*.png binary").
fbaf32c to
67fa0be
Compare
|
Rebased on top of main after #6781 has been merged. Many of the trailing newlines in source files were handled there. The only "offender" left is the PR template in |
| ### Expected behavior | ||
|
|
||
| <!-- | ||
| Describe the expected behaviour. |
There was a problem hiding this comment.
I noticed the template uses both "behavior" (US spelling) and "behaviour" (UK spelling, also technical term in Erlang/Elixir).
Maybe we could update towards one or the other for local consistency.
Reduce future code churn by gating source files with a test that ensures tracked text files in the repository end with a single trailing newline (UNIX convention).
Alternatives to enforce this without a test:
An
.editorconfigfile at the root of the repository makes most editors automatically insert a final newline and trim trailing whitespace on save, preventing the problem at the source:A
.gitattributesfile makes Git itself flag whitespace issues in diffs, on apply, and on merge:Both files support per-path exceptions. In
.editorconfig, a section like[*.png]can override any setting. In.gitattributes, paths can opt out with-whitespaceor be marked as binary (e.g.*.png binary).