Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
BasedOnStyle: Google
AlignAfterOpenBracket: DontAlign

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in the rare case where we exceed the ColumnLimit, aligning would improve readability.

AlignConsecutiveDeclarations: Consecutive

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This formats this:

float fmod_t(float num, float denom) {
  int tquot = num / denom;
  float res = num - tquot * denom;
  return res;
}

to this:

float fmod_t(float num, float denom) {
  int   tquot = num / denom;
  float res = num - tquot * denom;
  return res;
}

I prefer the first version.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree - the extra spaces in int tquot - to visually align it with the definition of float fmod_t - are confusing.

AlignEscapedNewlines: DontAlign

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was set because of your tool. I see no reason why we should set this to DontAlign since aligning would improve readability.

AlignOperands: DontAlign

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the rare case that this happens, I think aligning would improve readability here.

AlignTrailingComments: false
AllowAllArgumentsOnNextLine: false
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you want to set this to None?

Now this formats this:

int add(int a, int b) { return a + b; }

to this:

int add(int a, int b) {
  return a + b;
}

AllowShortIfStatementsOnASingleLine: Always
AlwaysBreakBeforeMultilineStrings: false
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The BreakConstructorInitializersBeforeComma should be replaced with the BreakConstructorInitializers option.

https://reviews.llvm.org/D32479

BreakStringLiterals: false
ColumnLimit: 240
ContinuationIndentWidth: 2
IndentPPDirectives: BeforeHash
KeepEmptyLinesAtTheStartOfBlocks: true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Deprecated empty-lines option
KeepEmptyLinesAtTheStartOfBlocks is deprecated. Update to the current equivalent (e.g., KeepEmptyLinesAtTopOfFunctions).

🤖 Prompt for AI Agents
In the .clang-format file at line 19, replace the deprecated option
KeepEmptyLinesAtTheStartOfBlocks with the current equivalent option
KeepEmptyLinesAtTopOfFunctions to ensure compatibility with the latest
clang-format versions.

MaxEmptyLinesToKeep: 2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should change this so that the code doesn't take up so many lines?

ReflowComments: false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should at least set this to IndentOnly so that misaligned comments are formatted.

SortIncludes: Never

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not?

SpacesBeforeTrailingComments: 1
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.cache
.clang-format
.direnv
.DS_Store
.idea
Expand Down
Loading