From af70b065af1e177f89c9c2bfe21acaef77df88ed Mon Sep 17 00:00:00 2001 From: atai1 Date: Fri, 2 Aug 2019 19:10:24 +0300 Subject: [PATCH 1/7] =?UTF-8?q?=D0=94=D0=B8=D0=B0=D0=B3=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B8=D0=BA=D0=B0=20=D0=BD=D0=B5=20=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=B0=D0=B5=D1=82.=20=D0=9E=D1=82=D0=BA=D0=B0?= =?UTF-8?q?=D1=82=D1=8B=D0=B2=D0=B0=D1=8E=D1=81=D1=8C=20=D0=BA=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B2=D0=BE=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=BE=D0=BC=D1=83=20=D1=81=D0=BE=D1=81=D1=82=D0=BE=D1=8F?= =?UTF-8?q?=D0=BD=D0=B8=D1=8E=20=D1=85=D1=80=D0=B0=D0=BD=D0=B8=D0=BB=D0=B8?= =?UTF-8?q?=D1=89=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/diagnostics/YodaStyle.md | 15 +++++ docs/en/diagnostics/YodaStyle.md | 15 +++++ .../diagnostics/YodaStyleDiagnostic.java | 58 +++++++++++++++++++ .../YodaStyleDiagnostic_en.properties | 2 + .../YodaStyleDiagnostic_ru.properties | 2 + .../diagnostics/YodaStyleDiagnosticTest.java | 47 +++++++++++++++ .../diagnostics/YodaStyleDiagnostic.bsl | 7 +++ 7 files changed, 146 insertions(+) create mode 100644 docs/diagnostics/YodaStyle.md create mode 100644 docs/en/diagnostics/YodaStyle.md create mode 100644 src/main/java/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic.java create mode 100644 src/main/resources/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic_en.properties create mode 100644 src/main/resources/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic_ru.properties create mode 100644 src/test/java/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnosticTest.java create mode 100644 src/test/resources/diagnostics/YodaStyleDiagnostic.bsl diff --git a/docs/diagnostics/YodaStyle.md b/docs/diagnostics/YodaStyle.md new file mode 100644 index 00000000000..988ab427045 --- /dev/null +++ b/docs/diagnostics/YodaStyle.md @@ -0,0 +1,15 @@ +# В операциях сравнения переменная должна быть слева от оператора, значение должно быть справа + +Переменным значения присваивая помни: переменные слева быть должны (С) Yoda + +Плохо: +```BSL +Если 0 = Сумма Тогда +``` + +Хорошо: +```BSL +Если Сумма = 0 Тогда +``` + +[Источник wikipedia](https://ru.wikipedia.org/wiki/%D0%A3%D1%81%D0%BB%D0%BE%D0%B2%D0%B8%D1%8F_%D0%99%D0%BE%D0%B4%D1%8B) \ No newline at end of file diff --git a/docs/en/diagnostics/YodaStyle.md b/docs/en/diagnostics/YodaStyle.md new file mode 100644 index 00000000000..8c098f0f007 --- /dev/null +++ b/docs/en/diagnostics/YodaStyle.md @@ -0,0 +1,15 @@ +# In comparison operations, the variable must be to the left of the operator, the value must be to the right + +Assigning values to variables, remember: the variables on the left should be (С) Yoda + +Bad: +```BSL +If 0 = Summ Then +``` + +Good: +```BSL +If Summ = 0 Then +``` + +[Source](https://www.united-coders.com/christian-harms/what-are-yoda-conditions/) \ No newline at end of file diff --git a/src/main/java/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic.java b/src/main/java/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic.java new file mode 100644 index 00000000000..cd961b04470 --- /dev/null +++ b/src/main/java/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic.java @@ -0,0 +1,58 @@ +/* + * This file is a part of BSL Language Server. + * + * Copyright © 2018-2019 + * Alexey Sosnoviy , Nikita Gryzlov and contributors + * + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * BSL Language Server is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * BSL Language Server is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with BSL Language Server. + */ +package org.github._1c_syntax.bsl.languageserver.diagnostics; + +import org.antlr.v4.runtime.Token; +import org.eclipse.lsp4j.Diagnostic; +import org.github._1c_syntax.bsl.languageserver.context.DocumentContext; +import org.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticMetadata; +import org.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticSeverity; +import org.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticScope; +import org.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticType; +import org.github._1c_syntax.bsl.languageserver.utils.RangeHelper; +import org.github._1c_syntax.bsl.parser.BSLParser; +import org.github._1c_syntax.bsl.parser.BSLLexer; +import org.antlr.v4.runtime.tree.ParseTree; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.stream.Collectors; + +@DiagnosticMetadata( + type = DiagnosticType.CODE_SMELL, + scope = DiagnosticScope.BSL, + severity = DiagnosticSeverity.MINOR, + minutesToFix = 2 +) +public class YodaStyleDiagnostic extends AbstractVisitorDiagnostic{ + + @Override + public ParseTree visitIfStatement(BSLParser.IfStatementContext ctx) { + + if (ctx.getToken(BSLLexer.ELSIF_KEYWORD, 0) != null && ctx.getToken(BSLLexer.ELSE_KEYWORD, 0) == null) { + diagnosticStorage.addDiagnostic(ctx.getStop()); + } + + return super.visitIfStatement(ctx); + } +} diff --git a/src/main/resources/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic_en.properties b/src/main/resources/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic_en.properties new file mode 100644 index 00000000000..29a2d38294a --- /dev/null +++ b/src/main/resources/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic_en.properties @@ -0,0 +1,2 @@ +diagnosticMessage=The Yoda style is not allowed in the texts of the modules. +diagnosticName=Using Yoda style in code \ No newline at end of file diff --git a/src/main/resources/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic_ru.properties b/src/main/resources/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic_ru.properties new file mode 100644 index 00000000000..79b46e65631 --- /dev/null +++ b/src/main/resources/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic_ru.properties @@ -0,0 +1,2 @@ +diagnosticMessage= , , . +diagnosticName= yoda style \ No newline at end of file diff --git a/src/test/java/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnosticTest.java b/src/test/java/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnosticTest.java new file mode 100644 index 00000000000..1a55efc22fd --- /dev/null +++ b/src/test/java/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnosticTest.java @@ -0,0 +1,47 @@ +/* + * This file is a part of BSL Language Server. + * + * Copyright © 2018-2019 + * Alexey Sosnoviy , Nikita Gryzlov and contributors + * + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * BSL Language Server is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * BSL Language Server is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with BSL Language Server. + */ +package org.github._1c_syntax.bsl.languageserver.diagnostics; + +import org.eclipse.lsp4j.Diagnostic; +import org.github._1c_syntax.bsl.languageserver.utils.RangeHelper; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +class YodaStyleDiagnosticTest extends AbstractDiagnosticTest { + + YodaStyleDiagnosticTest() { + super(YodaStyleDiagnostic.class); + } + + @Test + void test() { + // when + List diagnostics = getDiagnostics(); + // then + assertThat(diagnostics).hasSize(1); + assertThat(diagnostics) + .anyMatch(diagnostic -> diagnostic.getRange().equals(RangeHelper.newRange(1, 8 , 1, 27))); + } +} diff --git a/src/test/resources/diagnostics/YodaStyleDiagnostic.bsl b/src/test/resources/diagnostics/YodaStyleDiagnostic.bsl new file mode 100644 index 00000000000..9a1a043e3ab --- /dev/null +++ b/src/test/resources/diagnostics/YodaStyleDiagnostic.bsl @@ -0,0 +1,7 @@ + // Выражение с ошибкой + Если 100 = ЙодаГоворит Тогда + КонецЕсли; + + // Корректное выражение + Если ЙодаГоворит = 100 Тогда + КонецЕсли; \ No newline at end of file From 0f856c28d475851bfd56591cb476998f11059eb9 Mon Sep 17 00:00:00 2001 From: atai1 Date: Fri, 2 Aug 2019 23:52:53 +0300 Subject: [PATCH 2/7] =?UTF-8?q?=D0=91=D0=B8=D0=BB=D0=B4=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D1=85=D0=BE=D0=B4=D0=B8=D1=82,=20=D0=BD=D0=BE=20=D1=82?= =?UTF-8?q?=D0=B5=D1=81=D1=82=20=D0=B4=D0=B8=D0=B0=D0=B3=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B8=D0=BA=D0=B8=20=D1=84=D0=B5=D0=B9=D0=BB=D0=B8=D1=82?= =?UTF-8?q?=D1=81=D1=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../diagnostics/YodaStyleDiagnostic.java | 30 +++++++------- .../diagnostics/YodaStyleDiagnosticTest.java | 8 +++- .../diagnostics/YodaStyleDiagnostic.bsl | 40 ++++++++++++++++--- 3 files changed, 54 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic.java b/src/main/java/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic.java index cd961b04470..54b6d00969a 100644 --- a/src/main/java/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic.java +++ b/src/main/java/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic.java @@ -21,22 +21,14 @@ */ package org.github._1c_syntax.bsl.languageserver.diagnostics; -import org.antlr.v4.runtime.Token; -import org.eclipse.lsp4j.Diagnostic; -import org.github._1c_syntax.bsl.languageserver.context.DocumentContext; +import org.antlr.v4.runtime.tree.ParseTree; import org.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticMetadata; -import org.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticSeverity; import org.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticScope; +import org.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticSeverity; import org.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticType; -import org.github._1c_syntax.bsl.languageserver.utils.RangeHelper; import org.github._1c_syntax.bsl.parser.BSLParser; -import org.github._1c_syntax.bsl.parser.BSLLexer; -import org.antlr.v4.runtime.tree.ParseTree; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.stream.Collectors; +import java.util.regex.Pattern; @DiagnosticMetadata( type = DiagnosticType.CODE_SMELL, @@ -44,15 +36,21 @@ severity = DiagnosticSeverity.MINOR, minutesToFix = 2 ) -public class YodaStyleDiagnostic extends AbstractVisitorDiagnostic{ + +public class YodaStyleDiagnostic extends AbstractVisitorDiagnostic { + private static final Pattern messagePattern = Pattern.compile( + "(Если|if)\\s+([\\d]|\\\")(.)*\\=(.)(?!\\\"|\\d)", + Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE + ); @Override - public ParseTree visitIfStatement(BSLParser.IfStatementContext ctx) { + public ParseTree visitGlobalMethodCall(BSLParser.GlobalMethodCallContext ctx) { - if (ctx.getToken(BSLLexer.ELSIF_KEYWORD, 0) != null && ctx.getToken(BSLLexer.ELSE_KEYWORD, 0) == null) { - diagnosticStorage.addDiagnostic(ctx.getStop()); + if (messagePattern.matcher(ctx.methodName().getText()).matches()) { + diagnosticStorage.addDiagnostic(ctx); } - return super.visitIfStatement(ctx); + return super.visitGlobalMethodCall(ctx); } + } diff --git a/src/test/java/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnosticTest.java b/src/test/java/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnosticTest.java index 1a55efc22fd..f79f613a1ee 100644 --- a/src/test/java/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnosticTest.java +++ b/src/test/java/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnosticTest.java @@ -40,8 +40,12 @@ void test() { // when List diagnostics = getDiagnostics(); // then - assertThat(diagnostics).hasSize(1); + assertThat(diagnostics).hasSize(3); assertThat(diagnostics) - .anyMatch(diagnostic -> diagnostic.getRange().equals(RangeHelper.newRange(1, 8 , 1, 27))); + .anyMatch(diagnostic -> diagnostic.getRange().equals(RangeHelper.newRange(3, 0 , 3, 23))); + assertThat(diagnostics) + .anyMatch(diagnostic -> diagnostic.getRange().equals(RangeHelper.newRange(9, 0 , 9, 28))); + assertThat(diagnostics) + .anyMatch(diagnostic -> diagnostic.getRange().equals(RangeHelper.newRange(13, 0 , 13, 32))); } } diff --git a/src/test/resources/diagnostics/YodaStyleDiagnostic.bsl b/src/test/resources/diagnostics/YodaStyleDiagnostic.bsl index 9a1a043e3ab..7dcdfe1d56c 100644 --- a/src/test/resources/diagnostics/YodaStyleDiagnostic.bsl +++ b/src/test/resources/diagnostics/YodaStyleDiagnostic.bsl @@ -1,7 +1,35 @@ - // Выражение с ошибкой - Если 100 = ЙодаГоворит Тогда - КонецЕсли; +Процедура А() - // Корректное выражение - Если ЙодаГоворит = 100 Тогда - КонецЕсли; \ No newline at end of file +// Выражение с ошибкой +Если 100 = ЙодаГоворит Тогда +КонецЕсли; + +// Выражение с ошибкой +Если 100 + 10 = ЙодаГоворит Тогда +КонецЕсли; + +// Выражение с ошибкой +Если "МолчитИода" = ЙодаГоворит Тогда +КонецЕсли; + +// Корректное выражение +Если "МолчитИода" = "МолчитИода" Тогда +КонецЕсли; + +// Корректное выражение +Если 100 = 100 Тогда +КонецЕсли; + +// Корректное выражение +Если ЙодаГоворит = 100 Тогда +КонецЕсли; + +// Выражение с ошибкой +Если ЙодаГоворит = 100 + 10 Тогда +КонецЕсли; + +// Выражение с ошибкой +Если ЙодаГоворит = "МолчитИода" Тогда +КонецЕсли; + +КонецПроцедуры; \ No newline at end of file From cf2af9aa1a075c8db0fc0494ac8669734e1452d2 Mon Sep 17 00:00:00 2001 From: atai1 Date: Sat, 3 Aug 2019 10:38:08 +0300 Subject: [PATCH 3/7] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BE=D0=BF=D0=B5=D1=87=D0=B0=D1=82=D0=BA=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/diagnostics/YodaStyle.md | 2 +- docs/en/diagnostics/YodaStyle.md | 2 +- .../resources/diagnostics/YodaStyleDiagnostic.bsl | 12 ++---------- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/docs/diagnostics/YodaStyle.md b/docs/diagnostics/YodaStyle.md index 988ab427045..c11b4cd6ac6 100644 --- a/docs/diagnostics/YodaStyle.md +++ b/docs/diagnostics/YodaStyle.md @@ -1,6 +1,6 @@ # В операциях сравнения переменная должна быть слева от оператора, значение должно быть справа -Переменным значения присваивая помни: переменные слева быть должны (С) Yoda +Сравнивая значения и переменные помни: переменные слева быть должны (С) Yoda Плохо: ```BSL diff --git a/docs/en/diagnostics/YodaStyle.md b/docs/en/diagnostics/YodaStyle.md index 8c098f0f007..babe0f1b8c3 100644 --- a/docs/en/diagnostics/YodaStyle.md +++ b/docs/en/diagnostics/YodaStyle.md @@ -1,6 +1,6 @@ # In comparison operations, the variable must be to the left of the operator, the value must be to the right -Assigning values to variables, remember: the variables on the left should be (С) Yoda +Compare values and variables, remember: the variables on the left should be (С) Yoda Bad: ```BSL diff --git a/src/test/resources/diagnostics/YodaStyleDiagnostic.bsl b/src/test/resources/diagnostics/YodaStyleDiagnostic.bsl index 7dcdfe1d56c..9a73e72f241 100644 --- a/src/test/resources/diagnostics/YodaStyleDiagnostic.bsl +++ b/src/test/resources/diagnostics/YodaStyleDiagnostic.bsl @@ -12,23 +12,15 @@ Если "МолчитИода" = ЙодаГоворит Тогда КонецЕсли; -// Корректное выражение -Если "МолчитИода" = "МолчитИода" Тогда -КонецЕсли; - -// Корректное выражение -Если 100 = 100 Тогда -КонецЕсли; - // Корректное выражение Если ЙодаГоворит = 100 Тогда КонецЕсли; -// Выражение с ошибкой +// Корректное выражение Если ЙодаГоворит = 100 + 10 Тогда КонецЕсли; -// Выражение с ошибкой +// Корректное выражение Если ЙодаГоворит = "МолчитИода" Тогда КонецЕсли; From cdc4a0cdf2cabc842c6d7eeff8dbdd405c910e91 Mon Sep 17 00:00:00 2001 From: atai1 Date: Sat, 3 Aug 2019 22:01:44 +0300 Subject: [PATCH 4/7] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D1=8F?= =?UTF-8?q?=D1=8E=20=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B9=D0=BA=D0=B8?= =?UTF-8?q?=20=D1=81=D0=B0=D0=B9=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/index.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/index.md b/docs/index.md index 498af3a715e..1761b82cfd1 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,3 +1,8 @@ +--- +title: Home +layout: post +--- + # BSL Language Server [![Build Status](https://travis-ci.org/1c-syntax/bsl-language-server.svg?branch=master)](https://travis-ci.org/1c-syntax/bsl-language-server) From a37a67cb8c023147055b13923d0aeb3718ed797c Mon Sep 17 00:00:00 2001 From: lab Date: Wed, 6 Nov 2019 16:49:15 +0300 Subject: [PATCH 5/7] =?UTF-8?q?=D0=9E=D1=82=D0=BA=D0=B0=D1=82=20index.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/index.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/docs/index.md b/docs/index.md index 1761b82cfd1..498af3a715e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,8 +1,3 @@ ---- -title: Home -layout: post ---- - # BSL Language Server [![Build Status](https://travis-ci.org/1c-syntax/bsl-language-server.svg?branch=master)](https://travis-ci.org/1c-syntax/bsl-language-server) From e45956c841ff8c53f8d1b2e805e2c8734c9714df Mon Sep 17 00:00:00 2001 From: lab Date: Wed, 6 Nov 2019 17:06:36 +0300 Subject: [PATCH 6/7] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B2=D0=BE=D0=B4?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B5=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../diagnostics/YodaStyleDiagnostic.java | 20 ++++++++++--------- .../YodaStyleDiagnostic_en.properties | 0 .../YodaStyleDiagnostic_ru.properties | 0 .../diagnostics/YodaStyleDiagnosticTest.java | 15 ++++++-------- 4 files changed, 17 insertions(+), 18 deletions(-) rename src/main/java/{org => com}/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic.java (76%) rename src/main/resources/{org => com}/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic_en.properties (100%) rename src/main/resources/{org => com}/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic_ru.properties (100%) rename src/test/java/{org => com}/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnosticTest.java (69%) diff --git a/src/main/java/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic.java b/src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic.java similarity index 76% rename from src/main/java/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic.java rename to src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic.java index 54b6d00969a..216a020b399 100644 --- a/src/main/java/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic.java +++ b/src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic.java @@ -19,22 +19,24 @@ * You should have received a copy of the GNU Lesser General Public * License along with BSL Language Server. */ -package org.github._1c_syntax.bsl.languageserver.diagnostics; - +package com.github._1c_syntax.bsl.languageserver.diagnostics; + +import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticMetadata; +import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticScope; +import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticSeverity; +import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticTag; +import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticType; +import com.github._1c_syntax.bsl.parser.BSLParser; import org.antlr.v4.runtime.tree.ParseTree; -import org.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticMetadata; -import org.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticScope; -import org.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticSeverity; -import org.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticType; -import org.github._1c_syntax.bsl.parser.BSLParser; import java.util.regex.Pattern; @DiagnosticMetadata( type = DiagnosticType.CODE_SMELL, - scope = DiagnosticScope.BSL, severity = DiagnosticSeverity.MINOR, - minutesToFix = 2 + scope = DiagnosticScope.BSL, + minutesToFix = 1, + tags = {DiagnosticTag.BRAINOVERLOAD} ) public class YodaStyleDiagnostic extends AbstractVisitorDiagnostic { diff --git a/src/main/resources/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic_en.properties b/src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic_en.properties similarity index 100% rename from src/main/resources/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic_en.properties rename to src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic_en.properties diff --git a/src/main/resources/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic_ru.properties b/src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic_ru.properties similarity index 100% rename from src/main/resources/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic_ru.properties rename to src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic_ru.properties diff --git a/src/test/java/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnosticTest.java b/src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnosticTest.java similarity index 69% rename from src/test/java/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnosticTest.java rename to src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnosticTest.java index f79f613a1ee..2527c4c84c6 100644 --- a/src/test/java/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnosticTest.java +++ b/src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnosticTest.java @@ -19,15 +19,14 @@ * You should have received a copy of the GNU Lesser General Public * License along with BSL Language Server. */ -package org.github._1c_syntax.bsl.languageserver.diagnostics; +package com.github._1c_syntax.bsl.languageserver.diagnostics; import org.eclipse.lsp4j.Diagnostic; -import org.github._1c_syntax.bsl.languageserver.utils.RangeHelper; import org.junit.jupiter.api.Test; import java.util.List; -import static org.assertj.core.api.Assertions.assertThat; +import static com.github._1c_syntax.bsl.languageserver.util.Assertions.assertThat; class YodaStyleDiagnosticTest extends AbstractDiagnosticTest { @@ -41,11 +40,9 @@ void test() { List diagnostics = getDiagnostics(); // then assertThat(diagnostics).hasSize(3); - assertThat(diagnostics) - .anyMatch(diagnostic -> diagnostic.getRange().equals(RangeHelper.newRange(3, 0 , 3, 23))); - assertThat(diagnostics) - .anyMatch(diagnostic -> diagnostic.getRange().equals(RangeHelper.newRange(9, 0 , 9, 28))); - assertThat(diagnostics) - .anyMatch(diagnostic -> diagnostic.getRange().equals(RangeHelper.newRange(13, 0 , 13, 32))); + assertThat(diagnostics, true) + .hasRange(3, 0, 3, 23) + .hasRange(9, 0, 9, 28) + .hasRange(13, 0, 13, 32); } } From 05b3913b79811a2defed765085094faf0edcccc4 Mon Sep 17 00:00:00 2001 From: lab Date: Fri, 8 Nov 2019 08:22:34 +0300 Subject: [PATCH 7/7] visitIfBranch --- .../languageserver/diagnostics/YodaStyleDiagnostic.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic.java b/src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic.java index 216a020b399..6af688af0f2 100644 --- a/src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic.java +++ b/src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic.java @@ -46,13 +46,14 @@ public class YodaStyleDiagnostic extends AbstractVisitorDiagnostic { ); @Override - public ParseTree visitGlobalMethodCall(BSLParser.GlobalMethodCallContext ctx) { + public ParseTree visitIfBranch(BSLParser.IfBranchContext ctx) { - if (messagePattern.matcher(ctx.methodName().getText()).matches()) { + + if (messagePattern.matcher(ctx.getText()).matches()) { diagnosticStorage.addDiagnostic(ctx); } - return super.visitGlobalMethodCall(ctx); + return super.visitIfBranch(ctx); } }