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
4a2f45eeff
commit
4075834674
@ -24,6 +24,7 @@
|
||||
- Использован метод "РольДоступна()"
|
||||
- Программный вызов обработчика события формы
|
||||
- Изменение категории проверки use-non-recommended-method на "стандарты разработки"
|
||||
- Использование конструкции "Новый Цвет"
|
||||
|
||||
#### Запросы
|
||||
|
||||
|
23
bundles/com.e1c.v8codestyle.bsl/markdown/new-color.md
Normal file
23
bundles/com.e1c.v8codestyle.bsl/markdown/new-color.md
Normal file
@ -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.<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://support.1ci.com/hc/en-us/articles/4403174580370-5-5-22-Styles-and-style-elements)
|
23
bundles/com.e1c.v8codestyle.bsl/markdown/ru/new-color.md
Normal file
23
bundles/com.e1c.v8codestyle.bsl/markdown/ru/new-color.md
Normal file
@ -0,0 +1,23 @@
|
||||
# Использование конструкции "Новый Цвет"
|
||||
|
||||
Для изменения оформления следует использовать элементы стиля, а не
|
||||
задавать конкретные значения непосредственно в элементах управления.
|
||||
|
||||
## Неправильно
|
||||
|
||||
```bsl
|
||||
Цвет = Новый Цвет(0,0,0); ...
|
||||
```
|
||||
|
||||
## Правильно
|
||||
|
||||
```bsl
|
||||
Цвет = ЦветаСтиля.<Имя элемента стиля>; ...
|
||||
```
|
||||
|
||||
Это требуется для того, чтобы аналогичные элементы управления выглядели
|
||||
одинаково во всех формах, где они встречаются.
|
||||
|
||||
## См.
|
||||
|
||||
- [Элементы стиля](https://its.1c.ru/db/v8std#content:667:hdoc:1)
|
@ -160,6 +160,10 @@
|
||||
category="com.e1c.v8codestyle.bsl"
|
||||
class="com.e1c.v8codestyle.bsl.check.InvocationFormEventHandlerCheck">
|
||||
</check>
|
||||
<check
|
||||
category="com.e1c.v8codestyle.bsl"
|
||||
class="com.e1c.v8codestyle.bsl.check.NewColorCheck">
|
||||
</check>
|
||||
|
||||
</extension>
|
||||
<extension
|
||||
|
@ -102,6 +102,12 @@ final class Messages
|
||||
public static String StructureCtorTooManyKeysCheck_Structure_constructor_has_more_than__0__keys;
|
||||
public static String StructureCtorTooManyKeysCheck_title;
|
||||
|
||||
public static String NewColorCheck_Use_style_elements;
|
||||
|
||||
public static String NewColorCheck_Use_style_elements_not_specific_values;
|
||||
|
||||
public static String NewColorCheck_Using_new_color;
|
||||
|
||||
public static String NstrStringLiteralFormatCheck_Check_empty_interface_for_each_language;
|
||||
|
||||
public static String NstrStringLiteralFormatCheck_description;
|
||||
|
@ -0,0 +1,95 @@
|
||||
/*******************************************************************************
|
||||
* 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.COLOR;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
import com._1c.g5.v8.dt.bsl.model.FunctionStyleCreator;
|
||||
import com._1c.g5.v8.dt.bsl.model.OperatorStyleCreator;
|
||||
import com._1c.g5.v8.dt.mcore.Type;
|
||||
import com._1c.g5.v8.dt.mcore.TypeItem;
|
||||
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 Color.
|
||||
*
|
||||
* @author Artem Iliukhin
|
||||
*/
|
||||
public final class NewColorCheck
|
||||
extends BasicCheck
|
||||
{
|
||||
|
||||
private static final String CHECK_ID = "new-color"; //$NON-NLS-1$
|
||||
|
||||
@Override
|
||||
public String getCheckId()
|
||||
{
|
||||
return CHECK_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureCheck(CheckConfigurer builder)
|
||||
{
|
||||
builder.title(Messages.NewColorCheck_Using_new_color)
|
||||
.description(Messages.NewColorCheck_Use_style_elements_not_specific_values)
|
||||
.complexity(CheckComplexity.NORMAL)
|
||||
.severity(IssueSeverity.MINOR)
|
||||
.issueType(IssueType.WARNING)
|
||||
.extension(new StandardCheckExtension(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)
|
||||
{
|
||||
Type type = ((OperatorStyleCreator)object).getType();
|
||||
addResultAceptor(object, resultAceptor, type);
|
||||
}
|
||||
else if (object instanceof FunctionStyleCreator)
|
||||
{
|
||||
List<TypeItem> 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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 = Описание оповещения на серверную процедуру
|
||||
|
@ -0,0 +1,5 @@
|
||||
Процедура Тест()
|
||||
|
||||
color = new Color(0,0,0);
|
||||
|
||||
КонецПроцедуры
|
@ -0,0 +1,5 @@
|
||||
Процедура Тест()
|
||||
|
||||
color2 = new ("Color");
|
||||
|
||||
КонецПроцедуры
|
@ -0,0 +1,6 @@
|
||||
Процедура Тест()
|
||||
|
||||
name = "Color";
|
||||
color2 = new (name);
|
||||
|
||||
КонецПроцедуры
|
@ -0,0 +1,5 @@
|
||||
Процедура Тест()
|
||||
|
||||
color = new ("Цвет");
|
||||
|
||||
КонецПроцедуры
|
@ -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<Marker> 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<Marker> 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<Marker> markers = getModuleMarkers();
|
||||
assertEquals(0, markers.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNewColor4() throws Exception
|
||||
{
|
||||
updateModule(FOLDER_RESOURCE + "new-color4.bsl");
|
||||
|
||||
List<Marker> markers = getModuleMarkers();
|
||||
assertEquals(1, markers.size());
|
||||
Marker marker = markers.get(0);
|
||||
assertEquals(NEW_COLOR, marker.getMessage());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user