1
0
mirror of https://github.com/1C-Company/v8-code-style.git synced 2024-11-28 09:33:06 +02:00

#1142 #1143 Ложное срабатывание проверки: ql-constants-in-binary-operation (#1145)

* Исправлено ложное срабатывание при логическом операторе с параметром, улучшен текст сообщения
This commit is contained in:
Denis Maslennikov 2022-09-16 12:38:28 +07:00 committed by GitHub
parent 2dbb67614c
commit 1084572fc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 5 deletions

View File

@ -100,6 +100,8 @@
- Ложное срабатывание проверки: module-structure-event-regions для обработчиков событий расположенных в общем модуле #1102
- Автосортировка падает при переводе кода #1106
- Ложное срабатывание проверки: new-color при сбрасывании цвета в значение Авто можно использовать Новый Цвет #1123
- Ложное срабатывание проверки: ql-constants-in-binary-operation #1142
- Не понятно в какой бинарной операции ошибка ql-constants-in-binary-operation #1143
## 0.2.0

View File

@ -15,11 +15,17 @@ package com.e1c.v8codestyle.ql.check;
import static com._1c.g5.v8.dt.ql.model.QlPackage.Literals.ABINARY_OPERATORS_EXPRESSION__RIGHT;
import java.text.MessageFormat;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
import com._1c.g5.v8.dt.ql.model.ABinaryOperatorsExpression;
import com._1c.g5.v8.dt.ql.model.ALiteralsExpression;
import com._1c.g5.v8.dt.ql.model.ALogicalBinaryOperatorExpression;
import com._1c.g5.v8.dt.ql.model.ParameterExpression;
import com.e1c.g5.v8.dt.check.CheckComplexity;
import com.e1c.g5.v8.dt.check.ICheckParameters;
import com.e1c.g5.v8.dt.check.settings.IssueSeverity;
@ -62,16 +68,27 @@ public class ConstantsInBinaryOperationCheck
ICheckParameters parameters, IProgressMonitor monitor)
{
ABinaryOperatorsExpression binaryExpression = (ABinaryOperatorsExpression)object;
if (monitor.isCanceled())
{
return;
}
if ((binaryExpression instanceof ALogicalBinaryOperatorExpression)
&& ((binaryExpression.getLeft() instanceof ParameterExpression)
|| (binaryExpression.getRight() instanceof ParameterExpression)))
{
return;
}
if ((binaryExpression.getLeft() instanceof ALiteralsExpression)
&& (binaryExpression.getRight() instanceof ALiteralsExpression))
{
String message =
Messages.ConstantsInBinaryOperationCheck_Using_binary_operations_with_constants_in_queries_is_forbidden;
INode node = NodeModelUtils.findActualNodeFor(object);
int lineNumber = node.getStartLine();
String expressionText = node.getText().trim();
String message = MessageFormat.format(
Messages.ConstantsInBinaryOperationCheck_Using_binary_operations_with_constants_in_queries_is_forbidden,
lineNumber, expressionText);
resultAceptor.addIssue(message, binaryExpression, ABINARY_OPERATORS_EXPRESSION__RIGHT);
}
}

View File

@ -32,7 +32,7 @@ CastToMaxNumber_description = Query cast to max number
CastToMaxNumber_title = Query cast to max number
ConstantsInBinaryOperationCheck_Using_binary_operations_with_constants_in_queries_is_forbidden = Using binary operations with constants in queries is forbidden
ConstantsInBinaryOperationCheck_Using_binary_operations_with_constants_in_queries_is_forbidden = Using binary operations with constants in queries is forbidden (Line {0}: ...{1})
ConstantsInBinaryOperationCheck_description = Using binary operations with constants in queries is forbidden

View File

@ -33,7 +33,7 @@ CastToMaxNumber_description = Выражение к максимальному
CastToMaxNumber_title = Выражение к максимальному числу в запросе
ConstantsInBinaryOperationCheck_Using_binary_operations_with_constants_in_queries_is_forbidden = Не допускается использование бинарных операций с константами в запросах
ConstantsInBinaryOperationCheck_Using_binary_operations_with_constants_in_queries_is_forbidden = Не допускается использование бинарных операций с константами в запросах (Строка {0}: ...{1})
ConstantsInBinaryOperationCheck_description = Не допускается использование бинарных операций с константами в запросах

View File

@ -17,4 +17,19 @@ FROM
Catalogs.Products AS Products
WHERE
FieldName LIKE "123%";
SELECT
Products.Name AS Name,
FieldName AS Code
FROM
Catalogs.Products AS Products
WHERE
&Parameter = True;
SELECT
Products.Name AS Name,
FieldName AS Code
FROM
Catalogs.Products AS Products
WHERE
&Parameter1 = &Parameter2;