aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler/qqmljslogger.cpp
diff options
context:
space:
mode:
authorSami Shalayel <sami.shalayel@qt.io>2025-11-20 14:34:40 +0100
committerSami Shalayel <sami.shalayel@qt.io>2025-11-26 19:53:53 +0100
commit11f9dd7fcbad2abc169d64cecf4ab15b329720cb (patch)
tree5fd58eae092a970be1a285b469d996b51ba52719 /src/qmlcompiler/qqmljslogger.cpp
parent9ab13be95a531fc9c1b7f472c75ef8fa880a7206 (diff)
qmllint: warn on shadowed properties/signals/methods
Warn when shadowing properties/signals/methods in qmllint. Move the already existing duplicate property check into its own static method warnForDuplicates, and extend it to check whether base types also have a property of the same name. Use it when analysing definitions of methods, signals and properties in qmljsimportvisitor to warn about shadowed properties. As a drive-by change, fix the sourcelocation of the duplicated property warning to point to the name of the property/signal/method instead of the "property" or "function" keyword. To avoid adding more testcases to the already big tst_qmllint::dirtyQmlSnippets_data(), create a new tst_qmllint::shadow_data() method for the shadow related tests, and make tst_qmllint::shadow() call dirtyQmlSnippet(). This allows to reuse the test code from dirtyQmlSnippet without making dirtyQmlSnippets_data grow even more. Adapt some existing test-cases by adding qmllint disable directives where shadowing was wanted, and disable the shadow category on tst_qqmljsscope (which does not make use of the qmllint code that reads qmllint disable directives), as it seems that tst_qqmljsscope tests that shadowing works as expected (shadowing is a feature, after all...). I guess this patch might need to be updated in the future once we have override and virtual properties in QML via QTBUG-98320. Make the qmlShadow warning non-critical for qmltc, as qmltc supports shadowing, to avoid breaking the qmltc tests. Task-number: QTBUG-141854 Change-Id: I74c1b413e2c19a0db34215b34a9b65d43fbef6ce Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljslogger.cpp')
-rw-r--r--src/qmlcompiler/qqmljslogger.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/qmlcompiler/qqmljslogger.cpp b/src/qmlcompiler/qqmljslogger.cpp
index d98ccaf753..74a1670420 100644
--- a/src/qmlcompiler/qqmljslogger.cpp
+++ b/src/qmlcompiler/qqmljslogger.cpp
@@ -121,6 +121,8 @@ using namespace Qt::StringLiterals;
false, false) \
X(qmlRestrictedType, "restricted-type", "RestrictedType", "Warn about restricted types", \
QtWarningMsg, false, false) \
+ X(qmlShadow, "shadow", "Shadow", "Warn about shadowing attributes from a base class", \
+ QtWarningMsg, false, false) \
X(qmlSignalParameters, "signal-handler-parameters", "BadSignalHandlerParameters", \
"Warn about bad signal handler parameters", QtWarningMsg, false, false) \
X(qmlStalePropertyRead, "stale-property-read", "StalePropertyRead", \