QmlJSCheck: Add error for mixing translation functions

Change-Id: I0f5fd2edf2d8bf13938d9e18eadada5c8c1b85f2
Reviewed-by: Tapani Mattila <tapani.mattila@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Thomas Hartmann
2021-05-04 14:24:25 +02:00
parent 18ab828b6b
commit aba3a38a60
4 changed files with 25 additions and 2 deletions

View File

@@ -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"};