diff options
author | Olivier De Cannière <olivier.decanniere@qt.io> | 2023-06-06 15:39:05 +0200 |
---|---|---|
committer | Olivier De Cannière <olivier.decanniere@qt.io> | 2023-06-08 14:04:16 +0000 |
commit | ba21c3876b53b0780716e91ead53a27fd7e85477 (patch) | |
tree | 195c590be30e68b15d123040c3039961dfee90ee | |
parent | f447e10dcd78aa2f978465a66af8233ed9256628 (diff) |
sanitize-commit: Warn about extraneous semicolons after Qt macros
This patch adds checks for extraneous semicolons after Qt macros. These
macros can be 'object-like' such as Q_OBJECT or 'function-like' such as
'Q_PROPERTY(...)'. The macros are grouped in two lists according to
their type. These lists can easily be expanded in the future by adding
new entries.
Change-Id: Ia7237381de768efe357ab5b790eee100bd282e69
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rwxr-xr-x | git-hooks/sanitize-commit | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/git-hooks/sanitize-commit b/git-hooks/sanitize-commit index fd1038d..1e32529 100755 --- a/git-hooks/sanitize-commit +++ b/git-hooks/sanitize-commit @@ -750,6 +750,34 @@ sub flushFile() complain_style(); } +my $object_like_macro = qr/ + ( + QT_USE_NAMESPACE | + QT_BEGIN_INCLUDE_NAMESPACE | + QT_END_INCLUDE_NAMESPACE | + QT_BEGIN_NAMESPACE | + QT_END_NAMESPACE | + Q_OBJECT | + Q_GADGET | + QML_ELEMENT + ); +/x; + +my $function_like_macro = qr/ + ( + QT_FORWARD_DECLARE_CLASS | + QT_FORWARD_DECLARE_STRUCT | + Q_PROPERTY | + Q_DECLARE_PUBLIC | + Q_DECLARE_PRIVATE | + Q_DECLARE_PRIVATE_D | + Q_DISABLE_COPY | + Q_DISABLE_COPY_MOVE | + QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP | + QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP + )\([^)]*\); +/x; + my $merge; my $new_file; my $foreign; @@ -888,6 +916,10 @@ while (<DIFF>) { if (/QT_(?:DISABLE_)?DEPRECATED_/) { complain_ln("Deprecation adjustments already submitted?", "", -1); } + # Check for extraneous semicolon after macros. + if ($_ =~ $object_like_macro || $_ =~ $function_like_macro) { + styleFail("Semicolon after $1"); + } } else { flushChunk() if ($chunk); if (/^ /) { |