diff options
| author | Sami Shalayel <sami.shalayel@qt.io> | 2025-11-20 14:34:40 +0100 |
|---|---|---|
| committer | Sami Shalayel <sami.shalayel@qt.io> | 2025-11-26 19:53:53 +0100 |
| commit | 11f9dd7fcbad2abc169d64cecf4ab15b329720cb (patch) | |
| tree | 5fd58eae092a970be1a285b469d996b51ba52719 /src/qmlcompiler/qqmljsloggingutils.h | |
| parent | 9ab13be95a531fc9c1b7f472c75ef8fa880a7206 (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/qqmljsloggingutils.h')
| -rw-r--r-- | src/qmlcompiler/qqmljsloggingutils.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/qmlcompiler/qqmljsloggingutils.h b/src/qmlcompiler/qqmljsloggingutils.h index 10dca55ae3..78e876fbeb 100644 --- a/src/qmlcompiler/qqmljsloggingutils.h +++ b/src/qmlcompiler/qqmljsloggingutils.h @@ -84,6 +84,7 @@ extern const Q_QMLCOMPILER_EXPORT QQmlSA::LoggerWarningId qmlRecursionDepthError extern const Q_QMLCOMPILER_EXPORT QQmlSA::LoggerWarningId qmlRedundantOptionalChaining; extern const Q_QMLCOMPILER_EXPORT QQmlSA::LoggerWarningId qmlRequired; extern const Q_QMLCOMPILER_EXPORT QQmlSA::LoggerWarningId qmlRestrictedType; +extern const Q_QMLCOMPILER_EXPORT QQmlSA::LoggerWarningId qmlShadow; extern const Q_QMLCOMPILER_EXPORT QQmlSA::LoggerWarningId qmlSignalParameters; extern const Q_QMLCOMPILER_EXPORT QQmlSA::LoggerWarningId qmlStalePropertyRead; extern const Q_QMLCOMPILER_EXPORT QQmlSA::LoggerWarningId qmlSyntax; |
