codeformatter
codeformatter copied to clipboard
Add code formatting rule to add newlines at the end of code files
@stephentoub has pointed out that text files should end with a newline. This PR adds a code formatting rule to do this for C# source code files.
I guess I'll close #61 then. I never got to finishing it anyway. This closes #54.
Thanks for the pointer to #61 @khellang. Based on reading the discussion there, I've fixed the rule for cases where there are comments or compiler directives at the end of the file.
For simplicity, this PR merely makes sure that the file ends with a newline (in contrast with #61). It doesn't try to prevent it from ending with multiple newlines.
Ahh i just implemented this before seeing this PR :)
@dsplaisted: Can you rebase these commits, it's difficult to code review with context in different commits.
Won't this conflict with the standard formatter rule? The formatter by default will delete new lines at the end of the file.
Note that this is only required in case of CRLF on Windows. If you are using LF in editor, extra linefeed will persist in diff, which means git doesn't require additional line-break.
I think git converts CRLF+CRLF
as LF
for end of file and considers single CRLF as invalid end of file terminator.
One standard way to solve this problem is to have LF rule for all sources in .gitattributes file like this:
[*]
end_of_line = lf
// or
[*.cs, *.vb, *.csproj]
end_of_line = lf
(in corefx repository, .gitattributes is present, but almost never used: all rules are commented out)
Note, git only apply the .gitattributes rules on commit
, meaning your local formatting will stay intact.