Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Add code formatting rule to add newlines at the end of code files #127

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

dsplaisted
Copy link
Member

@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.

@khellang
Copy link
Member

I guess I'll close #61 then. I never got to finishing it anyway. This closes #54.

@dsplaisted
Copy link
Member Author

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.

@Priya91
Copy link
Contributor

Priya91 commented Jun 3, 2015

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.

@jaredpar
Copy link
Member

jaredpar commented Jun 4, 2015

Won't this conflict with the standard formatter rule? The formatter by default will delete new lines at the end of the file.

@ghost
Copy link

ghost commented Jun 6, 2015

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.

Base automatically changed from master to main March 11, 2021 16:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants