You've already forked v8-code-style
mirror of
https://github.com/1C-Company/v8-code-style.git
synced 2026-05-17 09:31:54 +02:00
add LinkPartSpaceCheck qfix and test
This commit is contained in:
@@ -392,6 +392,9 @@
|
||||
<fix
|
||||
class="com.e1c.v8codestyle.internal.bsl.ui.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.ui.qfix.ServerExecutionSafeModeFix">
|
||||
</fix>
|
||||
<fix
|
||||
class="com.e1c.v8codestyle.internal.bsl.ui.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.ui.qfix.LinkPartSpaceFix">
|
||||
</fix>
|
||||
</extension>
|
||||
<extension
|
||||
point="com._1c.g5.v8.dt.bsl.ui.bslModuleTextInsertInfoService">
|
||||
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2025, 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.ui.qfix;
|
||||
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.text.edits.DeleteEdit;
|
||||
import org.eclipse.text.edits.InsertEdit;
|
||||
import org.eclipse.text.edits.ReplaceEdit;
|
||||
import org.eclipse.text.edits.TextEdit;
|
||||
import org.eclipse.xtext.nodemodel.INode;
|
||||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
|
||||
import com._1c.g5.v8.dt.bsl.model.Method;
|
||||
import com._1c.g5.v8.dt.bsl.model.Module;
|
||||
import com.e1c.g5.v8.dt.bsl.check.qfix.IXtextBslModuleFixModel;
|
||||
import com.e1c.g5.v8.dt.bsl.check.qfix.SingleVariantXtextBslModuleFix;
|
||||
import com.e1c.g5.v8.dt.check.qfix.components.QuickFix;
|
||||
|
||||
/**
|
||||
* Correct format link part
|
||||
*
|
||||
* @author Ivan Sergeev
|
||||
*/
|
||||
@QuickFix(checkId = "link-part-comment-space", supplierId = "com.e1c.v8codestyle.bsl")
|
||||
public class LinkPartSpaceFix
|
||||
extends SingleVariantXtextBslModuleFix
|
||||
{
|
||||
|
||||
@Override
|
||||
protected void configureFix(FixConfigurer configurer)
|
||||
{
|
||||
configurer.interactive(true)
|
||||
.description(Messages.LinkPartSpaceFix_Description)
|
||||
.details(Messages.LinkPartSpaceFix_Details);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TextEdit fixIssue(XtextResource state, IXtextBslModuleFixModel model) throws BadLocationException
|
||||
{
|
||||
int issueOffset = model.getIssue().getOffset();
|
||||
Method method = (Method)model.getElement();
|
||||
EObject eObject = getModule(method);
|
||||
while (!(eObject instanceof Module))
|
||||
{
|
||||
eObject = getModule(eObject);
|
||||
}
|
||||
if (eObject instanceof Module)
|
||||
{
|
||||
INode node = NodeModelUtils.findActualNodeFor(eObject);
|
||||
if (node == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
String editText = node.getText();
|
||||
char checkChar = editText.charAt(issueOffset + 1);
|
||||
|
||||
if (!Character.isLetter(checkChar))
|
||||
{
|
||||
String nextChar = String.valueOf(editText.charAt(issueOffset + 2));
|
||||
if (nextChar.equals(" ")) //$NON-NLS-1$
|
||||
{
|
||||
return new DeleteEdit(issueOffset + 1, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ReplaceEdit(issueOffset + 1, 1, " "); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return new InsertEdit(issueOffset + 1, " "); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private EObject getModule(EObject eObject)
|
||||
{
|
||||
EObject nextContainer = eObject.eContainer();
|
||||
return nextContainer;
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,9 @@ final class Messages
|
||||
public static String SelfAssignFix_Description;
|
||||
public static String SelfAssignFix_Details;
|
||||
|
||||
public static String LinkPartSpaceFix_Description;
|
||||
public static String LinkPartSpaceFix_Details;
|
||||
|
||||
static
|
||||
{
|
||||
// initialize resource bundle
|
||||
|
||||
+2
@@ -29,6 +29,8 @@ SelfAssignFix_Description = Remove self-assign variable
|
||||
SelfAssignFix_Details = Remove self-assign variable
|
||||
ServerExecutionSafeModeFix_description = Enable safe mode
|
||||
ServerExecutionSafeModeFix_details = Insert safe mode enable statement before "Execute" or "Eval" method call
|
||||
LinkPartSpaceFix_Description = Add missing space
|
||||
LinkPartSpaceFix_Details = Add missing space
|
||||
UndefinedMethodFix_func_title=Create function
|
||||
UndefinedMethodFix_func_desc=Create a new function in the module
|
||||
UndefinedMethodFix_proc_title=Create procedure
|
||||
|
||||
+4
@@ -41,6 +41,10 @@ ServerExecutionSafeModeFix_description = Включить безопасный
|
||||
|
||||
ServerExecutionSafeModeFix_details = Добавить включение безопасного режима перед вызовом метода "Выполнить" или "Вычислить"
|
||||
|
||||
LinkPartSpaceFix_Description = Добавить пропущенный пробел
|
||||
|
||||
LinkPartSpaceFix_Details = Добавить пропущенный пробел
|
||||
|
||||
UndefinedMethodFix_func_desc = Создать новую функцию в модуле
|
||||
|
||||
UndefinedMethodFix_func_title = Создать функцию
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
# Space in link part comment
|
||||
|
||||
Missing space before link.
|
||||
|
||||
## Noncompliant Code Example
|
||||
|
||||
//IncorrectLink - SeeCatalogs.Catalog
|
||||
|
||||
## Compliant Solution
|
||||
|
||||
//CorrectLink - See Catalogs.Catalog
|
||||
@@ -0,0 +1,15 @@
|
||||
# Пробел в описании метода перед ссылкой
|
||||
|
||||
Пропущеный пробел перед ссылкой в описании метода коментарием.
|
||||
|
||||
## Неправильно
|
||||
|
||||
Например, неправильно:
|
||||
|
||||
//Неправельная ссылка - См.Справочники.Справочник1
|
||||
|
||||
## Правильно
|
||||
|
||||
Например, правельно:
|
||||
|
||||
//Правельная ссылка - См. Справочники.Справочник1
|
||||
@@ -196,6 +196,10 @@
|
||||
category="com.e1c.v8codestyle.bsl.comment"
|
||||
class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.comment.check.RefLinkPartCheck">
|
||||
</check>
|
||||
<check
|
||||
category="com.e1c.v8codestyle.bsl.comment"
|
||||
class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.comment.check.LinkPartSpaceCheck">
|
||||
</check>
|
||||
<check
|
||||
category="com.e1c.v8codestyle.bsl.comment"
|
||||
class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.comment.check.TypeDefinitionCheck">
|
||||
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2025, 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.comment.check;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.xtext.nodemodel.INode;
|
||||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
||||
import org.eclipse.xtext.scoping.IScopeProvider;
|
||||
|
||||
import com._1c.g5.v8.dt.bsl.documentation.comment.BslDocumentationComment;
|
||||
import com._1c.g5.v8.dt.bsl.documentation.comment.BslDocumentationComment.Description;
|
||||
import com._1c.g5.v8.dt.bsl.documentation.comment.IDescriptionPart;
|
||||
import com._1c.g5.v8.dt.bsl.documentation.comment.LinkPart;
|
||||
import com._1c.g5.v8.dt.bsl.model.Method;
|
||||
import com._1c.g5.v8.dt.core.platform.IBmModelManager;
|
||||
import com._1c.g5.v8.dt.core.platform.IResourceLookup;
|
||||
import com._1c.g5.v8.dt.core.platform.IV8Project;
|
||||
import com._1c.g5.v8.dt.core.platform.IV8ProjectManager;
|
||||
import com.e1c.g5.dt.core.api.naming.INamingService;
|
||||
import com.e1c.g5.dt.core.api.platform.BmOperationContext;
|
||||
import com.e1c.g5.v8.dt.check.CheckComplexity;
|
||||
import com.e1c.g5.v8.dt.check.ICheckParameters;
|
||||
import com.e1c.g5.v8.dt.check.settings.IssueSeverity;
|
||||
import com.e1c.g5.v8.dt.check.settings.IssueType;
|
||||
import com.e1c.v8codestyle.check.CommonSenseCheckExtension;
|
||||
import com.e1c.v8codestyle.internal.bsl.BslPlugin;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* Validates {@link LinkPart} of documentation comment has a space before the link
|
||||
*
|
||||
* @author Ivan Sergeev
|
||||
*/
|
||||
public class LinkPartSpaceCheck
|
||||
extends AbstractDocCommentTypeCheck
|
||||
{
|
||||
private static final String CHECK_ID = "link-part-comment-space"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Instantiates a new reference link part check.
|
||||
*
|
||||
* @param resourceLookup service for look up workspace resources, see {@link IResourceLookup}, cannot be <code>null</code>
|
||||
* @param namingService service for getting names of EDT object and resources, cannot be <code>null</code>
|
||||
* @param bmModelManager service for getting instance of Bm Model by {@link EObject}, cannot be <code>null</code>
|
||||
* @param v8ProjectManager {@link IV8ProjectManager} for getting {@link IV8Project} by {@link EObject}, cannot be <code>null</code>
|
||||
* @param scopeProvider the scope provider service, cannot be {@code null}.
|
||||
*/
|
||||
@Inject
|
||||
public LinkPartSpaceCheck(IResourceLookup resourceLookup, INamingService namingService,
|
||||
IBmModelManager bmModelManager, IV8ProjectManager v8ProjectManager, IScopeProvider scopeProvider)
|
||||
{
|
||||
super(resourceLookup, namingService, bmModelManager, v8ProjectManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCheckId()
|
||||
{
|
||||
return CHECK_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureCheck(CheckConfigurer builder)
|
||||
{
|
||||
builder.title(Messages.LinkPartSpaceCheck_title)
|
||||
.description(Messages.LinkPartSpaceCheck_description)
|
||||
.complexity(CheckComplexity.NORMAL)
|
||||
.severity(IssueSeverity.MINOR)
|
||||
.issueType(IssueType.CODE_STYLE)
|
||||
.extension(new CommonSenseCheckExtension(getCheckId(), BslPlugin.PLUGIN_ID))
|
||||
.delegate(LinkPart.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkDocumentationCommentObject(IDescriptionPart object, BslDocumentationComment root,
|
||||
DocumentationCommentResultAcceptor resultAceptor, ICheckParameters parameters,
|
||||
BmOperationContext typeComputationContext, IProgressMonitor monitor)
|
||||
{
|
||||
LinkPart linkPart = (LinkPart)object;
|
||||
|
||||
if (object.getParent() instanceof Description)
|
||||
{
|
||||
String checkString = linkPart.getInitialContent();
|
||||
String stringLink = linkPart.getLinkText();
|
||||
Method method = root.getMethod();
|
||||
INode node = NodeModelUtils.findActualNodeFor(method);
|
||||
if (node == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (checkString.toLowerCase().indexOf("См.".toLowerCase()) != -1 //$NON-NLS-1$
|
||||
|| checkString.toLowerCase().indexOf("See".toLowerCase()) != -1) //$NON-NLS-1$
|
||||
{
|
||||
String textMethod = node.getText();
|
||||
int indexCheckChar = textMethod.indexOf(checkString);
|
||||
int indexLinkText = checkString.indexOf(stringLink);
|
||||
char checkChar = checkString.charAt(indexLinkText - 1);
|
||||
char checkPrevChar = textMethod.charAt(indexCheckChar - 1);
|
||||
if (!String.valueOf(checkChar).equals(" ") //$NON-NLS-1$
|
||||
&& !Character.isLetter(checkPrevChar))
|
||||
{
|
||||
if (stringLink.equals(":") || stringLink.equals("_")) //$NON-NLS-1$ //$NON-NLS-2$
|
||||
{
|
||||
resultAceptor.addIssue(Messages.LinkPartSpaceCheck_issueColon, linkPart.getLineNumber(),
|
||||
linkPart.getLinkTextOffset() - 1, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
resultAceptor.addIssue(Messages.LinkPartSpaceCheck_issue, linkPart.getLineNumber(),
|
||||
linkPart.getLinkTextOffset() - 1, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
@@ -73,6 +73,10 @@ final class Messages
|
||||
public static String RefLinkPartCheck_description;
|
||||
public static String RefLinkPartCheck_Link_referenced_to_unexisting_object;
|
||||
public static String RefLinkPartCheck_title;
|
||||
public static String LinkPartSpaceCheck_description;
|
||||
public static String LinkPartSpaceCheck_issue;
|
||||
public static String LinkPartSpaceCheck_title;
|
||||
public static String LinkPartSpaceCheck_issueColon;
|
||||
public static String TypeDefinitionCheck_description;
|
||||
public static String TypeDefinitionCheck_title;
|
||||
public static String TypeDefinitionCheck_Unkown_type_M_specified;
|
||||
|
||||
+8
@@ -114,6 +114,14 @@ RefLinkPartCheck_description = Documentation comment link referenced object exis
|
||||
|
||||
RefLinkPartCheck_title = Documentation comment link referenced object exist
|
||||
|
||||
LinkPartSpaceCheck_description = Check for space after 'See' before link
|
||||
|
||||
LinkPartSpaceCheck_title = Check for space after 'See' before link
|
||||
|
||||
LinkPartSpaceCheck_issue = There is a space missing after 'See' before the link
|
||||
|
||||
LinkPartSpaceCheck_issueColon = There is extra colon before the link
|
||||
|
||||
TypeDefinitionCheck_Unkown_type_M_specified = Unknown type "{0}" specified in documentation comment
|
||||
|
||||
TypeDefinitionCheck_description = Documentation comment type definition contains valid type name
|
||||
|
||||
+8
@@ -114,6 +114,14 @@ RefLinkPartCheck_description = Ссылка документирующего к
|
||||
|
||||
RefLinkPartCheck_title = Ссылка документирующего комментария на существующий объект
|
||||
|
||||
LinkPartSpaceCheck_description = Проверка наличия пробела после 'См.' перед ссылкой
|
||||
|
||||
LinkPartSpaceCheck_title = Проверка наличия пробела после 'См.' перед ссылкой
|
||||
|
||||
LinkPartSpaceCheck_issue = Отсутствует пробел после 'См.' перед ссылкой
|
||||
|
||||
LinkPartSpaceCheck_issueColon = Лишнее двоеточие перед ссылкой
|
||||
|
||||
TypeDefinitionCheck_Unkown_type_M_specified = Неизвестный тип "{0}" указан в документирующем комментарии
|
||||
|
||||
TypeDefinitionCheck_description = Определение типа документирующего комментария содержит правильное имя типа
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#Region Abcd
|
||||
|
||||
//CorrectLink - See Catalog.Catalog1
|
||||
//IncorrectLink - SeeCatalog.Catalog1
|
||||
Procedure Test()
|
||||
|
||||
EndProcedure
|
||||
|
||||
#EndRegion
|
||||
@@ -0,0 +1,9 @@
|
||||
#Region Abcd
|
||||
|
||||
//IncorrectLink - SeeCatalog.Catalog1
|
||||
//CorrectLink - See Catalog.Catalog1
|
||||
Procedure Test()
|
||||
|
||||
EndProcedure
|
||||
|
||||
#EndRegion
|
||||
@@ -0,0 +1,8 @@
|
||||
#Region Abcd
|
||||
|
||||
//IncorrectLink - SeeCatalog.Catalog1
|
||||
Procedure Test()
|
||||
|
||||
EndProcedure
|
||||
|
||||
#EndRegion
|
||||
@@ -0,0 +1,8 @@
|
||||
#Region Abcd
|
||||
|
||||
//CorrectLink - See Catalog.Catalog1
|
||||
Procedure Test()
|
||||
|
||||
EndProcedure
|
||||
|
||||
#EndRegion
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2025, 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.comment.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.Marker;
|
||||
import com._1c.g5.v8.dt.validation.marker.StandardExtraInfo;
|
||||
import com.e1c.v8codestyle.bsl.check.itests.AbstractSingleModuleTestBase;
|
||||
import com.e1c.v8codestyle.bsl.comment.check.LinkPartSpaceCheck;
|
||||
|
||||
/**
|
||||
* Tests for {@link LinkPartSpaceCheck} check.
|
||||
*
|
||||
* @author Ivan Sergeev
|
||||
*/
|
||||
public class LinkPartSpaceCheckTest
|
||||
extends AbstractSingleModuleTestBase
|
||||
{
|
||||
private static final String PROJECT_NAME = "EventHandlerBooleanParam";
|
||||
|
||||
private static final String MODULE_FILE_NAME = "/src/Catalogs/Products/ManagerModule.bsl";
|
||||
|
||||
public LinkPartSpaceCheckTest()
|
||||
{
|
||||
super(LinkPartSpaceCheck.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean enableCleanUp()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestConfigurationName()
|
||||
{
|
||||
return PROJECT_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getModuleFileName()
|
||||
{
|
||||
return MODULE_FILE_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test incorrect link.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void testIncorrectLink() throws Exception
|
||||
{
|
||||
updateModule(FOLDER_RESOURCE + "space-missing-link-part.bsl");
|
||||
|
||||
List<Marker> markers = getModuleMarkers();
|
||||
assertEquals(1, markers.size());
|
||||
Marker marker = markers.get(0);
|
||||
assertEquals(Integer.valueOf(3), marker.getExtraInfo().get(StandardExtraInfo.TEXT_LINE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test incorrect link after another link.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void testLinkAfter() throws Exception
|
||||
{
|
||||
updateModule(FOLDER_RESOURCE + "space-missing-link-part-after.bsl");
|
||||
|
||||
List<Marker> markers = getModuleMarkers();
|
||||
assertEquals(1, markers.size());
|
||||
Marker marker = markers.get(0);
|
||||
assertEquals(Integer.valueOf(4), marker.getExtraInfo().get(StandardExtraInfo.TEXT_LINE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test incorrect link before another link
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void testLinkBefore() throws Exception
|
||||
{
|
||||
updateModule(FOLDER_RESOURCE + "space-missing-link-part-before.bsl");
|
||||
|
||||
List<Marker> markers = getModuleMarkers();
|
||||
assertEquals(1, markers.size());
|
||||
Marker marker = markers.get(0);
|
||||
assertEquals(Integer.valueOf(3), marker.getExtraInfo().get(StandardExtraInfo.TEXT_LINE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test correct link.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void testCorrectLink() throws Exception
|
||||
{
|
||||
updateModule(FOLDER_RESOURCE + "space-non-missing-link-part.bsl");
|
||||
|
||||
List<Marker> markers = getModuleMarkers();
|
||||
assertTrue(markers.isEmpty());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user