aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler/qqmljslogger.cpp
diff options
context:
space:
mode:
authorOlivier De Cannière <olivier.decanniere@qt.io>2025-03-21 17:32:33 +0100
committerOlivier De Cannière <olivier.decanniere@qt.io>2025-03-25 22:54:42 +0100
commit7d02c86531b02b8cfe97fb0270fd171f716af4c0 (patch)
treebf73f3bd8831501fcef3b61d88aa4e49402817f7 /src/qmlcompiler/qqmljslogger.cpp
parentce69cc78c0aaa0afea5cd74d15ea37685948e6d0 (diff)
Compiler: Ensure uniqueness of logging categories
Added some macros to static_assert that the logging categories are unique in name, settings name and description. This excludes empty strings. A duplicate description was already found and fixed thanks to this. Change-Id: I9fd689065f5bb3a567143ed78211800f88543408 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljslogger.cpp')
-rw-r--r--src/qmlcompiler/qqmljslogger.cpp34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/qmlcompiler/qqmljslogger.cpp b/src/qmlcompiler/qqmljslogger.cpp
index cd6d4cd973..d289c80f52 100644
--- a/src/qmlcompiler/qqmljslogger.cpp
+++ b/src/qmlcompiler/qqmljslogger.cpp
@@ -53,8 +53,8 @@ using namespace Qt::StringLiterals;
QtWarningMsg, false, false) \
X(qmlPrefixedImportType, "prefixed-import-type", "PrefixedImportType", \
"Warn about prefixed import types", QtWarningMsg, false, false) \
- X(qmlIncompatibleType, "incompatible-type", "IncompatibleType", "Warn about missing types", \
- QtWarningMsg, false, false) \
+ X(qmlIncompatibleType, "incompatible-type", "IncompatibleType", \
+ "Warn about incompatible types", QtWarningMsg, false, false) \
X(qmlTranslationFunctionMismatch, "translation-function-mismatch", \
"TranslationFunctionMismatch", \
"Warn about usages of ID and non-ID translation functions in the same file.", QtWarningMsg, \
@@ -112,6 +112,36 @@ using namespace Qt::StringLiterals;
QMLLINT_DEFAULT_CATEGORIES
#undef X
+
+#define X(category, name, setting, description, level, ignored, isDefault) ++i;
+constexpr size_t numCategories = [] { size_t i = 0; QMLLINT_DEFAULT_CATEGORIES return i; }();
+#undef X
+
+constexpr bool isUnique(const std::array<std::string_view, numCategories>& fields) {
+ for (std::size_t i = 0; i < fields.size(); ++i) {
+ for (std::size_t j = i + 1; j < fields.size(); ++j) {
+ if (!fields[i].empty() && fields[i] == fields[j]) {
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+#define X(category, name, setting, description, level, ignored, isDefault) std::string_view(name),
+static_assert(isUnique(std::array{ QMLLINT_DEFAULT_CATEGORIES }), "Duplicate names found!");
+#undef X
+
+#define X(category, name, setting, description, level, ignored, isDefault) std::string_view(setting),
+static_assert(isUnique(std::array{ QMLLINT_DEFAULT_CATEGORIES }), "Duplicate settings found!");
+#undef X
+
+#define X(category, name, setting, description, level, ignored, isDefault) std::string_view(description),\
+
+static_assert(isUnique(std::array{ QMLLINT_DEFAULT_CATEGORIES }), "Duplicate description found!");
+#undef X
+
+
QQmlJSLogger::QQmlJSLogger()
{
static const QList<QQmlJS::LoggerCategory> cats = defaultCategories();