diff --git a/src/libs/qmljs/qmljscheck.cpp b/src/libs/qmljs/qmljscheck.cpp index 8e364fa6bec..349e089eba3 100644 --- a/src/libs/qmljs/qmljscheck.cpp +++ b/src/libs/qmljs/qmljscheck.cpp @@ -736,6 +736,7 @@ void Check::enableQmlDesignerUiFileChecks() enableMessage(ErrBehavioursNotSupportedInQmlUi); enableMessage(ErrStatesOnlyInRootItemInQmlUi); enableMessage(ErrReferenceToParentItemNotSupportedInQmlUi); + enableMessage(ErrDoNotMixTranslationFunctionsInQmlUi); } void Check::disableQmlDesignerUiFileChecks() @@ -747,6 +748,7 @@ void Check::disableQmlDesignerUiFileChecks() disableMessage(ErrBehavioursNotSupportedInQmlUi); disableMessage(ErrStatesOnlyInRootItemInQmlUi); disableMessage(ErrReferenceToParentItemNotSupportedInQmlUi); + disableMessage(ErrDoNotMixTranslationFunctionsInQmlUi); } bool Check::preVisit(Node *ast) @@ -1757,6 +1759,22 @@ bool Check::visit(CallExpression *ast) if (!whiteListedFunction && !isMathFunction && !isDateFunction && !isDirectInConnectionsScope) addMessage(ErrFunctionsNotSupportedInQmlUi, location); + if (translationFunctions.contains(name)) { + TranslationFunction translationFunction = noTranslationfunction; + if (name == "qsTr" || name == "qsTrNoOp") + translationFunction = qsTr; + else if (name == "qsTrId" || name == "qsTrIdNoOp") + translationFunction = qsTrId; + else if (name == "qsTranslate" || name == "qsTranslateNoOp") + translationFunction = qsTranslate; + + if (lastTransLationfunction != noTranslationfunction + && lastTransLationfunction != translationFunction) + addMessage(ErrDoNotMixTranslationFunctionsInQmlUi, location); + + lastTransLationfunction = translationFunction; + } + static const QStringList globalFunctions = {"String", "Boolean", "Date", "Number", "Object", "Array", "Symbol", "Object", "Function", "RegExp", "QT_TR_NOOP", "QT_TRANSLATE_NOOP", "QT_TRID_NOOP"}; diff --git a/src/libs/qmljs/qmljscheck.h b/src/libs/qmljs/qmljscheck.h index ec208622485..362c0cc0ac6 100644 --- a/src/libs/qmljs/qmljscheck.h +++ b/src/libs/qmljs/qmljscheck.h @@ -152,11 +152,14 @@ private: bool wasSuppressed; }; + enum TranslationFunction { qsTr, qsTrId, qsTranslate, noTranslationfunction }; + QHash< int, QList > m_disabledMessageTypesByLine; bool _importsOk; bool _inStatementBinding; const Imports *_imports; + TranslationFunction lastTransLationfunction = noTranslationfunction; }; } // namespace QmlJS diff --git a/src/libs/qmljs/qmljsstaticanalysismessage.cpp b/src/libs/qmljs/qmljsstaticanalysismessage.cpp index 86ac7e8b562..24bb70c1869 100644 --- a/src/libs/qmljs/qmljsstaticanalysismessage.cpp +++ b/src/libs/qmljs/qmljsstaticanalysismessage.cpp @@ -239,6 +239,8 @@ StaticAnalysisMessages::StaticAnalysisMessages() tr("States are only supported in the root item in a Qt Quick UI form.")); newMsg(ErrReferenceToParentItemNotSupportedInQmlUi, Error, tr("Referencing the parent of the root item is not supported in a Qt Quick UI form.")); + newMsg(ErrDoNotMixTranslationFunctionsInQmlUi, Error, + tr("Do not mix translation functions in a Qt Quick UI form.")); newMsg(StateCannotHaveChildItem, Error, tr("A State cannot have a child item (%1)."), 1); newMsg(WarnDuplicateImport, Warning, diff --git a/src/libs/qmljs/qmljsstaticanalysismessage.h b/src/libs/qmljs/qmljsstaticanalysismessage.h index d7e2d32eb13..e651533fd79 100644 --- a/src/libs/qmljs/qmljsstaticanalysismessage.h +++ b/src/libs/qmljs/qmljsstaticanalysismessage.h @@ -39,8 +39,7 @@ class DiagnosticMessage; namespace StaticAnalysis { -enum Type -{ +enum Type { // Changing the numbers can break user code. // When adding a new check, also add it to the documentation, currently // in creator-code-syntax.qdoc. @@ -106,6 +105,7 @@ enum Type ErrBehavioursNotSupportedInQmlUi = 224, ErrStatesOnlyInRootItemInQmlUi = 225, ErrReferenceToParentItemNotSupportedInQmlUi = 226, + ErrDoNotMixTranslationFunctionsInQmlUi = 227, ErrUnknownComponent = 300, ErrCouldNotResolvePrototypeOf = 301, ErrCouldNotResolvePrototype = 302,