mirror of
https://github.com/1C-Company/v8-code-style.git
synced 2025-02-03 09:57:35 +02:00
parent
8875af2f8b
commit
00d16bb2f6
@ -61,6 +61,7 @@
|
||||
- Область пустая
|
||||
- Стандартная область структуры модуля верхнеуровневая
|
||||
- Использование директив компиляции модуля формы
|
||||
- Всегда использовать директивы компиляции в модуле формы
|
||||
|
||||
#### Запросы
|
||||
|
||||
|
@ -0,0 +1,29 @@
|
||||
# Always use compilation pragma in form module
|
||||
|
||||
An absence of a compilation directive before the procedure means using a directive by default.
|
||||
A directive by default is `AtServer` that leads to extra server call and it is not working on web-client.
|
||||
|
||||
## Noncompliant Code Example
|
||||
|
||||
|
||||
```bsl
|
||||
Procedure Server()
|
||||
|
||||
EndProcedure
|
||||
```
|
||||
|
||||
## Compliant Solution
|
||||
|
||||
```bsl
|
||||
&AtServer
|
||||
Procedure Server()
|
||||
|
||||
EndProcedure
|
||||
|
||||
```
|
||||
|
||||
## See
|
||||
|
||||
- [Form module](https://support.1ci.com/hc/en-us/articles/4403180966034-7-6-Form-module)
|
||||
- [Using compilation directives and preprocessor commands](https://support.1ci.com/hc/en-us/articles/360011002560-Using-compilation-directives-and-preprocessor-commands)
|
||||
- [General configuration requirements](https://support.1ci.com/hc/en-us/articles/360011107839-General-configuration-requirements)
|
@ -0,0 +1,36 @@
|
||||
# Всегда использовать директивы компиляции в модуле формы
|
||||
|
||||
1.1. Конфигурация должна использовать только штатные и документированные
|
||||
возможности платформы 1С:Предприятие.
|
||||
|
||||
...
|
||||
|
||||
Платформа позволяет в модулях форм реализовывать процедуры без директив
|
||||
компиляции (&НаСервере и т.п.). Такие процедуры не работают в
|
||||
веб-клиенте и приводят к лишнему серверному вызову.
|
||||
|
||||
## Неправильно
|
||||
|
||||
```bsl
|
||||
Процедура Серверная()
|
||||
|
||||
|
||||
КонецПроцедуры
|
||||
```
|
||||
|
||||
## Правильно
|
||||
|
||||
```bsl
|
||||
&НаСервере
|
||||
Процедура Серверная()
|
||||
|
||||
|
||||
КонецПроцедуры
|
||||
```
|
||||
|
||||
## См.
|
||||
|
||||
- [Исполнение модуля формы на клиенте и на сервере](https://its.1c.ru/db/pubv8devui/content/189/hdoc/)
|
||||
- [Использование директив компиляции и инструкций препроцессора](https://its.1c.ru/db/v8std/content/439/hdoc/)
|
||||
- [Общие требования к конфигурации](https://its.1c.ru/db/v8std#content:467:hdoc)
|
||||
- [Модуль формы](https://its.1c.ru/db/v8320doc#bookmark:dev:TI000000403)
|
@ -34,6 +34,10 @@
|
||||
category="com.e1c.v8codestyle.bsl"
|
||||
class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.check.StructureCtorTooManyKeysCheck">
|
||||
</check>
|
||||
<check
|
||||
category="com.e1c.v8codestyle.bsl"
|
||||
class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.check.FormModuleMissingPragmaCheck">
|
||||
</check>
|
||||
<check
|
||||
category="com.e1c.v8codestyle.bsl"
|
||||
class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.check.QueryInLoopCheck">
|
||||
|
@ -0,0 +1,100 @@
|
||||
/*******************************************************************************
|
||||
* 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.model.BslPackage.Literals.DECLARE_STATEMENT;
|
||||
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.ecore.EObject;
|
||||
import org.eclipse.xtext.EcoreUtil2;
|
||||
|
||||
import com._1c.g5.v8.dt.bsl.model.DeclareStatement;
|
||||
import com._1c.g5.v8.dt.bsl.model.ExplicitVariable;
|
||||
import com._1c.g5.v8.dt.bsl.model.Method;
|
||||
import com._1c.g5.v8.dt.bsl.model.Module;
|
||||
import com._1c.g5.v8.dt.bsl.model.ModuleType;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Checks that form or command module each method or module declared variables has compilation directives (pragmas).
|
||||
*
|
||||
* @author Dmitriy Marmyshev
|
||||
* @author Victor Golubev
|
||||
*/
|
||||
public class FormModuleMissingPragmaCheck
|
||||
extends BasicCheck
|
||||
{
|
||||
private static final String CHECK_ID = "form-module-missing-pragma"; //$NON-NLS-1$
|
||||
|
||||
@Override
|
||||
public String getCheckId()
|
||||
{
|
||||
return CHECK_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureCheck(CheckConfigurer builder)
|
||||
{
|
||||
builder.title(Messages.FormModuleMissingPragmaCheck_title)
|
||||
.description(Messages.FormModuleMissingPragmaCheck_description)
|
||||
.complexity(CheckComplexity.NORMAL)
|
||||
.severity(IssueSeverity.MAJOR)
|
||||
.issueType(IssueType.ERROR)
|
||||
.module()
|
||||
.checkedObjectType(METHOD, DECLARE_STATEMENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void check(Object object, ResultAcceptor resultAceptor, ICheckParameters parameters,
|
||||
IProgressMonitor monitor)
|
||||
{
|
||||
|
||||
Module module = EcoreUtil2.getContainerOfType((EObject)object, Module.class);
|
||||
ModuleType type = module.getModuleType();
|
||||
|
||||
if (type != ModuleType.FORM_MODULE && type != ModuleType.COMMAND_MODULE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (object instanceof Method)
|
||||
{
|
||||
Method method = (Method)object;
|
||||
if (method.getPragmas().isEmpty())
|
||||
{
|
||||
resultAceptor.addIssue(Messages.FormModuleMissingPragmaCheck_Missing_compilation_directives, method,
|
||||
NAMED_ELEMENT__NAME);
|
||||
}
|
||||
}
|
||||
else if (object instanceof DeclareStatement)
|
||||
{
|
||||
DeclareStatement declare = (DeclareStatement)object;
|
||||
Method method = EcoreUtil2.getContainerOfType((EObject)declare, Method.class);
|
||||
if (method == null && declare.getPragmas().isEmpty())
|
||||
{
|
||||
for (ExplicitVariable variable : declare.getVariables())
|
||||
{
|
||||
resultAceptor.addIssue(Messages.FormModuleMissingPragmaCheck_Missing_compilation_directives,
|
||||
variable, NAMED_ELEMENT__NAME);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -124,6 +124,13 @@ final class Messages
|
||||
public static String FormModulePragmaCheck_title;
|
||||
|
||||
|
||||
public static String FormModuleMissingPragmaCheck_description;
|
||||
|
||||
public static String FormModuleMissingPragmaCheck_Missing_compilation_directives;
|
||||
|
||||
public static String FormModuleMissingPragmaCheck_title;
|
||||
|
||||
|
||||
static
|
||||
{
|
||||
// initialize resource bundle
|
||||
|
@ -56,6 +56,12 @@ EventHandlerBooleanParamCheck_description = Use event handler boolean parameter
|
||||
|
||||
EventHandlerBooleanParamCheck_title = Use event handler boolean parameter
|
||||
|
||||
FormModuleMissingPragmaCheck_Missing_compilation_directives = Missing compilation directives
|
||||
|
||||
FormModuleMissingPragmaCheck_description = Always use compilation pragma in form module
|
||||
|
||||
FormModuleMissingPragmaCheck_title = Always use compilation pragma in form module
|
||||
|
||||
FormModulePragmaCheck_Form_module_compilation_pragma_used = Form module compilation pragma used
|
||||
|
||||
FormModulePragmaCheck_description = Use form module compilation pragma
|
||||
|
@ -56,6 +56,12 @@ EventHandlerBooleanParamCheck_description = Использование буле
|
||||
|
||||
EventHandlerBooleanParamCheck_title = Использование булевного параметра обработчика события
|
||||
|
||||
FormModuleMissingPragmaCheck_Missing_compilation_directives = Пропущена директива компиляции
|
||||
|
||||
FormModuleMissingPragmaCheck_description = Всегда использовать директивы компиляции в модуле формы
|
||||
|
||||
FormModuleMissingPragmaCheck_title = Всегда использовать директивы компиляции в модуле формы
|
||||
|
||||
FormModulePragmaCheck_Form_module_compilation_pragma_used = Использована директива компиляции модуля формы
|
||||
|
||||
FormModulePragmaCheck_description = Использование директив компиляции модуля формы
|
||||
@ -97,6 +103,7 @@ NstrStringLiteralFormatCheck_NStr_method_should_accept_string_as_first_param =
|
||||
NstrStringLiteralFormatCheck_description = НСтр формат строкового литерала
|
||||
|
||||
NstrStringLiteralFormatCheck_title = НСтр формат строкового литерала
|
||||
>>>>>>> refs/heads/master
|
||||
|
||||
QueryInLoop_Loop_has_method_with_query__0 = Цикл содержит вызов метода с запросом "{0}"
|
||||
|
||||
|
@ -0,0 +1,14 @@
|
||||
|
||||
Var NoncompliantVariable;
|
||||
|
||||
&AtClient
|
||||
Var CompliantVariable;
|
||||
|
||||
Procedure Noncompliant()
|
||||
|
||||
EndProcedure
|
||||
|
||||
&AtClient
|
||||
Procedure Compliant()
|
||||
|
||||
EndProcedure
|
@ -149,7 +149,7 @@ public class AbstractSingleModuleTestBase
|
||||
*/
|
||||
protected Module getModule()
|
||||
{
|
||||
IBmObject mdObject = getTopObjectByFqn(FQN, dtProject);
|
||||
IBmObject mdObject = getTopObjectByFqn(FQN, getProject());
|
||||
assertTrue(mdObject instanceof CommonModule);
|
||||
Module module = ((CommonModule)mdObject).getModule();
|
||||
assertNotNull(module);
|
||||
|
@ -0,0 +1,88 @@
|
||||
/*******************************************************************************
|
||||
* 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 static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com._1c.g5.v8.bm.core.IBmObject;
|
||||
import com._1c.g5.v8.dt.bsl.model.Module;
|
||||
import com._1c.g5.v8.dt.metadata.mdclass.AbstractForm;
|
||||
import com._1c.g5.v8.dt.validation.marker.IExtraInfoKeys;
|
||||
import com._1c.g5.v8.dt.validation.marker.Marker;
|
||||
import com.e1c.v8codestyle.bsl.check.FormModuleMissingPragmaCheck;
|
||||
|
||||
/**
|
||||
* The test of {@link FormModuleMissingPragmaCheck} check.
|
||||
*
|
||||
* @author Dmitriy Marmyshev
|
||||
*/
|
||||
public class FormModuleMissingPragmaCheckTest
|
||||
extends AbstractSingleModuleTestBase
|
||||
{
|
||||
|
||||
private static final String PROJECT_NAME = "CommonForm";
|
||||
|
||||
private static final String FQN = "CommonForm.Form.Form";
|
||||
|
||||
private static final String COMMON_FORM_FILE_NAME = "/src/CommonForms/Form/Module.bsl";
|
||||
|
||||
public FormModuleMissingPragmaCheckTest()
|
||||
{
|
||||
super(FormModuleMissingPragmaCheck.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestConfigurationName()
|
||||
{
|
||||
return PROJECT_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getModuleFileName()
|
||||
{
|
||||
return COMMON_FORM_FILE_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Module getModule()
|
||||
{
|
||||
IBmObject mdObject = getTopObjectByFqn(FQN, getProject());
|
||||
assertTrue(mdObject instanceof AbstractForm);
|
||||
Module module = ((AbstractForm)mdObject).getModule();
|
||||
assertNotNull(module);
|
||||
|
||||
return module;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormModuleHasPragma() throws Exception
|
||||
{
|
||||
updateModule(FOLDER_RESOURCE + "form-module-missing-pragma.bsl");
|
||||
|
||||
List<Marker> markers = getModuleMarkers();
|
||||
assertEquals(2, markers.size());
|
||||
|
||||
Marker marker = markers.get(0);
|
||||
assertEquals("7", marker.getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY));
|
||||
|
||||
marker = markers.get(1);
|
||||
assertEquals("2", marker.getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>CommonForm</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
|
||||
<nature>com._1c.g5.v8.dt.core.V8ConfigurationNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
@ -0,0 +1,2 @@
|
||||
Manifest-Version: 1.0
|
||||
Runtime-Version: 8.3.19
|
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form:Form xmlns:form="http://g5.1c.ru/v8/dt/form">
|
||||
<autoCommandBar>
|
||||
<name>FormCommandBar</name>
|
||||
<id>-1</id>
|
||||
<visible>true</visible>
|
||||
<enabled>true</enabled>
|
||||
<userVisible>
|
||||
<common>true</common>
|
||||
</userVisible>
|
||||
<horizontalAlign>Left</horizontalAlign>
|
||||
<autoFill>true</autoFill>
|
||||
</autoCommandBar>
|
||||
<autoTitle>true</autoTitle>
|
||||
<autoUrl>true</autoUrl>
|
||||
<group>Vertical</group>
|
||||
<autoFillCheck>true</autoFillCheck>
|
||||
<allowFormCustomize>true</allowFormCustomize>
|
||||
<enabled>true</enabled>
|
||||
<showTitle>true</showTitle>
|
||||
<showCloseButton>true</showCloseButton>
|
||||
<commandInterface>
|
||||
<navigationPanel/>
|
||||
<commandBar/>
|
||||
</commandInterface>
|
||||
</form:Form>
|
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<mdclass:CommonForm xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="216db722-ab53-4560-98b4-794b823f44a4">
|
||||
<name>Form</name>
|
||||
<synonym>
|
||||
<key>en</key>
|
||||
<value>Form</value>
|
||||
</synonym>
|
||||
<usePurposes>PersonalComputer</usePurposes>
|
||||
<usePurposes>MobileDevice</usePurposes>
|
||||
</mdclass:CommonForm>
|
@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<cmi:CommandInterface xmlns:cmi="http://g5.1c.ru/v8/dt/cmi"/>
|
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<mdclass:Configuration xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="42105ae2-7502-42e4-ad0a-3ecb0e5070e4">
|
||||
<name>CommonForm</name>
|
||||
<synonym>
|
||||
<key>en</key>
|
||||
<value>Common form</value>
|
||||
</synonym>
|
||||
<containedObjects classId="9cd510cd-abfc-11d4-9434-004095e12fc7" objectId="b33479dd-1abe-4f82-ab68-da187ff11473"/>
|
||||
<containedObjects classId="9fcd25a0-4822-11d4-9414-008048da11f9" objectId="964dc535-2da1-4c97-81b9-a62c4d466456"/>
|
||||
<containedObjects classId="e3687481-0a87-462c-a166-9f34594f9bba" objectId="f192f49f-f225-41f8-a572-522d046fbb76"/>
|
||||
<containedObjects classId="9de14907-ec23-4a07-96f0-85521cb6b53b" objectId="8138a14c-cf94-4876-bff4-3e06f2a6e1fa"/>
|
||||
<containedObjects classId="51f2d5d8-ea4d-4064-8892-82951750031e" objectId="4e239ae3-2769-4faa-906b-c1b57de06094"/>
|
||||
<containedObjects classId="e68182ea-4237-4383-967f-90c1e3370bc7" objectId="a0c01674-9ecf-4894-905e-53243fcb2007"/>
|
||||
<containedObjects classId="fb282519-d103-4dd3-bc12-cb271d631dfc" objectId="4f4ef3bf-cf9b-4cdb-9675-0cec6efb742c"/>
|
||||
<configurationExtensionCompatibilityMode>8.3.19</configurationExtensionCompatibilityMode>
|
||||
<defaultRunMode>ManagedApplication</defaultRunMode>
|
||||
<usePurposes>PersonalComputer</usePurposes>
|
||||
<usedMobileApplicationFunctionalities>
|
||||
<functionality>
|
||||
<use>true</use>
|
||||
</functionality>
|
||||
<functionality>
|
||||
<functionality>OSBackup</functionality>
|
||||
<use>true</use>
|
||||
</functionality>
|
||||
</usedMobileApplicationFunctionalities>
|
||||
<defaultLanguage>Language.English</defaultLanguage>
|
||||
<dataLockControlMode>Managed</dataLockControlMode>
|
||||
<objectAutonumerationMode>NotAutoFree</objectAutonumerationMode>
|
||||
<modalityUseMode>DontUse</modalityUseMode>
|
||||
<synchronousPlatformExtensionAndAddInCallUseMode>DontUse</synchronousPlatformExtensionAndAddInCallUseMode>
|
||||
<compatibilityMode>8.3.19</compatibilityMode>
|
||||
<languages uuid="bb947fd6-685a-4ff4-9eb4-4acb98304e65">
|
||||
<name>English</name>
|
||||
<synonym>
|
||||
<key>en</key>
|
||||
<value>English</value>
|
||||
</synonym>
|
||||
<languageCode>en</languageCode>
|
||||
</languages>
|
||||
<commonForms>CommonForm.Form</commonForms>
|
||||
</mdclass:Configuration>
|
@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<cmi:CommandInterface xmlns:cmi="http://g5.1c.ru/v8/dt/cmi"/>
|
Loading…
x
Reference in New Issue
Block a user