aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <[email protected]>2020-04-23 10:10:31 +0200
committerFabian Kosmale <[email protected]>2020-04-24 11:46:35 +0200
commitb5fa1411a0109c332ffc7c3dbe9145f7ecc2c9a7 (patch)
tree889b3e6b40e3b0ed6b2b538b5b18015eeba5304e
parentaf521a8df6caec41f626a4b3319601c20adff711 (diff)
qmllint: Show filename in addition to line and column
Fixes: QTBUG-83684 Change-Id: If15a9498ae223dccfbafe88b14453a4b180247d9 Reviewed-by: Ulf Hermann <[email protected]>
-rw-r--r--tests/auto/qml/qmllint/tst_qmllint.cpp26
-rw-r--r--tools/qmllint/checkidentifiers.cpp22
-rw-r--r--tools/qmllint/checkidentifiers.h5
-rw-r--r--tools/qmllint/findunqualified.cpp2
4 files changed, 32 insertions, 23 deletions
diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp
index 04e2054e37..e7088d7cf5 100644
--- a/tests/auto/qml/qmllint/tst_qmllint.cpp
+++ b/tests/auto/qml/qmllint/tst_qmllint.cpp
@@ -77,7 +77,7 @@ void TestQmllint::testUnqualified()
QFETCH(int, warningColumn);
const QString output = runQmllint(filename, false);
- QVERIFY(output.contains(QString::asprintf("Warning: unqualified access at %d:%d", warningLine, warningColumn)));
+ QVERIFY(output.contains(QString::asprintf("Warning: unqualified access at %s:%d:%d", testFile(filename).toUtf8().constData(), warningLine, warningColumn)));
QVERIFY(output.contains(warningMessage));
}
@@ -122,47 +122,47 @@ void TestQmllint::dirtyQmlCode_data()
QTest::newRow("Invalid_syntax_QML")
<< QStringLiteral("failure1.qml")
- << QStringLiteral("failure1.qml:4 : Expected token `:'")
+ << QStringLiteral("%1:4 : Expected token `:'")
<< QString();
QTest::newRow("Invalid_syntax_JS")
<< QStringLiteral("failure1.js")
- << QStringLiteral("failure1.js:4 : Expected token `;'")
+ << QStringLiteral("%1:4 : Expected token `;'")
<< QString();
QTest::newRow("AutomatchedSignalHandler")
<< QStringLiteral("AutomatchedSignalHandler.qml")
- << QString("Warning: unqualified access at 12:36")
+ << QString("Warning: unqualified access at %1:12:36")
<< QStringLiteral("no matching signal found");
QTest::newRow("MemberNotFound")
<< QStringLiteral("memberNotFound.qml")
- << QString("Warning: Property \"foo\" not found on type \"QtObject\" at 6:31")
+ << QString("Warning: Property \"foo\" not found on type \"QtObject\" at %1:6:31")
<< QString();
QTest::newRow("UnknownJavascriptMethd")
<< QStringLiteral("unknownJavascriptMethod.qml")
- << QString("Warning: Property \"foo2\" not found on type \"Methods\" at 5:25")
+ << QString("Warning: Property \"foo2\" not found on type \"Methods\" at %1:5:25")
<< QString();
QTest::newRow("badAlias")
<< QStringLiteral("badAlias.qml")
- << QString("Warning: unqualified access at 4:27")
+ << QString("Warning: unqualified access at %1:4:27")
<< QString();
QTest::newRow("badAliasProperty")
<< QStringLiteral("badAliasProperty.qml")
- << QString("Warning: Property \"nowhere\" not found on type \"QtObject\" at 5:32")
+ << QString("Warning: Property \"nowhere\" not found on type \"QtObject\" at %1:5:32")
<< QString();
QTest::newRow("badParent")
<< QStringLiteral("badParent.qml")
- << QString("Warning: Property \"rrr\" not found on type \"Item\" at 5:34")
+ << QString("Warning: Property \"rrr\" not found on type \"Item\" at %1:5:34")
<< QString();
QTest::newRow("parentIsComponent")
<< QStringLiteral("parentIsComponent.qml")
- << QString("Warning: Property \"progress\" not found on type \"QQuickItem\" at 7:39")
+ << QString("Warning: Property \"progress\" not found on type \"QQuickItem\" at %1:7:39")
<< QString();
QTest::newRow("badTypeAssertion")
<< QStringLiteral("badTypeAssertion.qml")
- << QString("Warning: Property \"rrr\" not found on type \"Item\" at 5:39")
+ << QString("Warning: Property \"rrr\" not found on type \"Item\" at %1:5:39")
<< QString();
QTest::newRow("incompleteQmltypes")
<< QStringLiteral("incompleteQmltypes.qml")
- << QString("Warning: Type \"QPalette\" of base \"palette\" not found when accessing member \"weDontKnowIt\" at 5:34")
+ << QString("Warning: Type \"QPalette\" of base \"palette\" not found when accessing member \"weDontKnowIt\" at %1:5:34")
<< QString();
QTest::newRow("inheritanceCylce")
<< QStringLiteral("Cycle1.qml")
@@ -175,6 +175,8 @@ void TestQmllint::dirtyQmlCode()
QFETCH(QString, filename);
QFETCH(QString, warningMessage);
QFETCH(QString, notContained);
+ if (warningMessage.contains(QLatin1String("%1")))
+ warningMessage = warningMessage.arg(testFile(filename));
const QString output = runQmllint(filename, false);
QVERIFY(output.contains(warningMessage));
diff --git a/tools/qmllint/checkidentifiers.cpp b/tools/qmllint/checkidentifiers.cpp
index 20b2ba6214..fb7aee2a6d 100644
--- a/tools/qmllint/checkidentifiers.cpp
+++ b/tools/qmllint/checkidentifiers.cpp
@@ -94,10 +94,11 @@ bool CheckIdentifiers::checkMemberAccess(const QVector<ScopeTree::FieldMember> &
if (scope.isNull()) {
writeWarning(m_colorOut);
m_colorOut->write(
- QString::fromLatin1("Type \"%1\" of base \"%2\" not found when accessing member \"%3\" at %4:%5.\n")
+ QString::fromLatin1("Type \"%1\" of base \"%2\" not found when accessing member \"%3\" at %4:%5:%6.\n")
.arg(detectedRestrictiveKind)
.arg(detectedRestrictiveName)
.arg(access.m_name)
+ .arg(m_fileName)
.arg(access.m_location.startLine)
.arg(access.m_location.startColumn), Normal);
printContext(access.m_location);
@@ -114,10 +115,11 @@ bool CheckIdentifiers::checkMemberAccess(const QVector<ScopeTree::FieldMember> &
writeWarning(m_colorOut);
m_colorOut->write(QString::fromLatin1(
- "\"%1\" is a %2. You cannot access \"%3\" on it at %4:%5\n")
+ "\"%1\" is a %2. You cannot access \"%3\" on it at %4:%5:%6\n")
.arg(detectedRestrictiveName)
.arg(detectedRestrictiveKind)
.arg(access.m_name)
+ .arg(m_fileName)
.arg(access.m_location.startLine)
.arg(access.m_location.startColumn), Normal);
printContext(access.m_location);
@@ -226,9 +228,10 @@ bool CheckIdentifiers::checkMemberAccess(const QVector<ScopeTree::FieldMember> &
writeWarning(m_colorOut);
m_colorOut->write(QString::fromLatin1(
- "Property \"%1\" not found on type \"%2\" at %3:%4\n")
+ "Property \"%1\" not found on type \"%2\" at %3:%4:%5\n")
.arg(access.m_name)
.arg(scopeName)
+ .arg(m_fileName)
.arg(access.m_location.startLine)
.arg(access.m_location.startColumn), Normal);
printContext(access.m_location);
@@ -252,8 +255,8 @@ bool CheckIdentifiers::operator()(const QHash<QString, ScopeTree::ConstPtr> &qml
for (const auto &handler : unmatchedSignalHandlers) {
writeWarning(m_colorOut);
m_colorOut->write(QString::fromLatin1(
- "no matching signal found for handler \"%1\" at %2:%3\n")
- .arg(handler.first).arg(handler.second.startLine)
+ "no matching signal found for handler \"%1\" at %2:%3:%4\n")
+ .arg(handler.first).arg(m_fileName).arg(handler.second.startLine)
.arg(handler.second.startColumn), Normal);
printContext(handler.second);
}
@@ -305,8 +308,9 @@ bool CheckIdentifiers::operator()(const QHash<QString, ScopeTree::ConstPtr> &qml
if (!qmlIt->type()) {
writeWarning(m_colorOut);
m_colorOut->write(QString::fromLatin1(
- "Type of property \"%2\" not found at %3:%4\n")
+ "Type of property \"%2\" not found at %3:%4:%5\n")
.arg(memberAccessBase.m_name)
+ .arg(m_fileName)
.arg(memberAccessBase.m_location.startLine)
.arg(memberAccessBase.m_location.startColumn), Normal);
printContext(memberAccessBase.m_location);
@@ -332,7 +336,8 @@ bool CheckIdentifiers::operator()(const QHash<QString, ScopeTree::ConstPtr> &qml
noUnqualifiedIdentifier = false;
writeWarning(m_colorOut);
const auto location = memberAccessBase.m_location;
- m_colorOut->write(QString::fromLatin1("unqualified access at %1:%2\n")
+ m_colorOut->write(QString::fromLatin1("unqualified access at %1:%2:%3\n")
+ .arg(m_fileName)
.arg(location.startLine).arg(location.startColumn),
Normal);
@@ -379,7 +384,8 @@ bool CheckIdentifiers::operator()(const QHash<QString, ScopeTree::ConstPtr> &qml
m_colorOut->write(
memberAccessBase.m_name + QString::fromLatin1(
" is accessible in this scope because "
- "you are handling a signal at %1:%2\n")
+ "you are handling a signal at %1:%2:%3\n")
+ .arg(m_fileName)
.arg(methodUsage.loc.startLine).arg(methodUsage.loc.startColumn),
Normal);
m_colorOut->write(QLatin1String("Consider using a function instead\n"), Normal);
diff --git a/tools/qmllint/checkidentifiers.h b/tools/qmllint/checkidentifiers.h
index 5d2236b7f9..28f8b24c09 100644
--- a/tools/qmllint/checkidentifiers.h
+++ b/tools/qmllint/checkidentifiers.h
@@ -37,8 +37,8 @@ class CheckIdentifiers
{
public:
CheckIdentifiers(ColorOutput *colorOut, const QString &code, const QHash<QString,
- ScopeTree::ConstPtr> &types) :
- m_colorOut(colorOut), m_code(code), m_types(types)
+ ScopeTree::ConstPtr> &types, const QString &fileName) :
+ m_colorOut(colorOut), m_code(code), m_types(types), m_fileName(fileName)
{}
bool operator ()(const QHash<QString, ScopeTree::ConstPtr> &qmlIDs,
@@ -52,6 +52,7 @@ private:
ColorOutput *m_colorOut = nullptr;
QString m_code;
QHash<QString, ScopeTree::ConstPtr> m_types;
+ QString m_fileName;
};
#endif // CHECKIDENTIFIERS_H
diff --git a/tools/qmllint/findunqualified.cpp b/tools/qmllint/findunqualified.cpp
index 77d7d487fc..abd9c07c31 100644
--- a/tools/qmllint/findunqualified.cpp
+++ b/tools/qmllint/findunqualified.cpp
@@ -725,7 +725,7 @@ bool FindUnqualifiedIDVisitor::check()
outstandingConnection.uiod->initializer->accept(this);
}
- CheckIdentifiers check(&m_colorOut, m_code, m_exportedName2Scope);
+ CheckIdentifiers check(&m_colorOut, m_code, m_exportedName2Scope, m_filePath);
return check(m_qmlid2scope, m_rootScope, m_rootId);
}