mirror of
https://github.com/1C-Company/v8-code-style.git
synced 2024-11-28 09:33:06 +02:00
* Использование конструкции Новый Шрифт
This commit is contained in:
parent
ffc108df57
commit
8afbb3dc09
@ -18,6 +18,7 @@
|
||||
#### Код модулей
|
||||
|
||||
- Добавление типизированного значения в не типизированную коллекцию
|
||||
- Использование конструкции "Новый Шрифт"
|
||||
- Проверка наличия префикса расширения в имени переменной расширения
|
||||
- Проверка наличия префикса расширения в методе расширения.
|
||||
- Устаревшая процедура (функция) расположена вне области "УстаревшиеПроцедурыИФункции"
|
||||
|
23
bundles/com.e1c.v8codestyle.bsl/markdown/new-font.md
Normal file
23
bundles/com.e1c.v8codestyle.bsl/markdown/new-font.md
Normal file
@ -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.<Name of style element>; ...
|
||||
```
|
||||
|
||||
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)
|
23
bundles/com.e1c.v8codestyle.bsl/markdown/ru/new-font.md
Normal file
23
bundles/com.e1c.v8codestyle.bsl/markdown/ru/new-font.md
Normal file
@ -0,0 +1,23 @@
|
||||
# Использование конструкции "Новый Шрифт"
|
||||
|
||||
Для изменения оформления следует использовать элементы стиля, а не
|
||||
задавать конкретные значения непосредственно в элементах управления.
|
||||
|
||||
## Неправильно
|
||||
|
||||
```bsl
|
||||
Шрифт = Новый Шрифт(, 1, Истина, Истина, Истина, Истина, 100); ...
|
||||
```
|
||||
|
||||
## Правильно
|
||||
|
||||
```bsl
|
||||
Шрифт = ШрифтСтиля.<Имя элемента стиля>; ...
|
||||
```
|
||||
|
||||
Это требуется для того, чтобы аналогичные элементы управления выглядели
|
||||
одинаково во всех формах, где они встречаются.
|
||||
|
||||
## См.
|
||||
|
||||
- [Элементы стиля](https://its.1c.ru/db/v8std#content:667:hdoc:1)
|
@ -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.bsl.check.NewFontCheck">
|
||||
</check>
|
||||
<check
|
||||
category="com.e1c.v8codestyle.bsl"
|
||||
class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.check.ExtensionVariablePrefixCheck">
|
||||
|
@ -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;
|
||||
|
@ -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<Expression> 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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=Для изменения оформления следует использовать элементы стиля, а не задавать конкретные значения непосредственно в элементах управления. Это требуется для того, чтобы аналогичные элементы управления выглядели одинаково во всех формах, где они встречаются.
|
||||
|
@ -0,0 +1,5 @@
|
||||
Процедура Тест()
|
||||
|
||||
font = new Font(, 1, True, True, False, True, 100);
|
||||
|
||||
КонецПроцедуры
|
10
tests/com.e1c.v8codestyle.bsl.itests/resources/new-font2.bsl
Normal file
10
tests/com.e1c.v8codestyle.bsl.itests/resources/new-font2.bsl
Normal file
@ -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
|
@ -0,0 +1,5 @@
|
||||
Процедура Тест()
|
||||
|
||||
font = new ("Font");
|
||||
|
||||
КонецПроцедуры
|
@ -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<Marker> 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<Marker> 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<Marker> markers = getModuleMarkers();
|
||||
assertTrue(markers.isEmpty());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user