mirror of
https://github.com/1C-Company/v8-code-style.git
synced 2024-12-01 10:41:05 +02:00
Merge remote-tracking branch 'origin/master' into edt-2022-3
This commit is contained in:
commit
57e193fb49
@ -20,6 +20,7 @@
|
||||
#### Код модулей
|
||||
|
||||
- Добавление типизированного значения в не типизированную коллекцию
|
||||
- Кэширование программного интерфейса
|
||||
- Проверка максимального количества допустимых пустых строк
|
||||
- Чтение отдельных реквизитов объекта из базы данных
|
||||
- Использование экспортных переменных в модулях объекта
|
||||
|
@ -0,0 +1,31 @@
|
||||
# Checks cached public
|
||||
|
||||
You should not create an API in modules that reuse return values.
|
||||
|
||||
## Noncompliant Code Example
|
||||
|
||||
```bsl
|
||||
|
||||
#Region Public
|
||||
|
||||
Procedure GetData() Export
|
||||
EndProcedure
|
||||
|
||||
#EndRegion
|
||||
|
||||
```
|
||||
|
||||
## Compliant Solution
|
||||
|
||||
```bsl
|
||||
|
||||
#Region Internal
|
||||
|
||||
Procedure GetData() Export
|
||||
EndProcedure
|
||||
|
||||
#EndRegion
|
||||
|
||||
```
|
||||
|
||||
## See
|
@ -0,0 +1,34 @@
|
||||
# Проверка кэширования программного интерфейса
|
||||
|
||||
Не следует создавать программный интерфейс в модулях с повторным использованием возвращаемых значений.
|
||||
|
||||
## Неправильно
|
||||
|
||||
```bsl
|
||||
|
||||
#Область ПрограммныйИнтерфейс
|
||||
|
||||
Процедура ПолучитьДанные() Экспорт
|
||||
КонецПроцедуры
|
||||
|
||||
#КонецОбласти
|
||||
|
||||
```
|
||||
|
||||
## Правильно
|
||||
|
||||
```bsl
|
||||
|
||||
#Область СлужебныйПрограммныйИнтерфейс
|
||||
|
||||
Процедура ПолучитьДанные() Экспорт
|
||||
КонецПроцедуры
|
||||
|
||||
#КонецОбласти
|
||||
|
||||
```
|
||||
|
||||
## См.
|
||||
|
||||
|
||||
- [Обеспечение совместимости библиотек](https://its.1c.ru/db/v8std/content/644/hdoc)
|
@ -311,6 +311,10 @@
|
||||
category="com.e1c.v8codestyle.bsl"
|
||||
class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.check.ModuleStructureVariablesInRegionCheck">
|
||||
</check>
|
||||
<check
|
||||
category="com.e1c.v8codestyle.bsl"
|
||||
class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.check.PublicMethodCachingCheck">
|
||||
</check>
|
||||
<check
|
||||
category="com.e1c.v8codestyle.bsl"
|
||||
class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.check.ConsecutiveEmptyLinesCheck">
|
||||
|
@ -38,6 +38,13 @@ final class Messages
|
||||
public static String AccessibilityAtClientInObjectModuleCheck_Methods_should_be_AtClient;
|
||||
|
||||
public static String AccessibilityAtClientInObjectModuleCheck_title;
|
||||
|
||||
public static String CachedPublicCheck_Description;
|
||||
|
||||
public static String CachedPublicCheck_Issue;
|
||||
|
||||
public static String CachedPublicCheck_Title;
|
||||
|
||||
public static String AttachableEventHandlerNameCheck_Description;
|
||||
|
||||
public static String AttachableEventHandlerNameCheck_Event_handler_name_pattern;
|
||||
|
@ -0,0 +1,116 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2022, 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.REGION_PREPROCESSOR;
|
||||
import static com._1c.g5.v8.dt.mcore.McorePackage.Literals.NAMED_ELEMENT__NAME;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
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.RegionPreprocessor;
|
||||
import com._1c.g5.v8.dt.core.platform.IV8Project;
|
||||
import com._1c.g5.v8.dt.core.platform.IV8ProjectManager;
|
||||
import com._1c.g5.v8.dt.metadata.mdclass.CommonModule;
|
||||
import com._1c.g5.v8.dt.metadata.mdclass.ReturnValuesReuse;
|
||||
import com._1c.g5.v8.dt.metadata.mdclass.ScriptVariant;
|
||||
import com.e1c.g5.v8.dt.check.CheckComplexity;
|
||||
import com.e1c.g5.v8.dt.check.ICheckParameters;
|
||||
import com.e1c.g5.v8.dt.check.components.ModuleTopObjectNameFilterExtension;
|
||||
import com.e1c.g5.v8.dt.check.settings.IssueSeverity;
|
||||
import com.e1c.g5.v8.dt.check.settings.IssueType;
|
||||
import com.e1c.v8codestyle.bsl.ModuleStructureSection;
|
||||
import com.e1c.v8codestyle.check.StandardCheckExtension;
|
||||
import com.e1c.v8codestyle.internal.bsl.BslPlugin;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* Checks cached public method
|
||||
*
|
||||
* @author Artem Iliukhin
|
||||
*/
|
||||
public class PublicMethodCachingCheck
|
||||
extends AbstractModuleStructureCheck
|
||||
{
|
||||
|
||||
private static final String CHECK_ID = "public-method-caching"; //$NON-NLS-1$
|
||||
private final IV8ProjectManager v8ProjectManager;
|
||||
|
||||
/**
|
||||
* Creates new instance which helps to check cached public method
|
||||
*
|
||||
* @param v8ProjectManager
|
||||
*/
|
||||
@Inject
|
||||
public PublicMethodCachingCheck(IV8ProjectManager v8ProjectManager)
|
||||
{
|
||||
super();
|
||||
this.v8ProjectManager = v8ProjectManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCheckId()
|
||||
{
|
||||
return CHECK_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureCheck(CheckConfigurer builder)
|
||||
{
|
||||
builder.title(Messages.CachedPublicCheck_Title)
|
||||
.description(Messages.CachedPublicCheck_Description)
|
||||
.complexity(CheckComplexity.NORMAL)
|
||||
.severity(IssueSeverity.MINOR)
|
||||
.issueType(IssueType.CODE_STYLE)
|
||||
.extension(new ModuleTopObjectNameFilterExtension())
|
||||
.extension(new StandardCheckExtension(644, getCheckId(), BslPlugin.PLUGIN_ID))
|
||||
.extension(ModuleTypeFilter.onlyTypes(ModuleType.COMMON_MODULE))
|
||||
.module()
|
||||
.checkedObjectType(REGION_PREPROCESSOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void check(Object object, ResultAcceptor result, ICheckParameters parameters, IProgressMonitor monitor)
|
||||
{
|
||||
RegionPreprocessor region = (RegionPreprocessor)object;
|
||||
|
||||
Optional<RegionPreprocessor> topRegion = getTopParentRegion(region);
|
||||
if (!topRegion.isEmpty())
|
||||
{
|
||||
region = topRegion.get();
|
||||
}
|
||||
IV8Project project = v8ProjectManager.getProject(region);
|
||||
ScriptVariant scriptVariant = project.getScriptVariant();
|
||||
if (!ModuleStructureSection.PUBLIC.getName(scriptVariant).equals(region.getName()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Module module = EcoreUtil2.getContainerOfType(region, Module.class);
|
||||
if (module == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CommonModule commonModule = (CommonModule)module.getOwner();
|
||||
if (commonModule.getReturnValuesReuse() == ReturnValuesReuse.DONT_USE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
result.addIssue(Messages.CachedPublicCheck_Issue, region, NAMED_ELEMENT__NAME);
|
||||
}
|
||||
}
|
@ -28,6 +28,12 @@ AccessibilityAtClientInObjectModuleCheck_description = Method or variable access
|
||||
|
||||
AccessibilityAtClientInObjectModuleCheck_title = Method or variable accessible AtClient
|
||||
|
||||
CachedPublicCheck_Description=Cached public method
|
||||
|
||||
CachedPublicCheck_Issue=Not recommended to use cached public method
|
||||
|
||||
CachedPublicCheck_Title=Cached public method
|
||||
|
||||
AttachableEventHandlerNameCheck_Description = Programmatically added event handler name should match pattern
|
||||
|
||||
AttachableEventHandlerNameCheck_Event_handler_name_pattern = Event handler name pattern
|
||||
|
@ -36,6 +36,12 @@ AttachableEventHandlerNameCheck_Message = Программно добавлен
|
||||
|
||||
AttachableEventHandlerNameCheck_Title = Имя подключаемого обработчика события
|
||||
|
||||
CachedPublicCheck_Description=Кэширование интерфейсного метода
|
||||
|
||||
CachedPublicCheck_Issue=Не рекомендуется кэшировать программный интерфейс
|
||||
|
||||
CachedPublicCheck_Title=Кэширование интерфейсного метода
|
||||
|
||||
CanonicalPragmaCheck_Pragma_0_is_not_written_canonically_correct_spelling_is_1 = Аннотация {0} написана не канонически, правильное написание {1}
|
||||
|
||||
CanonicalPragmaCheck_description = Проверяет что аннотация метода написана канонически
|
||||
|
@ -0,0 +1,82 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2022, 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.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.core.runtime.Path;
|
||||
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.g5.v8.dt.testing.check.SingleProjectReadOnlyCheckTestBase;
|
||||
import com.e1c.v8codestyle.bsl.check.PublicMethodCachingCheck;
|
||||
|
||||
/**
|
||||
* Tests for {@link PublicMethodCachingCheck} check
|
||||
*
|
||||
* @author Artem Iliukhin
|
||||
*/
|
||||
public class PublicMethodCachingCheckTest
|
||||
extends SingleProjectReadOnlyCheckTestBase
|
||||
{
|
||||
|
||||
private static final String PROJECT_NAME = "CachedPublicCheck";
|
||||
private static final String CACHED_FILE_NAME = "/src/CommonModules/CommonModuleCached/Module.bsl";
|
||||
private static final String COMPLIANT_CACHED_FILE_NAME =
|
||||
"/src/CommonModules/CommonModuleCachedCompliant/Module.bsl";
|
||||
private static final String NON_CACHED_FILE_NAME = "/src/CommonModules/CommonModule/Module.bsl";
|
||||
private static final String CHECK_ID = "public-method-caching";
|
||||
|
||||
@Override
|
||||
protected String getTestConfigurationName()
|
||||
{
|
||||
return PROJECT_NAME;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCachedMethod() throws Exception
|
||||
{
|
||||
List<Marker> markers = getMarkers(CACHED_FILE_NAME);
|
||||
assertEquals(1, markers.size());
|
||||
assertEquals("2", markers.get(0).getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCachedMethodCompliant() throws Exception
|
||||
{
|
||||
List<Marker> markers = getMarkers(COMPLIANT_CACHED_FILE_NAME);
|
||||
assertTrue(markers.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonCachedMethod() throws Exception
|
||||
{
|
||||
List<Marker> markers = getMarkers(NON_CACHED_FILE_NAME);
|
||||
assertTrue(markers.isEmpty());
|
||||
}
|
||||
|
||||
private List<Marker> getMarkers(String moduleFileName)
|
||||
{
|
||||
String moduleId = Path.ROOT.append(getTestConfigurationName()).append(moduleFileName).toString();
|
||||
List<Marker> markers = List.of(markerManager.getMarkers(getProject().getWorkspaceProject(), moduleId));
|
||||
|
||||
return markers.stream()
|
||||
.filter(marker -> CHECK_ID.equals(getCheckIdFromMarker(marker, getProject())))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>CachedPublicCheck</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,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="979c2dfc-c323-4b9b-a18a-68602ed98011">
|
||||
<name>CommonModule</name>
|
||||
<synonym>
|
||||
<key>en</key>
|
||||
<value>Common module</value>
|
||||
</synonym>
|
||||
<server>true</server>
|
||||
<externalConnection>true</externalConnection>
|
||||
<clientOrdinaryApplication>true</clientOrdinaryApplication>
|
||||
</mdclass:CommonModule>
|
@ -0,0 +1,8 @@
|
||||
|
||||
#Region Public
|
||||
|
||||
Procedure GetData() Export
|
||||
|
||||
EndProcedure
|
||||
|
||||
#EndRegion
|
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="b01baf06-293f-4ddc-8c09-7f2ab68daf16">
|
||||
<name>CommonModuleCached</name>
|
||||
<synonym>
|
||||
<key>en</key>
|
||||
<value>Common module cached</value>
|
||||
</synonym>
|
||||
<server>true</server>
|
||||
<externalConnection>true</externalConnection>
|
||||
<clientOrdinaryApplication>true</clientOrdinaryApplication>
|
||||
<returnValuesReuse>DuringSession</returnValuesReuse>
|
||||
</mdclass:CommonModule>
|
@ -0,0 +1,8 @@
|
||||
|
||||
#Region Public
|
||||
|
||||
Procedure GetData() Export
|
||||
|
||||
EndProcedure
|
||||
|
||||
#EndRegion
|
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="7cf0918e-70fa-4bff-841b-4a0e72bb4087">
|
||||
<name>CommonModuleCachedCompliant</name>
|
||||
<synonym>
|
||||
<key>en</key>
|
||||
<value>Common module cached compliant</value>
|
||||
</synonym>
|
||||
<server>true</server>
|
||||
<externalConnection>true</externalConnection>
|
||||
<clientOrdinaryApplication>true</clientOrdinaryApplication>
|
||||
<returnValuesReuse>DuringSession</returnValuesReuse>
|
||||
</mdclass:CommonModule>
|
@ -0,0 +1,8 @@
|
||||
|
||||
#Region Internal
|
||||
|
||||
Procedure GetData() Export
|
||||
|
||||
EndProcedure
|
||||
|
||||
#EndRegion
|
@ -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,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<mdclass:Configuration xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="5145acbf-1c5b-4523-aac4-212a347aa34a">
|
||||
<name>CachedPublicCheck</name>
|
||||
<synonym>
|
||||
<key>en</key>
|
||||
<value>Cached public check</value>
|
||||
</synonym>
|
||||
<containedObjects classId="9cd510cd-abfc-11d4-9434-004095e12fc7" objectId="0dc2167e-c8c2-4733-b465-13b7442f7d91"/>
|
||||
<containedObjects classId="9fcd25a0-4822-11d4-9414-008048da11f9" objectId="06ec9823-c2ab-4968-a8b2-4abdfdb59761"/>
|
||||
<containedObjects classId="e3687481-0a87-462c-a166-9f34594f9bba" objectId="23d88fa1-c6ac-4887-accd-f04bb889e29a"/>
|
||||
<containedObjects classId="9de14907-ec23-4a07-96f0-85521cb6b53b" objectId="e2ad7245-7b18-4561-8a4a-2612226ed9f9"/>
|
||||
<containedObjects classId="51f2d5d8-ea4d-4064-8892-82951750031e" objectId="226f8224-ac83-415d-a7e4-b19aa04c6d65"/>
|
||||
<containedObjects classId="e68182ea-4237-4383-967f-90c1e3370bc7" objectId="de855bce-4f5d-4221-a07b-9fcc9b35d43b"/>
|
||||
<containedObjects classId="fb282519-d103-4dd3-bc12-cb271d631dfc" objectId="79eb6212-51c7-4a94-9b0c-41a53e0abc10"/>
|
||||
<configurationExtensionCompatibilityMode>8.3.21</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.21</compatibilityMode>
|
||||
<languages uuid="a2c91e21-184e-4a5a-9f72-d913d22682e4">
|
||||
<name>English</name>
|
||||
<synonym>
|
||||
<key>en</key>
|
||||
<value>English</value>
|
||||
</synonym>
|
||||
<languageCode>en</languageCode>
|
||||
</languages>
|
||||
<commonModules>CommonModule.CommonModule</commonModules>
|
||||
<commonModules>CommonModule.CommonModuleCached</commonModules>
|
||||
<commonModules>CommonModule.CommonModuleCachedCompliant</commonModules>
|
||||
</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…
Reference in New Issue
Block a user