Lehks
Lehks

Reputation: 3176

clang-format normalized line endings

Is it possible to make clang-format normalize line endings to make the coherent in the entire project?

Like this:

int main() \n
{\r\n
     return 0;\n
}\r\n

would be formatted to:

int main() \n
{\n
     return 0;\n
}\n

Upvotes: 2

Views: 5110

Answers (2)

MikeOnline
MikeOnline

Reputation: 1224

Starting with Clang-Format version 16, you can specify the line endings to write in each file you format. For example, you could add the following to your .clang-format file:

# Set EOL to LF unconditionally
LineEnding: LF

Clang-Format 16 and newer also offer options to honor the prevailing line endings in each file you are formatting. For example:

# Set EOL to LF unless CR+LF is predominant
LineEnding: DeriveLF

For other LineEnding options such as CRLF see Clang-Format Style Options in the latest Clang-Format documentation.

Source files for LLVM 16.0.0-rc2 -- including the clang source, which includes Clang-Format in folder clang/tools/clang-format -- is currently available via the LLVM repository on GitHub. I do not know when a general release of Clang-Format 16 or newer will occur.

Upvotes: 5

ANjaNA
ANjaNA

Reputation: 1426

If you soppost to commit your code with git, you have a solution.

Optionally, you can configure the way Git manages line endings on a per-repository basis by configuring a special .gitattributes file.

Here's an example .gitattributes file.

Declare files that will always have CRLF line endings on checkout:

*.sln text eol=crlf

Further information can be find in this link

Upvotes: 0

Related Questions