diff --git a/CHANGELOG.md b/CHANGELOG.md index a4dc2f0b..16dc3e58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ #### Код модулей - Добавление типизированного значения в не типизированную коллекцию +- Использование конструкции "Новый Шрифт" - Проверка наличия префикса расширения в имени переменной расширения - Проверка наличия префикса расширения в методе расширения. - Устаревшая процедура (функция) расположена вне области "УстаревшиеПроцедурыИФункции" diff --git a/bundles/com.e1c.v8codestyle.bsl/markdown/new-font.md b/bundles/com.e1c.v8codestyle.bsl/markdown/new-font.md new file mode 100644 index 00000000..3a655140 --- /dev/null +++ b/bundles/com.e1c.v8codestyle.bsl/markdown/new-font.md @@ -0,0 +1,23 @@ +# Using the "New Font" construction + +To change the design, you should use style elements and not +set specific values directly in the controls. + +## Noncompliant Code Example + +```bsl +Font = new Font(, 1, True, True, False, True, 100); ... +``` + +## Compliant Solution + +```bsl +Font = StyleFonts.; ... +``` + +This is required in order for similar controls to look +the same in all forms where they occur. + +## See + +- [Styles and style elements](https://kb.1ci.com/1C_Enterprise_Platform/Guides/Developer_Guides/1C_Enterprise_8.3.18_Developer_Guide/Chapter_5._Configuration_objects/5.5.__Common__configuration_branch/5.5.22._Styles_and_style_elements/5.5.22._Styles_and_style_elements) diff --git a/bundles/com.e1c.v8codestyle.bsl/markdown/ru/new-font.md b/bundles/com.e1c.v8codestyle.bsl/markdown/ru/new-font.md new file mode 100644 index 00000000..30818943 --- /dev/null +++ b/bundles/com.e1c.v8codestyle.bsl/markdown/ru/new-font.md @@ -0,0 +1,23 @@ +# Использование конструкции "Новый Шрифт" + +Для изменения оформления следует использовать элементы стиля, а не +задавать конкретные значения непосредственно в элементах управления. + +## Неправильно + +```bsl +Шрифт = Новый Шрифт(, 1, Истина, Истина, Истина, Истина, 100); ... +``` + +## Правильно + +```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 57392196..742f6438 100644 --- a/bundles/com.e1c.v8codestyle.bsl/plugin.xml +++ b/bundles/com.e1c.v8codestyle.bsl/plugin.xml @@ -311,6 +311,10 @@ category="com.e1c.v8codestyle.bsl" class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.check.ModuleStructureVariablesInRegionCheck"> + + diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/check/Messages.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/check/Messages.java index b3a5b988..bbd19616 100644 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/check/Messages.java +++ b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/check/Messages.java @@ -267,6 +267,12 @@ final class Messages public static String NewColorCheck_Using_new_color; + public static String NewFontCheck_Description; + + public static String NewFontCheck_Issue; + + public static String NewFontCheck_Title; + public static String NstrStringLiteralFormatCheck_Check_empty_interface_for_each_language; public static String NstrStringLiteralFormatCheck_description; diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/check/NewFontCheck.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/check/NewFontCheck.java new file mode 100644 index 00000000..48bebd73 --- /dev/null +++ b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/check/NewFontCheck.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * 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.FUNCTION_STYLE_CREATOR; +import static com._1c.g5.v8.dt.bsl.model.BslPackage.Literals.OPERATOR_STYLE_CREATOR; +import static com._1c.g5.v8.dt.platform.IEObjectTypeNames.FONT; +import static com._1c.g5.v8.dt.platform.IEObjectTypeNames.FONT_RU; + +import java.util.List; + +import org.eclipse.core.runtime.IProgressMonitor; + +import com._1c.g5.v8.dt.bsl.model.Expression; +import com._1c.g5.v8.dt.bsl.model.FunctionStyleCreator; +import com._1c.g5.v8.dt.bsl.model.Invocation; +import com._1c.g5.v8.dt.bsl.model.OperatorStyleCreator; +import com._1c.g5.v8.dt.bsl.model.StringLiteral; +import com._1c.g5.v8.dt.mcore.Type; +import com._1c.g5.v8.dt.mcore.util.McoreUtil; +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.bsl.BslPlugin; + +/** + * Checks use constructor New Font. + * + * @author Artem Iliukhin + */ +public final class NewFontCheck + extends BasicCheck +{ + + private static final String CHECK_ID = "new-font"; //$NON-NLS-1$ + + @Override + public String getCheckId() + { + return CHECK_ID; + } + + @Override + protected void configureCheck(CheckConfigurer builder) + { + builder.title(Messages.NewFontCheck_Title) + .description(Messages.NewFontCheck_Description) + .complexity(CheckComplexity.NORMAL) + .severity(IssueSeverity.MINOR) + .issueType(IssueType.WARNING) + .extension(new StandardCheckExtension(667, getCheckId(), BslPlugin.PLUGIN_ID)) + .module() + .checkedObjectType(OPERATOR_STYLE_CREATOR) + .checkedObjectType(FUNCTION_STYLE_CREATOR); + } + + @Override + protected void check(Object object, ResultAcceptor resultAceptor, ICheckParameters parameters, + IProgressMonitor monitor) + { + if (object instanceof OperatorStyleCreator && !((OperatorStyleCreator)object).getParams().isEmpty()) + { + Type type = ((OperatorStyleCreator)object).getType(); + String name = McoreUtil.getTypeName(type); + check(object, resultAceptor, name); + } + else if (object instanceof FunctionStyleCreator && ((FunctionStyleCreator)object).getParamsExpression() != null) + { + Expression typeNameExpression = ((FunctionStyleCreator)object).getTypeNameExpression(); + if (typeNameExpression instanceof Invocation) + { + List params = ((Invocation)typeNameExpression).getParams(); + if (!params.isEmpty() && params.get(0) instanceof StringLiteral + && ((StringLiteral)params.get(0)).lines(true).size() == 1) + { + String name = ((StringLiteral)params.get(0)).lines(true).get(0); + check(object, resultAceptor, name); + } + } + // TODO: After implementing the issue #G5V8DT-22450 of supporting dfa for the Type, + // support scenarios when a variable or method is passed as a parameter that returns Type Font #1128 + } + } + + private void check(Object object, ResultAcceptor resultAceptor, String name) + { + if (FONT.equalsIgnoreCase(name) || FONT_RU.equalsIgnoreCase(name)) + { + resultAceptor.addIssue(Messages.NewFontCheck_Issue, 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 0f83ae7d..8295932c 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 @@ -305,6 +305,12 @@ NewColorCheck_Use_style_elements_not_specific_values=To change the design, you s NewColorCheck_Using_new_color=Using the "New Color" construction +NewFontCheck_Description=To change the font you should use style elements + +NewFontCheck_Issue=To change the font you should use style elements + +NewFontCheck_Title=Using the "New Font" 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 2f0fa36e..b82e180a 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 @@ -306,6 +306,12 @@ ModuleStructureEventRegionsCheck_Event_handler__0__not_region__1=Обработ ModuleStructureEventRegionsCheck_Title=Проверяет область обработчиков событий на наличие методов относящихся только к обработчикам +NewFontCheck_Description=Для изменения шрифта следует использовать элементы стиля + +NewFontCheck_Issue=Для изменения шрифта следует использовать элементы стиля + +NewFontCheck_Title=Использование конструкции "Новый Шрифт" + NewColorCheck_Use_style_elements=Для изменения оформления следует использовать элементы стиля, а не задавать конкретные значения непосредственно в элементах управления NewColorCheck_Use_style_elements_not_specific_values=Для изменения оформления следует использовать элементы стиля, а не задавать конкретные значения непосредственно в элементах управления. Это требуется для того, чтобы аналогичные элементы управления выглядели одинаково во всех формах, где они встречаются. diff --git a/tests/com.e1c.v8codestyle.bsl.itests/resources/new-font.bsl b/tests/com.e1c.v8codestyle.bsl.itests/resources/new-font.bsl new file mode 100644 index 00000000..3418d69f --- /dev/null +++ b/tests/com.e1c.v8codestyle.bsl.itests/resources/new-font.bsl @@ -0,0 +1,5 @@ +Процедура Тест() + + font = new Font(, 1, True, True, False, True, 100); + +КонецПроцедуры \ No newline at end of file diff --git a/tests/com.e1c.v8codestyle.bsl.itests/resources/new-font2.bsl b/tests/com.e1c.v8codestyle.bsl.itests/resources/new-font2.bsl new file mode 100644 index 00000000..f87130a3 --- /dev/null +++ b/tests/com.e1c.v8codestyle.bsl.itests/resources/new-font2.bsl @@ -0,0 +1,10 @@ +Procedure Test() + + Param = new Array(3); + Param[0] = 200; + Param[1] = 100; + Param[2] = 100; + + font = new (Type("Font"), Param); + +EndProcedure \ No newline at end of file diff --git a/tests/com.e1c.v8codestyle.bsl.itests/resources/new-font3.bsl b/tests/com.e1c.v8codestyle.bsl.itests/resources/new-font3.bsl new file mode 100644 index 00000000..1af0b454 --- /dev/null +++ b/tests/com.e1c.v8codestyle.bsl.itests/resources/new-font3.bsl @@ -0,0 +1,5 @@ +Процедура Тест() + + font = new ("Font"); + +КонецПроцедуры \ No newline at end of file diff --git a/tests/com.e1c.v8codestyle.bsl.itests/src/com/e1c/v8codestyle/bsl/check/itests/NewFontCheckTest.java b/tests/com.e1c.v8codestyle.bsl.itests/src/com/e1c/v8codestyle/bsl/check/itests/NewFontCheckTest.java new file mode 100644 index 00000000..c26d44a4 --- /dev/null +++ b/tests/com.e1c.v8codestyle.bsl.itests/src/com/e1c/v8codestyle/bsl/check/itests/NewFontCheckTest.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * 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 org.junit.Test; + +import com._1c.g5.v8.dt.validation.marker.IExtraInfoKeys; +import com._1c.g5.v8.dt.validation.marker.Marker; +import com.e1c.v8codestyle.bsl.check.NewFontCheck; + +/** + * Tests for {@link NewFontCheck} check. + * + * @author Artem Iliukhin + */ +public class NewFontCheckTest + extends AbstractSingleModuleTestBase +{ + + public NewFontCheckTest() + { + super(NewFontCheck.class); + } + + @Test + public void testNewFont1() throws Exception + { + updateModule(FOLDER_RESOURCE + "new-font.bsl"); + + List markers = getModuleMarkers(); + assertEquals(1, markers.size()); + Marker marker = markers.get(0); + assertEquals("3", marker.getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY)); + } + + @Test + public void testNewFont2() throws Exception + { + updateModule(FOLDER_RESOURCE + "new-font2.bsl"); + + List markers = getModuleMarkers(); + assertEquals(1, markers.size()); + Marker marker = markers.get(0); + assertEquals("8", marker.getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY)); + } + + @Test + public void testNewFont3() throws Exception + { + updateModule(FOLDER_RESOURCE + "new-font3.bsl"); + + List markers = getModuleMarkers(); + assertTrue(markers.isEmpty()); + } + +}