aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2021-05-12 13:23:59 +0200
committerMaximilian Goldstein <max.goldstein@qt.io>2021-05-14 10:43:41 +0200
commit401b515626c46d915a8394a98fbe95cf1c6f4aa4 (patch)
tree2b3b78b371534b18f1bdb6ab38411743ab1479f4
parente6bc19d518b92d47639de871e255bfe73118cd17 (diff)
qmllint: Utilize qjsroot.qmltypes
Previously for some types like QString, QDateTime and QRegularExpression and others there was no sensible type information available. Now that we have qjsroot.qmltypes we can refer to its type information in order to resolve these types. Change-Id: Iea88cf467c694299396630e0f180ca6ff4ca3847 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--src/imports/builtins/builtins.qmltypes9
-rw-r--r--src/qmlcompiler/qqmljsimporter.cpp16
-rw-r--r--tests/auto/qml/qmllint/data/qjsroot.qml20
-rw-r--r--tests/auto/qml/qmllint/tst_qmllint.cpp1
-rw-r--r--tools/qmllint/checkidentifiers.cpp10
5 files changed, 41 insertions, 15 deletions
diff --git a/src/imports/builtins/builtins.qmltypes b/src/imports/builtins/builtins.qmltypes
index a9cc4ea4d7..f1a57cfab3 100644
--- a/src/imports/builtins/builtins.qmltypes
+++ b/src/imports/builtins/builtins.qmltypes
@@ -88,6 +88,7 @@ Module {
Component {
name: "number"
+ extension: "Number"
accessSemantics: "value"
}
@@ -115,6 +116,7 @@ Module {
Component {
name: "QString"
+ extension: "String"
exports: ["QML/string 1.0"]
exportMetaObjectRevisions: [256]
accessSemantics: "value"
@@ -129,6 +131,7 @@ Module {
Component {
name: "QDateTime"
+ extension: "Date"
exports: ["QML/date 1.0"]
exportMetaObjectRevisions: [256]
accessSemantics: "value"
@@ -151,4 +154,10 @@ Module {
name: "QVariantMap"
accessSemantics: "value"
}
+
+ Component {
+ name: "QRegularExpression"
+ extension: "RegExp"
+ accessSemantics: "value"
+ }
}
diff --git a/src/qmlcompiler/qqmljsimporter.cpp b/src/qmlcompiler/qqmljsimporter.cpp
index 0f184c4419..c8107ecd4d 100644
--- a/src/qmlcompiler/qqmljsimporter.cpp
+++ b/src/qmlcompiler/qqmljsimporter.cpp
@@ -271,7 +271,7 @@ void QQmlJSImporter::processImport(const QQmlJSImporter::Import &import,
}
/*!
- * Imports builtins.qmltypes found in any of the import paths.
+ * Imports builtins.qmltypes and jsroot.qmltypes found in any of the import paths.
*/
QQmlJSImporter::ImportedTypes QQmlJSImporter::importBuiltins()
{
@@ -284,16 +284,22 @@ QQmlJSImporter::AvailableTypes QQmlJSImporter::builtinImportHelper()
if (!m_builtins.qmlNames.isEmpty() || !m_builtins.cppNames.isEmpty())
return m_builtins;
+ Import result;
for (auto const &dir : m_importPaths) {
- Import result;
- QDirIterator it { dir, QStringList() << QLatin1String("builtins.qmltypes"), QDir::NoFilter,
- QDirIterator::Subdirectories };
+ QDirIterator it { dir,
+ QStringList() << QStringLiteral("builtins.qmltypes")
+ << QStringLiteral("jsroot.qmltypes"),
+ QDir::NoFilter, QDirIterator::Subdirectories };
while (it.hasNext())
readQmltypes(it.next(), &result.objects, &result.dependencies);
+
importDependencies(result, &m_builtins);
- processImport(result, &m_builtins);
}
+ // Process them together since there they have interdependencies that wouldn't get resolved
+ // otherwise
+ processImport(result, &m_builtins);
+
return m_builtins;
}
diff --git a/tests/auto/qml/qmllint/data/qjsroot.qml b/tests/auto/qml/qmllint/data/qjsroot.qml
new file mode 100644
index 0000000000..c5995b9576
--- /dev/null
+++ b/tests/auto/qml/qmllint/data/qjsroot.qml
@@ -0,0 +1,20 @@
+import QtQuick
+
+QtObject {
+ property var locale: Qt.locale()
+ property date currentDate: new Date()
+ property RegularExpressionValidator validator: RegularExpressionValidator { regularExpression: /20([0-9]+)/ };
+ property double pi: 3.14
+
+ // Test date
+ property string dateString: currentDate.toLocaleDateString();
+
+ // Test string
+ property int dateStringDotIndex: dateString.indexOf(".")
+
+ // Test regularExpression
+ property var dateStringReplace: validator.regularExpression.exec(dateString)
+
+ // Test double
+ property string fixedPi: pi.toFixed(1)
+}
diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp
index df303088bf..d6f5088a9d 100644
--- a/tests/auto/qml/qmllint/tst_qmllint.cpp
+++ b/tests/auto/qml/qmllint/tst_qmllint.cpp
@@ -747,6 +747,7 @@ void TestQmllint::cleanQmlCode_data()
QTest::newRow("aliasToList") << QStringLiteral("aliasToList.qml");
QTest::newRow("QVariant") << QStringLiteral("qvariant.qml");
QTest::newRow("Accessible") << QStringLiteral("accessible.qml");
+ QTest::newRow("qjsroot") << QStringLiteral("qjsroot.qml");
}
void TestQmllint::cleanQmlCode()
diff --git a/tools/qmllint/checkidentifiers.cpp b/tools/qmllint/checkidentifiers.cpp
index 66903c29a8..72e0d6fd7d 100644
--- a/tools/qmllint/checkidentifiers.cpp
+++ b/tools/qmllint/checkidentifiers.cpp
@@ -87,9 +87,6 @@ void CheckIdentifiers::checkMemberAccess(const QVector<FieldMember> &members,
if (prop != nullptr && prop->isList()) {
detectedRestrictiveKind = QLatin1String("list");
expectedNext.append(QLatin1String("length"));
- } else if (outerScope->internalName() == QLatin1String("QString")) {
- detectedRestrictiveKind = QLatin1String("QString");
- expectedNext.append(QLatin1String("length"));
}
QQmlJSScope::ConstPtr scope = outerScope;
@@ -136,13 +133,6 @@ void CheckIdentifiers::checkMemberAccess(const QVector<FieldMember> &members,
continue;
}
- if (typeName == QLatin1String("QString")) {
- detectedRestrictiveKind = typeName;
- detectedRestrictiveName = access.m_name;
- expectedNext.append(QLatin1String("length"));
- continue;
- }
-
if (access.m_parentType.isEmpty()) {
if (binding.hasValue())
scope = binding.value();