aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2025-05-21 15:21:41 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2025-06-11 17:05:24 +0200
commita4ef8ef8f74241a95f17c6a0e478468ee70eebd4 (patch)
treef4402192c5e6fe6eed722cfa96f92f11e5fa4edf
parent063cb0becd037e167dbbb188d95e60e60c898529 (diff)
qmllint: Recognize transparent as a color in quick plugin
Besides the named constants and (A)RGB representations, QColor::fromString (which is used to parse valid strings) also supports using "transparent". The linter however did not handle this special case so far. This commit adds the missing support. We don't add "transparent" to the list of known color names to mirror the documentation in QColor::fromString: "transparent" is not actually a color keyword, but a separate check. Amends 53ccd321360a6a88c606210631169741041cf540 Fixes: QTBUG-137054 Change-Id: Ic031144b888d3fa892a87c44b4bffdc4c21bebf8 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
-rw-r--r--src/plugins/qmllint/quick/quicklintplugin.cpp3
-rw-r--r--tests/auto/qml/qmllint/tst_qmllint.cpp1
2 files changed, 4 insertions, 0 deletions
diff --git a/src/plugins/qmllint/quick/quicklintplugin.cpp b/src/plugins/qmllint/quick/quicklintplugin.cpp
index 2876477d95..c030cead18 100644
--- a/src/plugins/qmllint/quick/quicklintplugin.cpp
+++ b/src/plugins/qmllint/quick/quicklintplugin.cpp
@@ -717,6 +717,9 @@ void ColorValidatorPass::onBinding(const QQmlSA::Element &element, const QString
if (std::binary_search(m_colorNames.cbegin(), m_colorNames.cend(), colorName))
return;
+ if (colorName == u"transparent")
+ return;
+
auto suggestion = QQmlJSUtils::didYouMean(
colorName, m_colorNames,
QQmlSA::SourceLocationPrivate::sourceLocation(binding.sourceLocation()));
diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp
index 75749107a7..3982e0ed26 100644
--- a/tests/auto/qml/qmllint/tst_qmllint.cpp
+++ b/tests/auto/qml/qmllint/tst_qmllint.cpp
@@ -1531,6 +1531,7 @@ void TestQmllint::cleanQmlSnippet_data()
QTest::newRow("color-name") << u"property color myColor: \"blue\""_s << defaultOptions;
QTest::newRow("color-name2") << u"property color myColor\nmyColor: \"grEen\""_s
<< defaultOptions;
+ QTest::newRow("color-transparent") << u"property color myColor: \"transparent\""_s << defaultOptions;
{
CallQmllintOptions options;
options.rootUrls.append(testFile("ContextProperties/src"_L1));