From 4075834674056e6295504203c303ae8e6c9403a2 Mon Sep 17 00:00:00 2001 From: Artem Iliukhin Date: Thu, 6 Jan 2022 12:58:53 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BD=D1=81?= =?UTF-8?q?=D1=82=D1=80=D1=83=D0=BA=D1=86=D0=B8=D0=B8=20"=D0=9D=D0=BE?= =?UTF-8?q?=D0=B2=D1=8B=D0=B9=20=D0=A6=D0=B2=D0=B5=D1=82"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + .../markdown/new-color.md | 23 +++++ .../markdown/ru/new-color.md | 23 +++++ bundles/com.e1c.v8codestyle.bsl/plugin.xml | 4 + .../e1c/v8codestyle/bsl/check/Messages.java | 6 ++ .../v8codestyle/bsl/check/NewColorCheck.java | 95 +++++++++++++++++++ .../v8codestyle/bsl/check/messages.properties | 6 ++ .../bsl/check/messages_ru.properties | 6 ++ .../resources/new-color.bsl | 5 + .../resources/new-color2.bsl | 5 + .../resources/new-color3.bsl | 6 ++ .../resources/new-color4.bsl | 5 + .../bsl/check/itests/NewColorCheckTest.java | 82 ++++++++++++++++ 13 files changed, 267 insertions(+) create mode 100644 bundles/com.e1c.v8codestyle.bsl/markdown/new-color.md create mode 100644 bundles/com.e1c.v8codestyle.bsl/markdown/ru/new-color.md create mode 100644 bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/check/NewColorCheck.java create mode 100644 tests/com.e1c.v8codestyle.bsl.itests/resources/new-color.bsl create mode 100644 tests/com.e1c.v8codestyle.bsl.itests/resources/new-color2.bsl create mode 100644 tests/com.e1c.v8codestyle.bsl.itests/resources/new-color3.bsl create mode 100644 tests/com.e1c.v8codestyle.bsl.itests/resources/new-color4.bsl create mode 100644 tests/com.e1c.v8codestyle.bsl.itests/src/com/e1c/v8codestyle/bsl/check/itests/NewColorCheckTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index db7b3d18..6150fc2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - Использован метод "РольДоступна()" - Программный вызов обработчика события формы - Изменение категории проверки use-non-recommended-method на "стандарты разработки" +- Использование конструкции "Новый Цвет" #### Запросы diff --git a/bundles/com.e1c.v8codestyle.bsl/markdown/new-color.md b/bundles/com.e1c.v8codestyle.bsl/markdown/new-color.md new file mode 100644 index 00000000..c1b773c0 --- /dev/null +++ b/bundles/com.e1c.v8codestyle.bsl/markdown/new-color.md @@ -0,0 +1,23 @@ +# Using the "New Color" construction + +To change the design, you should use style elements, and not +set specific values directly in the controls. + +## Noncompliant Code Example + +```bsl +Color = new Color(0,0,0); ... +``` + +## Compliant Solution + +```bsl +Color = StyleColors.; ... +``` + +This is required in order for similar controls to look +the same in all forms where they occur. + +## See + +- [Styles and style elements](https://support.1ci.com/hc/en-us/articles/4403174580370-5-5-22-Styles-and-style-elements) diff --git a/bundles/com.e1c.v8codestyle.bsl/markdown/ru/new-color.md b/bundles/com.e1c.v8codestyle.bsl/markdown/ru/new-color.md new file mode 100644 index 00000000..191ffadf --- /dev/null +++ b/bundles/com.e1c.v8codestyle.bsl/markdown/ru/new-color.md @@ -0,0 +1,23 @@ +# Использование конструкции "Новый Цвет" + +Для изменения оформления следует использовать элементы стиля, а не +задавать конкретные значения непосредственно в элементах управления. + +## Неправильно + +```bsl +Цвет = Новый Цвет(0,0,0); ... +``` + +## Правильно + +```bsl +Цвет = ЦветаСтиля.<Имя элемента стиля>; ... +``` + +Это требуется для того, чтобы аналогичные элементы управления выглядели +одинаково во всех формах, где они встречаются. + +## См. + +- [Элементы стиля](https://its.1c.ru/db/v8std#content:667:hdoc:1) diff --git a/bundles/com.e1c.v8codestyle.bsl/plugin.xml b/bundles/com.e1c.v8codestyle.bsl/plugin.xml index 46aca8ce..de63c0b2 100644 --- a/bundles/com.e1c.v8codestyle.bsl/plugin.xml +++ b/bundles/com.e1c.v8codestyle.bsl/plugin.xml @@ -160,6 +160,10 @@ category="com.e1c.v8codestyle.bsl" class="com.e1c.v8codestyle.bsl.check.InvocationFormEventHandlerCheck"> + + types = ((FunctionStyleCreator)object).getTypes(); + if (!types.isEmpty()) + { + TypeItem type = types.get(0); + addResultAceptor(object, resultAceptor, type); + } + } + } + + private void addResultAceptor(Object object, ResultAcceptor resultAceptor, TypeItem type) + { + String name = McoreUtil.getTypeName(type); + if (COLOR.equalsIgnoreCase(name)) + { + resultAceptor.addIssue(Messages.NewColorCheck_Use_style_elements, object); + } + } +} diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/check/messages.properties b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/check/messages.properties index b077895b..7b97253c 100644 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/check/messages.properties +++ b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/check/messages.properties @@ -140,6 +140,12 @@ ModuleUnusedMethodCheck_Title = Unused method check ModuleUnusedMethodCheck_Unused_method__0 = Unused method "{0}" +NewColorCheck_Use_style_elements=To change the design, you should use style elements, and not set specific values directly in the controls + +NewColorCheck_Use_style_elements_not_specific_values=To change the design, you should use style elements, and not set specific values directly in the controls. This is required in order for similar controls to look the same in all forms where they occur. + +NewColorCheck_Using_new_color=Using the "New Color" construction + NotifyDescriptionToServerProcedureCheck_Notify_description_procedure_should_be_export = Notify description procedure should exist and be export NotifyDescriptionToServerProcedureCheck_Notify_description_to_Server_procedure = Notify description to Server procedure diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/check/messages_ru.properties b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/check/messages_ru.properties index eecd84a8..cdf3d2de 100644 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/check/messages_ru.properties +++ b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/check/messages_ru.properties @@ -140,6 +140,12 @@ ModuleUnusedMethodCheck_Title = Проверка неиспользуемых м ModuleUnusedMethodCheck_Unused_method__0 = Неиспользуемый метод "{0}" +NewColorCheck_Use_style_elements=Для изменения оформления следует использовать элементы стиля, а не задавать конкретные значения непосредственно в элементах управления + +NewColorCheck_Use_style_elements_not_specific_values=Для изменения оформления следует использовать элементы стиля, а не задавать конкретные значения непосредственно в элементах управления. Это требуется для того, чтобы аналогичные элементы управления выглядели одинаково во всех формах, где они встречаются. + +NewColorCheck_Using_new_color=Использование конструкции "Новый Цвет" + NotifyDescriptionToServerProcedureCheck_Notify_description_procedure_should_be_export = Процедура описания оповещения должна существовать и быть экспортной NotifyDescriptionToServerProcedureCheck_Notify_description_to_Server_procedure = Описание оповещения на серверную процедуру diff --git a/tests/com.e1c.v8codestyle.bsl.itests/resources/new-color.bsl b/tests/com.e1c.v8codestyle.bsl.itests/resources/new-color.bsl new file mode 100644 index 00000000..be00da71 --- /dev/null +++ b/tests/com.e1c.v8codestyle.bsl.itests/resources/new-color.bsl @@ -0,0 +1,5 @@ +Процедура Тест() + + color = new Color(0,0,0); + +КонецПроцедуры \ No newline at end of file diff --git a/tests/com.e1c.v8codestyle.bsl.itests/resources/new-color2.bsl b/tests/com.e1c.v8codestyle.bsl.itests/resources/new-color2.bsl new file mode 100644 index 00000000..a49e2835 --- /dev/null +++ b/tests/com.e1c.v8codestyle.bsl.itests/resources/new-color2.bsl @@ -0,0 +1,5 @@ +Процедура Тест() + + color2 = new ("Color"); + +КонецПроцедуры \ No newline at end of file diff --git a/tests/com.e1c.v8codestyle.bsl.itests/resources/new-color3.bsl b/tests/com.e1c.v8codestyle.bsl.itests/resources/new-color3.bsl new file mode 100644 index 00000000..792a4609 --- /dev/null +++ b/tests/com.e1c.v8codestyle.bsl.itests/resources/new-color3.bsl @@ -0,0 +1,6 @@ +Процедура Тест() + + name = "Color"; + color2 = new (name); + +КонецПроцедуры \ No newline at end of file diff --git a/tests/com.e1c.v8codestyle.bsl.itests/resources/new-color4.bsl b/tests/com.e1c.v8codestyle.bsl.itests/resources/new-color4.bsl new file mode 100644 index 00000000..5b10595a --- /dev/null +++ b/tests/com.e1c.v8codestyle.bsl.itests/resources/new-color4.bsl @@ -0,0 +1,5 @@ +Процедура Тест() + + color = new ("Цвет"); + +КонецПроцедуры \ No newline at end of file diff --git a/tests/com.e1c.v8codestyle.bsl.itests/src/com/e1c/v8codestyle/bsl/check/itests/NewColorCheckTest.java b/tests/com.e1c.v8codestyle.bsl.itests/src/com/e1c/v8codestyle/bsl/check/itests/NewColorCheckTest.java new file mode 100644 index 00000000..404534ac --- /dev/null +++ b/tests/com.e1c.v8codestyle.bsl.itests/src/com/e1c/v8codestyle/bsl/check/itests/NewColorCheckTest.java @@ -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 java.util.List; + +import org.junit.Test; + +import com._1c.g5.v8.dt.validation.marker.Marker; +import com.e1c.v8codestyle.bsl.check.NewColorCheck; + +/** + * Tests for {@link NewColorCheck} check. + * + * @author Artem Iliukhin + */ +public class NewColorCheckTest + extends AbstractSingleModuleTestBase +{ + + private static final String NEW_COLOR = + "To change the design, you should use style elements, and not set specific values directly in the controls"; + + public NewColorCheckTest() + { + super(NewColorCheck.class); + } + + @Test + public void testNewColorO() throws Exception + { + updateModule(FOLDER_RESOURCE + "new-color.bsl"); + + List markers = getModuleMarkers(); + assertEquals(1, markers.size()); + Marker marker = markers.get(0); + assertEquals(NEW_COLOR, marker.getMessage()); + } + + @Test + public void testNewColorF() throws Exception + { + updateModule(FOLDER_RESOURCE + "new-color2.bsl"); + + List markers = getModuleMarkers(); + assertEquals(1, markers.size()); + Marker marker = markers.get(0); + assertEquals(NEW_COLOR, marker.getMessage()); + } + + @Test + public void testNewColor3() throws Exception + { + updateModule(FOLDER_RESOURCE + "new-color3.bsl"); + + List markers = getModuleMarkers(); + assertEquals(0, markers.size()); + } + + @Test + public void testNewColor4() throws Exception + { + updateModule(FOLDER_RESOURCE + "new-color4.bsl"); + + List markers = getModuleMarkers(); + assertEquals(1, markers.size()); + Marker marker = markers.get(0); + assertEquals(NEW_COLOR, marker.getMessage()); + } +}