You've already forked v8-code-style
mirror of
https://github.com/1C-Company/v8-code-style.git
synced 2025-07-17 21:17:41 +02:00
--------- Co-authored-by: Dmitriy Marmyshev <dmar@1c.ru>
This commit is contained in:
@ -30,6 +30,7 @@
|
|||||||
- Документирующий комментарий не содержит секцию "Описание" для экспортной процедуры (функции)
|
- Документирующий комментарий не содержит секцию "Описание" для экспортной процедуры (функции)
|
||||||
- Проверка корректного наименования переменных
|
- Проверка корректного наименования переменных
|
||||||
- Обращение к несуществующему параметру формы
|
- Обращение к несуществующему параметру формы
|
||||||
|
- Необязательный параметр процедуры/функции стоит перед обязательным
|
||||||
- Обращение к опциональному параметру формы
|
- Обращение к опциональному параметру формы
|
||||||
|
|
||||||
#### Запросы
|
#### Запросы
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
# Method optional parameters before required
|
||||||
|
|
||||||
|
Optional parameters (with default values) must follow required parameters (without default values).
|
||||||
|
|
||||||
|
## Noncompliant Code Example
|
||||||
|
|
||||||
|
```bsl
|
||||||
|
Function ExchangeRateOnDate(Date = Undefined, Currency) Export
|
||||||
|
```
|
||||||
|
|
||||||
|
## Compliant Solution
|
||||||
|
|
||||||
|
```bsl
|
||||||
|
Function ExchangeRateOnDate(Currency, Date = Undefined) Export
|
||||||
|
```
|
||||||
|
|
||||||
|
## See
|
||||||
|
|
||||||
|
- [Procedure and function parameters](https://kb.1ci.com/1C_Enterprise_Platform/Guides/Developer_Guides/1C_Enterprise_Development_Standards/Code_conventions/Module_formatting/Procedure_and_function_parameters/)
|
@ -0,0 +1,20 @@
|
|||||||
|
# Необязательные параметры процедуры/функции расположены перед обязательными
|
||||||
|
|
||||||
|
Необязательные параметры (параметры со значениями по умолчанию)
|
||||||
|
должны располагаться после параметров без значений по умолчанию.
|
||||||
|
|
||||||
|
## Неправильно
|
||||||
|
|
||||||
|
```bsl
|
||||||
|
Функция КурсВалютыНаДату(Дата = Неопределено, Валюта) Экспорт
|
||||||
|
```
|
||||||
|
|
||||||
|
## Правильно
|
||||||
|
|
||||||
|
```bsl
|
||||||
|
Функция КурсВалютыНаДату(Валюта, Дата = Неопределено) Экспорт
|
||||||
|
```
|
||||||
|
|
||||||
|
## См.
|
||||||
|
|
||||||
|
- [Параметры процедур и функций](https://its.1c.ru/db/v8std#content:640:hdoc:4)
|
@ -347,6 +347,10 @@
|
|||||||
category="com.e1c.v8codestyle.bsl"
|
category="com.e1c.v8codestyle.bsl"
|
||||||
class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.check.DeprecatedProcedureOutsideDeprecatedRegionCheck">
|
class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.check.DeprecatedProcedureOutsideDeprecatedRegionCheck">
|
||||||
</check>
|
</check>
|
||||||
|
<check
|
||||||
|
category="com.e1c.v8codestyle.bsl"
|
||||||
|
class="com.e1c.v8codestyle.bsl.check.MethodOptionalParameterBeforeRequiredCheck">
|
||||||
|
</check>
|
||||||
<check
|
<check
|
||||||
category="com.e1c.v8codestyle.bsl"
|
category="com.e1c.v8codestyle.bsl"
|
||||||
class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.check.CodeAfterAsyncCallCheck">
|
class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.check.CodeAfterAsyncCallCheck">
|
||||||
|
@ -366,6 +366,12 @@ final class Messages
|
|||||||
|
|
||||||
public static String UseNonRecommendedMethods_title;
|
public static String UseNonRecommendedMethods_title;
|
||||||
|
|
||||||
|
public static String MethodOptionalParameterBeforeRequiredCheck_description;
|
||||||
|
|
||||||
|
public static String MethodOptionalParameterBeforeRequiredCheck_Optional_parameter_before_required;
|
||||||
|
|
||||||
|
public static String MethodOptionalParameterBeforeRequiredCheck_title;
|
||||||
|
|
||||||
public static String MethodTooManyPramsCheck_description;
|
public static String MethodTooManyPramsCheck_description;
|
||||||
|
|
||||||
public static String MethodTooManyPramsCheck_Max_parameters;
|
public static String MethodTooManyPramsCheck_Max_parameters;
|
||||||
|
@ -0,0 +1,112 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* 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.METHOD;
|
||||||
|
import static com._1c.g5.v8.dt.mcore.McorePackage.Literals.NAMED_ELEMENT__NAME;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.emf.common.util.EList;
|
||||||
|
|
||||||
|
import com._1c.g5.v8.dt.bsl.model.FormalParam;
|
||||||
|
import com._1c.g5.v8.dt.bsl.model.Method;
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check methods formal params, that optional parameter before required.
|
||||||
|
* @author Vadim Goncharov
|
||||||
|
*/
|
||||||
|
public class MethodOptionalParameterBeforeRequiredCheck
|
||||||
|
extends BasicCheck
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final String CHECK_ID = "method-optional-parameter-before-required"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
public MethodOptionalParameterBeforeRequiredCheck()
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCheckId()
|
||||||
|
{
|
||||||
|
return CHECK_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configureCheck(CheckConfigurer builder)
|
||||||
|
{
|
||||||
|
builder.title(Messages.MethodOptionalParameterBeforeRequiredCheck_title)
|
||||||
|
.description(Messages.MethodOptionalParameterBeforeRequiredCheck_description)
|
||||||
|
.complexity(CheckComplexity.NORMAL)
|
||||||
|
.severity(IssueSeverity.TRIVIAL)
|
||||||
|
.issueType(IssueType.CODE_STYLE)
|
||||||
|
.extension(new StandardCheckExtension(640, getCheckId(), BslPlugin.PLUGIN_ID))
|
||||||
|
.module()
|
||||||
|
.checkedObjectType(METHOD);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void check(Object object, ResultAcceptor resultAcceptor, ICheckParameters parameters,
|
||||||
|
IProgressMonitor monitor)
|
||||||
|
{
|
||||||
|
|
||||||
|
Method method = (Method)object;
|
||||||
|
EList<FormalParam> params = method.getFormalParams();
|
||||||
|
if (monitor.isCanceled() || params.isEmpty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int indexOfOptionalParam = -1;
|
||||||
|
int indexOfRequiredParam = -1;
|
||||||
|
|
||||||
|
for (int i = 0; i < params.size(); i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (monitor.isCanceled())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.get(i).getDefaultValue() == null)
|
||||||
|
{
|
||||||
|
indexOfRequiredParam = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.get(i).getDefaultValue() != null && indexOfOptionalParam == -1)
|
||||||
|
{
|
||||||
|
indexOfOptionalParam = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (indexOfOptionalParam != -1 && indexOfRequiredParam != -1 && indexOfOptionalParam < indexOfRequiredParam)
|
||||||
|
{
|
||||||
|
resultAcceptor.addIssue(
|
||||||
|
Messages.MethodOptionalParameterBeforeRequiredCheck_Optional_parameter_before_required,
|
||||||
|
params.get(indexOfOptionalParam), NAMED_ELEMENT__NAME);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -228,6 +228,12 @@ ManagerModuleNamedSelfReferenceCheck_issue = Excessive named self reference
|
|||||||
|
|
||||||
ManagerModuleNamedSelfReferenceCheck_title = Excessive named self reference in manager module
|
ManagerModuleNamedSelfReferenceCheck_title = Excessive named self reference in manager module
|
||||||
|
|
||||||
|
MethodOptionalParameterBeforeRequiredCheck_description=Optional parameter before required
|
||||||
|
|
||||||
|
MethodOptionalParameterBeforeRequiredCheck_Optional_parameter_before_required=Optional parameter before required
|
||||||
|
|
||||||
|
MethodOptionalParameterBeforeRequiredCheck_title=Optional parameter before required
|
||||||
|
|
||||||
MethodTooManyPramsCheck_Max_parameters = Max parameters
|
MethodTooManyPramsCheck_Max_parameters = Max parameters
|
||||||
|
|
||||||
MethodTooManyPramsCheck_Max_parameters_with_default_value = Max parameters with default value
|
MethodTooManyPramsCheck_Max_parameters_with_default_value = Max parameters with default value
|
||||||
|
@ -228,6 +228,12 @@ ManagerModuleNamedSelfReferenceCheck_issue = Избыточное обращен
|
|||||||
|
|
||||||
ManagerModuleNamedSelfReferenceCheck_title = Избыточное обращение по собственному имени в модуле менеджера
|
ManagerModuleNamedSelfReferenceCheck_title = Избыточное обращение по собственному имени в модуле менеджера
|
||||||
|
|
||||||
|
MethodOptionalParameterBeforeRequiredCheck_Optional_parameter_before_required = Обязательный параметр расположен перед обязательным
|
||||||
|
|
||||||
|
MethodOptionalParameterBeforeRequiredCheck_description = Обязательный параметр расположен перед обязательным
|
||||||
|
|
||||||
|
MethodOptionalParameterBeforeRequiredCheck_title = Обязательный параметр расположен перед обязательным
|
||||||
|
|
||||||
MethodTooManyPramsCheck_Max_parameters = Максимум параметров
|
MethodTooManyPramsCheck_Max_parameters = Максимум параметров
|
||||||
|
|
||||||
MethodTooManyPramsCheck_Max_parameters_with_default_value = Максимум параметров со значением по умолчанию
|
MethodTooManyPramsCheck_Max_parameters_with_default_value = Максимум параметров со значением по умолчанию
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
Процедура ПолучитьЗадолженностьКонтрагента(Дата = Неопределено, Контрагент)
|
||||||
|
КонецПроцедуры
|
||||||
|
|
||||||
|
Процедура ПолучитьЗадолженностьКонтрагента2(Контрагент, Дата = Неопределено)
|
||||||
|
КонецПроцедуры
|
||||||
|
|
||||||
|
Процедура ПолучитьЗадолженностьКонтрагента3(Контрагент, Дата)
|
||||||
|
КонецПроцедуры
|
||||||
|
|
||||||
|
Процедура РассчитатьКурсовыеРазницы(Организация, Подразделение = Неопределено, Дата)
|
||||||
|
КонецПроцедуры
|
||||||
|
|
||||||
|
Процедура РассчитатьКурсовыеРазницы2(Организация, Подразделение = Неопределено, Дата = Неопределено)
|
||||||
|
КонецПроцедуры
|
||||||
|
|
||||||
|
Процедура ОтправитьСообщениеПользователю()
|
||||||
|
КонецПроцедуры
|
@ -0,0 +1,56 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* 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.itests;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
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.MethodOptionalParameterBeforeRequiredCheck;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for the class {@link MethodOptionalParameterBeforeRequiredCheck}.
|
||||||
|
* @author Vadim Goncharov
|
||||||
|
*/
|
||||||
|
public class MethodOptionalParameterBeforeRequiredCheckTest
|
||||||
|
extends AbstractSingleModuleTestBase
|
||||||
|
{
|
||||||
|
|
||||||
|
public MethodOptionalParameterBeforeRequiredCheckTest()
|
||||||
|
{
|
||||||
|
super(MethodOptionalParameterBeforeRequiredCheck.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test optional param before require.
|
||||||
|
*
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testOptionalParamBeforeRequire() throws Exception
|
||||||
|
{
|
||||||
|
updateModule(FOLDER_RESOURCE + "method-optional-parameter-before-required.bsl");
|
||||||
|
|
||||||
|
List<Marker> markers = getModuleMarkers();
|
||||||
|
assertEquals(2, markers.size());
|
||||||
|
|
||||||
|
assertEquals("1", markers.get(0).getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY));
|
||||||
|
assertEquals("10", markers.get(1).getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user