From e6b22f922a07c29ad491edaef72a4967f3c5ef9b Mon Sep 17 00:00:00 2001
From: Artem Iliukhin <20300020+iArtemv@users.noreply.github.com>
Date: Tue, 24 Jan 2023 06:19:29 +0300
Subject: [PATCH] =?UTF-8?q?#499=20=D0=93=D0=BB=D0=BE=D0=B1=D0=B0=D0=BB?=
=?UTF-8?q?=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82?=
=?UTF-8?q?=D1=81=D0=BA=D0=B8=D0=B9=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8C?=
=?UTF-8?q?=20=D0=BD=D0=B5=20=D0=B4=D0=BE=D0=BB=D0=B6=D0=B5=D0=BD=20=D1=81?=
=?UTF-8?q?=D0=BE=D0=B4=D0=B5=D1=80=D0=B6=D0=B0=D1=82=D1=8C=20=D0=BF=D0=BE?=
=?UTF-8?q?=D1=81=D1=82=D1=84=D0=B8=D0=BA=D1=81=20=D0=9A=D0=BB=D0=B8=D0=B5?=
=?UTF-8?q?=D0=BD=D1=82=20(#1194)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
CHANGELOG.md | 1 +
.../common-module-name-global-client.md | 16 +++
.../ru/common-module-name-global-client.md | 17 +++
bundles/com.e1c.v8codestyle.md/plugin.xml | 4 +
.../md/check/CommonModuleNameGlobal.java | 6 +-
.../CommonModuleNameGlobalClientCheck.java | 104 +++++++++++++++++
.../e1c/v8codestyle/md/check/Messages.java | 9 +-
.../v8codestyle/md/check/messages.properties | 12 +-
.../md/check/messages_ru.properties | 12 +-
...CommonModuleNameGlobalClientCheckTest.java | 108 ++++++++++++++++++
10 files changed, 277 insertions(+), 12 deletions(-)
create mode 100644 bundles/com.e1c.v8codestyle.md/markdown/common-module-name-global-client.md
create mode 100644 bundles/com.e1c.v8codestyle.md/markdown/ru/common-module-name-global-client.md
create mode 100644 bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/CommonModuleNameGlobalClientCheck.java
create mode 100644 tests/com.e1c.v8codestyle.md.itests/src/com/e1c/v8codestyle/md/check/itests/CommonModuleNameGlobalClientCheckTest.java
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 658b8561..673bc6a7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@
#### Метаданные
- Превышена максимальная длина ресурса регистра накопления или бухгалтерии (25 знаков)
+- Для глобальных модулей не следует добавлять постфикс «Клиент»
- Проверка наличия префикса расширения в имени объекта расширения.
- Общий модуль, для которого установлен признак привилегированный, должен именоваться с постфиксом "ПолныеПрава"
diff --git a/bundles/com.e1c.v8codestyle.md/markdown/common-module-name-global-client.md b/bundles/com.e1c.v8codestyle.md/markdown/common-module-name-global-client.md
new file mode 100644
index 00000000..e47f4805
--- /dev/null
+++ b/bundles/com.e1c.v8codestyle.md/markdown/common-module-name-global-client.md
@@ -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/)
\ No newline at end of file
diff --git a/bundles/com.e1c.v8codestyle.md/markdown/ru/common-module-name-global-client.md b/bundles/com.e1c.v8codestyle.md/markdown/ru/common-module-name-global-client.md
new file mode 100644
index 00000000..461a5dc6
--- /dev/null
+++ b/bundles/com.e1c.v8codestyle.md/markdown/ru/common-module-name-global-client.md
@@ -0,0 +1,17 @@
+# Глобальный клиентский общий модуль должен оканчиваться на суффикс Глобальный без суффикса Клиент
+
+3.2.1. Для глобальных модулей добавляется постфикс «Глобальный», в
+этом случае постфикс «Клиент» добавлять не следует.
+
+
+## Неправильно
+
+РаботаСФайламиГлобальныйКлиент
+
+## Правильно
+
+РаботаСФайламиГлобальный
+
+## См.
+
+[Правила создания общих модулей](https://its.1c.ru/db/v8std#content:469:hdoc:3.2.1)
\ No newline at end of file
diff --git a/bundles/com.e1c.v8codestyle.md/plugin.xml b/bundles/com.e1c.v8codestyle.md/plugin.xml
index 702f07c7..97706624 100644
--- a/bundles/com.e1c.v8codestyle.md/plugin.xml
+++ b/bundles/com.e1c.v8codestyle.md/plugin.xml
@@ -98,6 +98,10 @@
category="com.e1c.v8codestyle.md"
class="com.e1c.v8codestyle.md.check.SubsystemSynonymTooLongCheck">
+
+
diff --git a/bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/CommonModuleNameGlobal.java b/bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/CommonModuleNameGlobal.java
index f80c1b06..9ac81211 100644
--- a/bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/CommonModuleNameGlobal.java
+++ b/bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/CommonModuleNameGlobal.java
@@ -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);
}
diff --git a/bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/CommonModuleNameGlobalClientCheck.java b/bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/CommonModuleNameGlobalClientCheck.java
new file mode 100644
index 00000000..9cfa8fe7
--- /dev/null
+++ b/bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/CommonModuleNameGlobalClientCheck.java
@@ -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);
+ }
+ }
+}
diff --git a/bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/Messages.java b/bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/Messages.java
index 87260099..ad24ba4f 100644
--- a/bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/Messages.java
+++ b/bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/Messages.java
@@ -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;
diff --git a/bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/messages.properties b/bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/messages.properties
index 7b75554b..568ac2f4 100644
--- a/bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/messages.properties
+++ b/bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/messages.properties
@@ -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
diff --git a/bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/messages_ru.properties b/bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/messages_ru.properties
index fa38107c..fcc422b5 100644
--- a/bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/messages_ru.properties
+++ b/bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/messages_ru.properties
@@ -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 = Общий модуль имеет некорректный тип
diff --git a/tests/com.e1c.v8codestyle.md.itests/src/com/e1c/v8codestyle/md/check/itests/CommonModuleNameGlobalClientCheckTest.java b/tests/com.e1c.v8codestyle.md.itests/src/com/e1c/v8codestyle/md/check/itests/CommonModuleNameGlobalClientCheckTest.java
new file mode 100644
index 00000000..e1226d32
--- /dev/null
+++ b/tests/com.e1c.v8codestyle.md.itests/src/com/e1c/v8codestyle/md/check/itests/CommonModuleNameGlobalClientCheckTest.java
@@ -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("change type")
+ {
+ @Override
+ public Void execute(IBmTransaction transaction, IProgressMonitor monitor)
+ {
+ IBmObject object = transaction.getTopObjectByFqn(fqn);
+
+ for (Entry 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);
+ }
+}