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

#390 Использование директив компиляции модуля формы (#450)

This commit is contained in:
Dmitriy Marmyshev 2021-11-19 21:24:20 +03:00 committed by GitHub
parent 3e91cd707e
commit f7009113bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 220 additions and 1 deletions

View File

@ -59,6 +59,7 @@
- Сообщить
- Область пустая
- Стандартная область структуры модуля верхнеуровневая
- Использование директив компиляции модуля формы
#### Запросы

View File

@ -0,0 +1,26 @@
# Use form module compilation pragma
Compilation directives (pragma)
```bsl
&AtClient
&AtServer
&AtServerNoContext
```
should be applied only in the code of managed form modules and in the code of command modules.
In other modules, it is recommended to use instructions to the preprocessor.
In server or client common modules, the execution context is obvious, so there is no sense in compilation directives.
In Client-Server common modules the use of compilation directives makes it difficult to understand which procedures (functions) are available in the end.
## Noncompliant Code Example
## Compliant Solution
## See
- [Using compilation directives](https://1c-dn.com/library/using_compilation_directives/)
- [Knowledge base - Compilation directives](https://1c-dn.com/library/tutorials/practical_developer_guide_compilation_directives/)

View File

@ -0,0 +1,23 @@
# Использование директив компиляции модуля формы
Директивы компиляции
```bsl
&НаКлиенте
&НаСервере
&НаСервереБезКонтекста
```
следует применять только в коде модулей управляемых форм и в коде модулей команд.
В остальных модулях рекомендуется применять инструкции препроцессору.
В серверных или клиентских общих модулях контекст исполнения очевиден, поэтому смысла в директивах компиляции нет.
В общих модулях с признаками клиент и сервер применение директив компиляции затрудняет понимание, какие же процедуры (функции) доступны в конечном итоге.
## Неправильно
## Правильно
## См.
- [Использование директив компиляции и инструкций препроцессора](https://its.1c.ru/db/v8std#content:439:hdoc:1)

View File

@ -50,6 +50,10 @@
category="com.e1c.v8codestyle.bsl"
class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.check.NstrStringLiteralFormatCheck">
</check>
<check
category="com.e1c.v8codestyle.bsl"
class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.check.FormModulePragmaCheck">
</check>
<check
category="com.e1c.v8codestyle.bsl"
class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.check.CanonicalPragmaCheck">

View File

@ -0,0 +1,81 @@
/*******************************************************************************
* Copyright (C) 2021, 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.common.Symbols.COMMAND_MODULE_SYMBOLS;
import static com._1c.g5.v8.dt.bsl.common.Symbols.FORM_MODULE_SYMBOLS;
import static com._1c.g5.v8.dt.bsl.model.BslPackage.Literals.PRAGMA;
import static com._1c.g5.v8.dt.bsl.model.BslPackage.Literals.PRAGMA__VALUE;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.xtext.EcoreUtil2;
import com._1c.g5.v8.dt.bsl.model.Module;
import com._1c.g5.v8.dt.bsl.model.ModuleType;
import com._1c.g5.v8.dt.bsl.model.Pragma;
import com._1c.g5.v8.dt.lcore.util.CaseInsensitiveString;
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;
/**
* Check that pragmas is not used in other modules than form or command module.
*
* @author Dmitriy Marmyshev
* @author Victor Golubev
*/
public class FormModulePragmaCheck
extends BasicCheck
{
private static final String CHECK_ID = "form-module-pragma"; //$NON-NLS-1$
@Override
public String getCheckId()
{
return CHECK_ID;
}
@Override
protected void configureCheck(CheckConfigurer builder)
{
builder.title(Messages.FormModulePragmaCheck_title)
.description(Messages.FormModulePragmaCheck_description)
.complexity(CheckComplexity.NORMAL)
.severity(IssueSeverity.MAJOR)
.issueType(IssueType.ERROR)
.module()
.checkedObjectType(PRAGMA);
}
@Override
protected void check(Object object, ResultAcceptor resultAceptor, ICheckParameters parameters,
IProgressMonitor monitor)
{
Pragma pragma = (Pragma)object;
CaseInsensitiveString symbol = new CaseInsensitiveString(pragma.getSymbol());
if (FORM_MODULE_SYMBOLS.contains(symbol) || COMMAND_MODULE_SYMBOLS.contains(symbol))
{
Module module = EcoreUtil2.getContainerOfType(pragma, Module.class);
ModuleType type = module.getModuleType();
if (type != ModuleType.FORM_MODULE && type != ModuleType.COMMAND_MODULE)
{
resultAceptor.addIssue(Messages.FormModulePragmaCheck_Form_module_compilation_pragma_used, pragma,
PRAGMA__VALUE);
}
}
}
}

View File

@ -105,6 +105,13 @@ final class Messages
public static String UseNonRecommendedMethods_title;
public static String FormModulePragmaCheck_description;
public static String FormModulePragmaCheck_Form_module_compilation_pragma_used;
public static String FormModulePragmaCheck_title;
static
{
// initialize resource bundle

View File

@ -56,11 +56,17 @@ EventHandlerBooleanParamCheck_description = Use event handler boolean parameter
EventHandlerBooleanParamCheck_title = Use event handler boolean parameter
FormModulePragmaCheck_Form_module_compilation_pragma_used = Form module compilation pragma used
FormModulePragmaCheck_description = Use form module compilation pragma
FormModulePragmaCheck_title = Use form module compilation pragma
ModuleStructureTopRegionCheck_description = Check that module structure region is on top
ModuleStructureTopRegionCheck_error_message = Module structure region is not on top
ModuleStructureTopRegionCheck_title = Module stucture top region
ModuleStructureTopRegionCheck_title = Module structure top region
NstrStringLiteralFormatCheck_Check_empty_interface_for_each_language = Check empty interface for each language

View File

@ -56,6 +56,12 @@ EventHandlerBooleanParamCheck_description = Использование буле
EventHandlerBooleanParamCheck_title = Использование булевного параметра обработчика события
FormModulePragmaCheck_Form_module_compilation_pragma_used = Использована директива компиляции модуля формы
FormModulePragmaCheck_description = Использование директив компиляции модуля формы
FormModulePragmaCheck_title = Использование директив компиляции модуля формы
ModuleStructureTopRegionCheck_description = Проверяет что стандартная область структуры модуля не является вложенной
ModuleStructureTopRegionCheck_error_message = Стандартная область структуры модуля является вложенной

View File

@ -0,0 +1,9 @@
&AtClient
Procedure Noncompliant()
EndProcedure
Procedure Compliant()
EndProcedure

View File

@ -0,0 +1,56 @@
/*******************************************************************************
* Copyright (C) 2021, 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.FormModulePragmaCheck;
/**
* Tests for {@link FormModulePragmaCheck} check.
*
* @author Dmitriy Marmyshev
*/
public class FormModulePragmaCheckTest
extends AbstractSingleModuleTestBase
{
public FormModulePragmaCheckTest()
{
super(FormModulePragmaCheck.class);
}
/**
* Test common module has pragma for first method and second method doesn't have.
*
* @throws Exception the exception
*/
@Test
public void testCommonModuleHasPragma() throws Exception
{
updateModule(FOLDER_RESOURCE + "form-module-pragma.bsl");
List<Marker> markers = getModuleMarkers();
assertEquals(1, markers.size());
Marker marker = markers.get(0);
assertEquals("2", marker.getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY));
}
}