Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .clang-format #1866

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

takase1121
Copy link
Member

This would probably be a polarizing, if not controversial, PR.

This PR adds .clang-format based on the current code style, which would format most source files except the UTF8 library since that library doesn't seem to have been created by us.

Please refer to the changelog in the individual commit to see what is actually being done.

@takase1121
Copy link
Member Author

While we have this .clang-format file, it might be worth discussing what to do with it going forward. We should consider checking if the PRs are properly formatted. We could also consider enforcing this as a procedure when creating PRs.

I don't want people to "fight the formatter" or spend too much time making the code format well with clang-tidy. There's no hard requirement to never disable clang-format, as long as they're reasonable.

Copy link
Member

@Guldoman Guldoman left a comment

Choose a reason for hiding this comment

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

Main things I don't really like:

  • It tries to align stuff with tons of spaces. I could understand a few spaces, but in some places it's more spaces than actual code...
  • It merges small if blocks into a single line
  • It merges small functions into a single line

I think we should avoid doing a big commit with all these changes, and just add them when we touch the respective code.
I understand that it might be a bit of a chore, but I think a big commit like this makes git blame more annoying to work with.

Still, having a .clang-format that has a final say on what the formatting should be is a good thing.

src/api/dirmonitor.c Outdated Show resolved Hide resolved
src/api/dirmonitor.c Outdated Show resolved Hide resolved
Comment on lines 61 to 66
static void stream_callback(ConstFSEventStreamRef streamRef,
void *monitor_ptr,
size_t numEvents,
void *eventPaths,
const FSEventStreamEventFlags eventFlags[],
const FSEventStreamEventId eventIds[]) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I like this. What other formatting alternatives are there?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's pretty this or align the parameters on a newline.

src/api/dirmonitor/fsevents.c Outdated Show resolved Hide resolved
src/api/system.c Show resolved Hide resolved
@takase1121 takase1121 force-pushed the chore/clang-format branch 2 times, most recently from b179e9b to ecc83e1 Compare July 27, 2024 21:58
@aqilc
Copy link
Contributor

aqilc commented Jul 28, 2024

This formatting sucks overall and is super (badly) opinionated. There's no problems with readability in the current codebase so this commit is completely unnecessary. The inconsistencies in the codebase can be fixed manually and instead of forcing formatting, put the coding style in the contributing doc.

@takase1121
Copy link
Member Author

This formatting sucks overall and is super (badly) opinionated. There's no problems with readability in the current codebase so this commit is completely unnecessary. The inconsistencies in the codebase can be fixed manually and instead of forcing formatting, put the coding style in the contributing doc.

I would greatly appreciate constructive feedback on the formatting. I believe formatting code is indeed an opinionated (and mostly opinion-based) business. There should be minimal compromises (sticking to a known code style) or no compromises (like Black, which enforces a single style) for how code should look. Ultimately I am biased towards no-compromises formatting like Black and go fmt, but for now this formatting is indeed based on the current codebase.

The intention of adding .clang-format is to fix consistencies in the codebase. Fixing the inconsistencies manually is possible but takes time, which could be better utilized to do something else. The whole point of having .clang-format is to remove the need to format code and make mistakes when doing so manually.

I suggest you check out the PR in an editor and read it instead of using GitHub's diff view. That way, you would get complete context of the changed lines (by clang-format) and understand that the code really hasn't changed that much. There are some rough edges, but in my opinion, this is decently familiar with our current codebase.

As @Guldoman suggested, the real issue here is how to deploy a code style, whether in the form of clang-format or documentation. If we merge this commit as-is (which I've warned not to do) it will cause issues with Git blame, so we may need to explore that.

…ting

This will certainly be a polarizing, if not controversial PR.
I scanned the project with Clang Format Editor and edited some of the values
to match the current project as close as possible.
It will not be an exact match, but I think it is good enough.
@takase1121
Copy link
Member Author

I experimented with aligning the pointer to the left instead of the right; it appears that we have about the same amount of code that aligns in both directions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants