1
0
mirror of https://github.com/1C-Company/v8-code-style.git synced 2025-07-16 12:44:15 +02:00

#499 Глобальный клиентский модуль не должен содержать постфикс Клиент (#1194)

This commit is contained in:
Artem Iliukhin
2023-01-24 06:19:29 +03:00
committed by GitHub
parent 9a5488db9a
commit e6b22f922a
10 changed files with 277 additions and 12 deletions

View File

@ -11,6 +11,7 @@
#### Метаданные
- Превышена максимальная длина ресурса регистра накопления или бухгалтерии (25 знаков)
- Для глобальных модулей не следует добавлять постфикс «Клиент»
- Проверка наличия префикса расширения в имени объекта расширения.
- Общий модуль, для которого установлен признак привилегированный, должен именоваться с постфиксом "ПолныеПрава"

View File

@ -0,0 +1,16 @@
# Global client common module should end with Global suffix no Client suffix
3.2.1. Add the "Global" postfix for global modules. In this case, you do not need to add the "Client" postfix.
## Noncompliant Code Example
FilesOperationsGlobalClient, InfobaseUpdateGlobalClient.
## Compliant Solution
FilesOperationsGlobal, InfobaseUpdateGlobal.
## See
[Common modules creating rules](https://kb.1ci.com/1C_Enterprise_Platform/Guides/Developer_Guides/1C_Enterprise_Development_Standards/Creating_and_modifying_metadata_objects/Configuration_operation_arrangement/Common_modules_creating_rules/)

View File

@ -0,0 +1,17 @@
# Глобальный клиентский общий модуль должен оканчиваться на суффикс Глобальный без суффикса Клиент
3.2.1. Для глобальных модулей добавляется постфикс «Глобальный», в
этом случае постфикс «Клиент» добавлять не следует.
## Неправильно
РаботаСФайламиГлобальныйКлиент
## Правильно
РаботаСФайламиГлобальный
## См.
[Правила создания общих модулей](https://its.1c.ru/db/v8std#content:469:hdoc:3.2.1)

View File

@ -98,6 +98,10 @@
category="com.e1c.v8codestyle.md"
class="com.e1c.v8codestyle.md.check.SubsystemSynonymTooLongCheck">
</check>
<check
category="com.e1c.v8codestyle.md"
class="com.e1c.v8codestyle.internal.md.ExecutableExtensionFactory:com.e1c.v8codestyle.md.check.CommonModuleNameGlobalClientCheck">
</check>
<check
category="com.e1c.v8codestyle.md"
class="com.e1c.v8codestyle.md.check.CommonModuleNamePrivilegedCheck">

View File

@ -66,8 +66,8 @@ public final class CommonModuleNameGlobal
protected void configureCheck(CheckConfigurer builder)
{
//@formatter:off
builder.title(Messages.CommonModuleNameGlobal_title)
.description(Messages.CommonModuleNameGlobal_description)
builder.title(Messages.CommonModuleNameGlobal_Title)
.description(Messages.CommonModuleNameGlobal_Description)
.complexity(CheckComplexity.NORMAL)
.severity(IssueSeverity.CRITICAL)
.issueType(IssueType.WARNING)
@ -111,7 +111,7 @@ public final class CommonModuleNameGlobal
return;
}
String message = MessageFormat.format(Messages.CommonModuleNameGlobal_message,
String message = MessageFormat.format(Messages.CommonModuleNameGlobal_Message,
parameters.getString(MdObjectNameWithoutSuffix.NAME_SUFFIX_PARAMETER_NAME));
resultAceptor.addIssue(message, MD_OBJECT__NAME);
}

View File

@ -0,0 +1,104 @@
/*******************************************************************************
* 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.md.check;
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.COMMON_MODULE;
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.COMMON_MODULE__GLOBAL;
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.MD_OBJECT__NAME;
import java.text.MessageFormat;
import org.eclipse.core.runtime.IProgressMonitor;
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.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.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.md.CorePlugin;
import com.google.inject.Inject;
/**
* Checks client global common module name has not "Client" suffix
*
* @author Artem Iliukhin
*/
public class CommonModuleNameGlobalClientCheck
extends BasicCheck
{
private static final String CHECK_ID = "common-module-name-global-client"; //$NON-NLS-1$
private static final String NAME_SUFFIX_RU = "Клиент"; //$NON-NLS-1$
private static final String NAME_SUFFIX_EN = "Client"; //$NON-NLS-1$
private final IV8ProjectManager v8ProjectManager;
/**
* Instantiates a new common module name global client check.
*
* @param v8ProjectManager
*/
@Inject
public CommonModuleNameGlobalClientCheck(IV8ProjectManager v8ProjectManager)
{
super();
this.v8ProjectManager = v8ProjectManager;
}
@Override
public String getCheckId()
{
return CHECK_ID;
}
@Override
protected void configureCheck(CheckConfigurer builder)
{
builder.title(Messages.CommonModuleNameGlobalClientCheck_Title)
.description(Messages.CommonModuleNameGlobalClientCheck_Description)
.complexity(CheckComplexity.NORMAL)
.severity(IssueSeverity.CRITICAL)
.issueType(IssueType.WARNING)
.extension(new StandardCheckExtension(469, getCheckId(), CorePlugin.PLUGIN_ID))
.topObject(COMMON_MODULE)
.checkTop()
.features(MD_OBJECT__NAME, COMMON_MODULE__GLOBAL);
}
@Override
protected void check(Object object, ResultAcceptor resultAceptor, ICheckParameters parameters,
IProgressMonitor monitor)
{
CommonModule commonModule = (CommonModule)object;
if (!commonModule.isGlobal())
{
return;
}
IV8Project project = v8ProjectManager.getProject(commonModule);
ScriptVariant variant = project == null ? ScriptVariant.ENGLISH : project.getScriptVariant();
String name = commonModule.getName();
String suffix = ScriptVariant.ENGLISH == variant ? NAME_SUFFIX_EN : NAME_SUFFIX_RU;
if (name.contains(suffix))
{
String message = MessageFormat.format(Messages.CommonModuleNameGlobalClientCheck_Message, suffix);
resultAceptor.addIssue(message, MD_OBJECT__NAME);
}
}
}

View File

@ -35,9 +35,12 @@ final class Messages
public static String CommonModuleNamePrivilegedCheck_Description;
public static String CommonModuleNamePrivilegedCheck_Issue;
public static String CommonModuleNamePrivilegedCheck_Title;
public static String CommonModuleNameGlobal_description;
public static String CommonModuleNameGlobal_message;
public static String CommonModuleNameGlobal_title;
public static String CommonModuleNameGlobal_Description;
public static String CommonModuleNameGlobal_Message;
public static String CommonModuleNameGlobal_Title;
public static String CommonModuleNameGlobalClientCheck_Description;
public static String CommonModuleNameGlobalClientCheck_Message;
public static String CommonModuleNameGlobalClientCheck_Title;
public static String CommonModuleType_description;
public static String CommonModuleType_message;
public static String CommonModuleType_title;

View File

@ -17,11 +17,17 @@ CommonModuleNamePrivilegedCheck_Issue=Privileged common module should end with "
CommonModuleNamePrivilegedCheck_Title=Privileged common module should end with FullAccess suffix
CommonModuleNameGlobal_description = Global common module should end with Global suffix
CommonModuleNameGlobal_Description=Global common module should end with Global suffix
CommonModuleNameGlobal_message = Global common module should end with "{0}" suffix
CommonModuleNameGlobal_Message=Global common module should end with "{0}" suffix
CommonModuleNameGlobal_title = Global common module should end with Global suffix
CommonModuleNameGlobal_Title=Global common module should end with Global suffix
CommonModuleNameGlobalClientCheck_Description=Global common module should end with Global suffix
CommonModuleNameGlobalClientCheck_Message=Global common module should not have "{0}" suffix
CommonModuleNameGlobalClientCheck_Title=Global common module should end with Global suffix
CommonModuleType_description = Common module has incorrect type

View File

@ -18,11 +18,17 @@ CommonModuleNamePrivilegedCheck_Issue=Привилегированный мод
CommonModuleNamePrivilegedCheck_Title=Привилегированный модуль должен оканчиваться на суффикс ПолныеПрава
CommonModuleNameGlobal_description = Глобальный общий модуль должен оканчиваться на суффикс Глобальный
CommonModuleNameGlobal_Description = Глобальный общий модуль должен оканчиваться на суффикс Глобальный
CommonModuleNameGlobal_message = Глобальный общий модуль должен оканчиваться на суффикс "{0}"
CommonModuleNameGlobal_Message = Глобальный общий модуль должен оканчиваться на суффикс "{0}"
CommonModuleNameGlobal_title = Глобальный общий модуль должен оканчиваться на суффикс Глобальный
CommonModuleNameGlobal_Title = Глобальный общий модуль должен оканчиваться на суффикс Глобальный
CommonModuleNameGlobalClientCheck_Description=Глобальный общий модуль должен оканчиваться на суффикс Глобальный
CommonModuleNameGlobalClientCheck_Message=Глобальный общий модуль не должен содержать суффикс "{0}"
CommonModuleNameGlobalClientCheck_Title=Глобальный общий модуль должен оканчиваться на суффикс Глобальный
CommonModuleType_description = Общий модуль имеет некорректный тип

View File

@ -0,0 +1,108 @@
/**
*
*/
package com.e1c.v8codestyle.md.check.itests;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.util.Map.Entry;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.junit.Test;
import com._1c.g5.v8.bm.core.IBmObject;
import com._1c.g5.v8.bm.core.IBmTransaction;
import com._1c.g5.v8.bm.integration.AbstractBmTask;
import com._1c.g5.v8.bm.integration.IBmModel;
import com._1c.g5.v8.dt.core.platform.IDtProject;
import com._1c.g5.v8.dt.metadata.mdclass.CommonModule;
import com._1c.g5.v8.dt.validation.marker.Marker;
import com.e1c.g5.v8.dt.testing.check.CheckTestBase;
import com.e1c.v8codestyle.md.CommonModuleTypes;
import com.e1c.v8codestyle.md.check.CommonModuleNameGlobalClientCheck;
/**
* Tests for {@link CommonModuleNameGlobalClientCheck} check.
*
* @author Artem Iliukhin
*
*/
public class CommonModuleNameGlobalClientCheckTest
extends CheckTestBase
{
private static final String CHECK_ID = "common-module-name-global-client";
private static final String PROJECT_NAME = "CommonModuleName";
private static final String MODULE_DEFAULT_FQN = "CommonModule.CommonModuleName";
@Test
public void testCommonModuleNameClientGlobal() throws Exception
{
IDtProject dtProject = openProjectAndWaitForValidationFinish(PROJECT_NAME);
assertNotNull(dtProject);
String fqn = "CommonModule.CommonModuleGlobalClient";
updateCommonModule(dtProject, MODULE_DEFAULT_FQN, CommonModuleTypes.CLIENT_GLOBAL, fqn);
long id = getTopObjectIdByFqn(fqn, dtProject);
Marker marker = getFirstMarker(CHECK_ID, id, dtProject);
assertNotNull(marker);
}
@Test
public void testCommonModuleNameClientGlobalCompliant() throws Exception
{
IDtProject dtProject = openProjectAndWaitForValidationFinish(PROJECT_NAME);
assertNotNull(dtProject);
String fqn = "CommonModule.CommonModuleGlobal";
updateCommonModule(dtProject, MODULE_DEFAULT_FQN, CommonModuleTypes.CLIENT_GLOBAL, fqn);
long id = getTopObjectIdByFqn(fqn, dtProject);
Marker marker = getFirstMarker(CHECK_ID, id, dtProject);
assertNull(marker);
}
private void updateCommonModule(IDtProject dtProject, String fqn, CommonModuleTypes type, String newFqn)
{
IBmModel model = bmModelManager.getModel(dtProject);
model.execute(new AbstractBmTask<Void>("change type")
{
@Override
public Void execute(IBmTransaction transaction, IProgressMonitor monitor)
{
IBmObject object = transaction.getTopObjectByFqn(fqn);
for (Entry<EStructuralFeature, Object> entry : type.getFeatureValues(false).entrySet())
{
object.eSet(entry.getKey(), entry.getValue());
}
if (!(object instanceof CommonModule))
{
return null;
}
CommonModule module = (CommonModule)object;
if (newFqn != null)
{
String[] fqnArray = newFqn.split("[.]");
if (fqnArray.length == 2)
{
module.setName(fqnArray[1]);
transaction.updateTopObjectFqn(object, newFqn);
}
}
return null;
}
});
waitForDD(dtProject);
}
}