You've already forked v8-code-style
mirror of
https://github.com/1C-Company/v8-code-style.git
synced 2025-07-16 20:54:14 +02:00
Merge pull request #1262 from VAGoncharov/feature/398-use-goto
#398 Использован оператор "Перейти"
This commit is contained in:
@ -36,6 +36,7 @@
|
||||
- Необязательный параметр процедуры/функции стоит перед обязательным
|
||||
- Обращение к опциональному параметру формы
|
||||
- Функция "РольДоступна" ссылается на несуществующие роли
|
||||
- Проверка на использование оператора Перейти (Goto) в коде модулей
|
||||
|
||||
#### Запросы
|
||||
|
||||
|
@ -0,0 +1,31 @@
|
||||
# Используется оператор Перейти
|
||||
|
||||
В коде на встроенном языке не рекомендуется использовать оператор Перейти,
|
||||
так как необдуманное использование данного оператора приводит к получению запутанных,
|
||||
плохо структурированных модулей, по тексту которых затруднительно понять порядок
|
||||
исполнения и взаимозависимость фрагментов. Вместо оператора Перейти рекомендуется использовать
|
||||
другие конструкции встроенного языка.
|
||||
|
||||
## Неправильно
|
||||
|
||||
```bsl
|
||||
Если ПланВидовРасчета = Объект.ПланВидовРасчета Тогда
|
||||
|
||||
Перейти ~ПланВидовРасчета;
|
||||
|
||||
КонецЕсли;
|
||||
```
|
||||
|
||||
## Правильно
|
||||
|
||||
```bsl
|
||||
Если ПланВидовРасчета = Объект.ПланВидовРасчета Тогда
|
||||
|
||||
ОбработатьПланВидовРасчета();
|
||||
|
||||
КонецЕсли;
|
||||
```
|
||||
|
||||
## См.
|
||||
|
||||
- [Ограничение на использование оператора Перейти](https://its.1c.ru/db/v8std#content:547:hdoc:1)
|
@ -0,0 +1,30 @@
|
||||
# Goto operator use
|
||||
|
||||
Avoid using the GoTo operator in 1C:Enterprise language code as its use can result
|
||||
in complicated and ill-structured modules. It is difficult to understand the execution
|
||||
sequence and interrelation of its snippets. Instead of the GoTo operator, use other statements
|
||||
of 1C:Enterprise language.
|
||||
|
||||
## Noncompliant Code Example
|
||||
|
||||
```bsl
|
||||
If ChartOfCalculationTypes = Object.ChartOfCalculationTypes Then
|
||||
|
||||
GoTo ChartOfCalculationTypes;
|
||||
|
||||
EndIf;
|
||||
```
|
||||
|
||||
## Compliant Solution
|
||||
|
||||
```bsl
|
||||
If ChartOfCalculationTypes = Object.ChartOfCalculationTypes Then
|
||||
|
||||
ProcessChartOfCalculationTypes();
|
||||
|
||||
EndIf;
|
||||
```
|
||||
|
||||
## See
|
||||
|
||||
- [Restrictions on using Go operator](https://kb.1ci.com/1C_Enterprise_Platform/Guides/Developer_Guides/1C_Enterprise_Development_Standards/Code_conventions/Using_1C_Enterprise_language_structures/Restrictions_on_using_Go_operator/?language=en)
|
@ -347,6 +347,10 @@
|
||||
category="com.e1c.v8codestyle.bsl"
|
||||
class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.check.DeprecatedProcedureOutsideDeprecatedRegionCheck">
|
||||
</check>
|
||||
<check
|
||||
category="com.e1c.v8codestyle.bsl"
|
||||
class="com.e1c.v8codestyle.bsl.check.UseGotoOperatorCheck">
|
||||
</check>
|
||||
<check
|
||||
category="com.e1c.v8codestyle.bsl"
|
||||
class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.check.IsInRoleMethodRoleExistCheck">
|
||||
|
@ -354,6 +354,14 @@ final class Messages
|
||||
|
||||
public static String RollbackTransactionCheck_Transactions_is_broken_des;
|
||||
|
||||
public static String UseGotoOperatorCheck_description;
|
||||
|
||||
public static String UseGotoOperatorCheck_title;
|
||||
|
||||
public static String UseGotoOperatorCheck_Use_Goto_operator;
|
||||
|
||||
public static String UseGotoOperatorCheck_Use_Label_with_Goto_operator;
|
||||
|
||||
public static String UnknownFormParameterAccessCheck_description;
|
||||
|
||||
public static String UnknownFormParameterAccessCheck_title;
|
||||
|
@ -0,0 +1,79 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2023, 1C-Soft LLC and others.
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* 1C-Soft LLC - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package com.e1c.v8codestyle.bsl.check;
|
||||
|
||||
import static com._1c.g5.v8.dt.bsl.model.BslPackage.Literals.GOTO_STATEMENT;
|
||||
import static com._1c.g5.v8.dt.bsl.model.BslPackage.Literals.LABELED_STATEMENT;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
import com._1c.g5.v8.dt.bsl.model.GotoStatement;
|
||||
import com._1c.g5.v8.dt.bsl.model.LabeledStatement;
|
||||
import com.e1c.g5.v8.dt.check.CheckComplexity;
|
||||
import com.e1c.g5.v8.dt.check.ICheckParameters;
|
||||
import com.e1c.g5.v8.dt.check.components.BasicCheck;
|
||||
import com.e1c.g5.v8.dt.check.settings.IssueSeverity;
|
||||
import com.e1c.g5.v8.dt.check.settings.IssueType;
|
||||
import com.e1c.v8codestyle.check.StandardCheckExtension;
|
||||
import com.e1c.v8codestyle.internal.bsl.BslPlugin;
|
||||
|
||||
/**
|
||||
* The check on use Goto operator
|
||||
* @author Vadim Goncharov
|
||||
*/
|
||||
public class UseGotoOperatorCheck
|
||||
extends BasicCheck
|
||||
{
|
||||
|
||||
private static final String CHECK_ID = "use-goto-operator"; //$NON-NLS-1$
|
||||
|
||||
public UseGotoOperatorCheck()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCheckId()
|
||||
{
|
||||
return CHECK_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureCheck(CheckConfigurer builder)
|
||||
{
|
||||
builder.title(Messages.UseGotoOperatorCheck_title)
|
||||
.description(Messages.UseGotoOperatorCheck_description)
|
||||
.complexity(CheckComplexity.NORMAL)
|
||||
.severity(IssueSeverity.MAJOR)
|
||||
.issueType(IssueType.CODE_STYLE)
|
||||
.extension(new StandardCheckExtension(547, getCheckId(), BslPlugin.PLUGIN_ID))
|
||||
.module()
|
||||
.checkedObjectType(GOTO_STATEMENT, LABELED_STATEMENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void check(Object object, ResultAcceptor resultAcceptor, ICheckParameters parameters,
|
||||
IProgressMonitor monitor)
|
||||
{
|
||||
if (object instanceof GotoStatement)
|
||||
{
|
||||
resultAcceptor.addIssue(Messages.UseGotoOperatorCheck_Use_Goto_operator, object);
|
||||
}
|
||||
else if (object instanceof LabeledStatement)
|
||||
{
|
||||
resultAcceptor.addIssue(Messages.UseGotoOperatorCheck_Use_Label_with_Goto_operator, object);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -478,6 +478,14 @@ StructureCtorTooManyKeysCheck_description = Check structure constructor has too
|
||||
|
||||
StructureCtorTooManyKeysCheck_title = Structure constructor has too many keys
|
||||
|
||||
UseGotoOperatorCheck_Use_Goto_operator = Use Goto operator
|
||||
|
||||
UseGotoOperatorCheck_Use_Label_with_Goto_operator = Use Label with Goto operator
|
||||
|
||||
UseGotoOperatorCheck_description = Use Goto operator
|
||||
|
||||
UseGotoOperatorCheck_title = Use Goto operator
|
||||
|
||||
UnknownFormParameterAccessCheck_Unknown_form_parameter_access = Unknown form parameter "{0}" access
|
||||
|
||||
UnknownFormParameterAccessCheck_description = Unknown form parameter access
|
||||
|
@ -478,6 +478,14 @@ StructureCtorTooManyKeysCheck_description = Проверка конструкт
|
||||
|
||||
StructureCtorTooManyKeysCheck_title = Конструктор структуры содержит слишком много ключей
|
||||
|
||||
UseGotoOperatorCheck_Use_Goto_operator = Использован оператор Перейти
|
||||
|
||||
UseGotoOperatorCheck_Use_Label_with_Goto_operator = Использована Метка вместе с оператором Перейти
|
||||
|
||||
UseGotoOperatorCheck_description = Использован оператор Перейти
|
||||
|
||||
UseGotoOperatorCheck_title = Использован оператор Перейти
|
||||
|
||||
UnknownFormParameterAccessCheck_Unknown_form_parameter_access = Обращение к несуществующему параметру формы "{0}"
|
||||
|
||||
UnknownFormParameterAccessCheck_description = Обращение к несуществующему параметру формы
|
||||
|
@ -0,0 +1,8 @@
|
||||
Процедура ТестоваяПроцедура1()
|
||||
|
||||
Перейти ~КудаПерейти;
|
||||
|
||||
~МеткаПервая:
|
||||
ТестоваяПеременная = 1;
|
||||
|
||||
КонецПроцедуры
|
@ -0,0 +1,56 @@
|
||||
package com.e1c.v8codestyle.bsl.check.itests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com._1c.g5.v8.dt.validation.marker.IExtraInfoKeys;
|
||||
import com._1c.g5.v8.dt.validation.marker.Marker;
|
||||
import com.e1c.v8codestyle.bsl.check.UseGotoOperatorCheck;
|
||||
|
||||
/**
|
||||
* Tests for {@link UseGotoOperatorCheck} check.
|
||||
*
|
||||
* @author Vadim Goncharov
|
||||
*/
|
||||
public class UseGotoOperatorCheckTest
|
||||
extends AbstractSingleModuleTestBase
|
||||
{
|
||||
|
||||
public UseGotoOperatorCheckTest()
|
||||
{
|
||||
super(UseGotoOperatorCheck.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the module use goto operator and labeled statement.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void testUseGotoOperator() throws Exception
|
||||
{
|
||||
|
||||
updateModule(FOLDER_RESOURCE + "use-goto-operator.bsl");
|
||||
|
||||
List<Marker> markers = getModuleMarkers();
|
||||
assertEquals(2, markers.size());
|
||||
|
||||
Set<String> testMarkersList = Set.of("3", "5");
|
||||
Set<String> projectMarkersList = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
for (Marker marker : markers)
|
||||
{
|
||||
projectMarkersList.add(marker.getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY));
|
||||
}
|
||||
|
||||
assertTrue(testMarkersList.equals(projectMarkersList));
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user