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

[Codestyle] Set clang-format RemoveSemicolon rule to true #97934

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

adamscott
Copy link
Member

@adamscott adamscott commented Oct 7, 2024

This should fix the superfluous semi-colons issue that takes a lot of time for some reviewers to flag in PRs.

@adamscott adamscott added this to the 4.4 milestone Oct 7, 2024
@adamscott adamscott requested review from a team as code owners October 7, 2024 15:05
@adamscott adamscott removed request for a team October 7, 2024 15:05
@adamscott adamscott removed request for a team October 7, 2024 15:05
@adamscott adamscott changed the title Set clang-format RemoveSemicolon rule to true [Codestyle] Set clang-format RemoveSemicolon rule to true Oct 7, 2024
@adamscott adamscott requested a review from Repiteo October 7, 2024 15:06
@adamscott adamscott requested a review from a team as a code owner October 7, 2024 15:08
@adamscott adamscott removed the request for review from a team October 7, 2024 15:11
@adamscott adamscott force-pushed the give-AThousandShips-a-break branch 3 times, most recently from 120802c to f125b8e Compare October 7, 2024 15:47
- Set clang-format `Standard` rule to `c++20`
- Add `FORCE_SEMICOLON` macro in core/typedefs.h
@AThousandShips
Copy link
Member

See also:

For a different approach (which doesn't apply to CI but allows us to fix this)

Comment on lines 502 to +505
SCOPE_EXIT {
_recursion_flag_ = false;
};
}
FORCE_SEMICOLON
Copy link
Member Author

Choose a reason for hiding this comment

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

Here's an example of the use of FORCE_SEMICOLON. Only use when the formatter is stubborn removing a necessary semi-colon.

Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively:

	SCOPE_EXIT { // clang-format off
		_recursion_flag_ = false;
	}; // clang-format on

Copy link
Member Author

@adamscott adamscott Oct 7, 2024

Choose a reason for hiding this comment

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

I don't know. Like, yeah it works, but what if a format error is introduced between them?
What I mean is that it's the only case in the whole codebase that it occurs.

Copy link
Contributor

@Repiteo Repiteo Oct 8, 2024

Choose a reason for hiding this comment

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

If format errors in between are the concern, just move the // clang-format off down one line. Because the settings only apply to subsequent lines, this will turn clang-format off only for the line with the semicolon.

	SCOPE_EXIT {
		_recursion_flag_ = false; // clang-format off
	}; // clang-format on

While that's the option I'd prefer most, here's two more alternatives: after looking at the SCOPE_EXIT macro, it turns out this is the only place in the entire repo where it's used. I'd sooner say to either remove that macro entirely, or replace it with a version that wraps the content itself, both of which will fix clang-format removing the semicolon.

	gdmono::ScopeExit GD_UNIQUE_NAME(gd_scope_exit) = gdmono::ScopeExitAux() + [=]() -> void {
		_recursion_flag_ = false;
	};
#define SCOPE_EXIT(m_content) \
	auto GD_UNIQUE_NAME(gd_scope_exit) = gdmono::ScopeExitAux() + [=]() -> void { m_content };
//////////
	SCOPE_EXIT(_recursion_flag_ = false;)

I prefer these workarounds because I see FORCE_SEMICOLON better used for ensuring a trailing semicolon on macro. Here's an excerpt from one of my prospective PRs that wanted to tackle this on the clang-tidy scope:

// By appending to a macro, ensures that it'll require a trailing semicolon.
#ifndef FORCE_SEMICOLON
#define FORCE_SEMICOLON static_assert(true)
#endif

static_assert produces zero build-time bloat, being a functionally "free" addition (especially in this always-true context). What it does provide is a way to require a trailing semicolon in virtually any context, as static_assert requires a semicolon to follow its declaration.

Copy link
Contributor

@Repiteo Repiteo left a comment

Choose a reason for hiding this comment

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

I disagree with FORCE_SEMICOLON being added in this context (see #97934 (comment)), but I'm otherwise onboard with this! I'd recommend a .git-blame-ignore-revs commit as well, as there's no functional changes to speak of.

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