From 6612fa5e1b63ddc6c8cf20ce5f81627d50de6386 Mon Sep 17 00:00:00 2001 From: atai1 Date: Thu, 1 Aug 2019 09:25:05 +0300 Subject: [PATCH 1/8] =?UTF-8?q?=D0=9D=D0=B5=D0=BC=D0=BD=D0=BE=D0=B3=D0=BE?= =?UTF-8?q?=20=D1=83=D0=BF=D0=BE=D1=80=D1=8F=D0=B4=D0=BE=D1=87=D0=B8=D0=BB?= =?UTF-8?q?=20=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B8=20=D0=B2=20=D0=B3=D0=B8?= =?UTF-8?q?=D1=82=D0=B8=D0=B3=D0=BD=D0=BE=D1=80.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 128 +++++++++++++++++++++++---------------------- .idea/compiler.xml | 2 + 2 files changed, 67 insertions(+), 63 deletions(-) diff --git a/.gitignore b/.gitignore index 0e9e4c005a6..3bd29799d88 100644 --- a/.gitignore +++ b/.gitignore @@ -1,63 +1,65 @@ -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/**/usage.statistics.xml -.idea/**/dictionaries -.idea/**/shelf - -# Generated files -.idea/**/contentModel.xml - -# Sensitive or high-churn files -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml -.idea/**/dbnavigator.xml - -# Gradle -.idea/**/gradle.xml -.idea/**/libraries - -# Gradle and Maven with auto-import -# When using Gradle or Maven with auto-import, you should exclude module files, -# since they will be recreated, and may cause churn. Uncomment if using -# auto-import. -.idea/modules.xml -.idea/*.iml -.idea/modules - -# IntelliJ -out/ - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties - -# Editor-based Rest Client -.idea/httpRequests - -.gradle/ -*.zip -*.ps1 -target/ -build/ - -# Scala compiler user settings -.idea/hydra.xml - -.idea/sonarlint/ - -intellij-bsl/src/test/resources/parser/.idea/ - -gen/ - -.idea/sonarlint-state.xml -.idea/sonarlint.xml +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +.idea/modules.xml +.idea/*.iml +.idea/modules + +# IntelliJ +out/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Scala compiler user settings +.idea/hydra.xml + +# Sonar configuration +.idea/sonarlint/ +.idea/sonarlint-state.xml +.idea/sonarlint.xml + +# Archive files +*.zip +*.ps1 + +# Other folder +intellij-bsl/src/test/resources/parser/.idea/ +gen/ +target/ +build/ +gradle/ + diff --git a/.idea/compiler.xml b/.idea/compiler.xml index d56e18d2bc5..ebbf0621394 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -5,6 +5,8 @@ + + From a1032d3c9e2323fbb44fc8d07bb811f6e3ac23ae Mon Sep 17 00:00:00 2001 From: atai1 Date: Thu, 1 Aug 2019 09:29:02 +0300 Subject: [PATCH 2/8] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20=D0=B4?= =?UTF-8?q?=D0=BB=D0=B8=D0=BD=D0=BD=D1=83=D1=8E=20=D1=81=D1=82=D1=80=D0=BE?= =?UTF-8?q?=D1=87=D0=BA=D1=83=20=D0=B2=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B5.?= =?UTF-8?q?=20=D0=9A=D0=B0=D0=B6=D0=B5=D1=82=D1=81=D1=8F=20=D1=82=D0=B0?= =?UTF-8?q?=D0=BA=20=D1=87=D0=B8=D1=82=D0=B0=D1=82=D1=8C=20=D0=BB=D0=B5?= =?UTF-8?q?=D0=B3=D1=87=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CONTRIBUTING.md | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 598873e20ee..f3915ffaf2c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,14 +1,19 @@ -# Руководство контрибьютора - -## Требования к окружению - -* Java Development Kit 8 -* IntelliJ IDEA Community Edition -* Lombok Plugin к IntelliJ IDEA -* EditorConfig Plugin к IntelliJ IDEA - -## Настройка IntelliJ IDEA - -* Java SDK на JDK8 -* File | Settings | Build, Execution, Deployment | Compiler | Annotation Processors | Enable annotation processing - checked - +# Руководство контрибьютора + +## Требования к окружению + +* Java Development Kit 8 +* IntelliJ IDEA Community Edition +* Lombok Plugin к IntelliJ IDEA +* EditorConfig Plugin к IntelliJ IDEA + +## Настройка IntelliJ IDEA + +* Java SDK на JDK8 +* File + * Settings + * Build, Execution, Deployment + * Compiler + * Annotation Processors + * Enable annotation processing - checked + From 5784a8a308dbb260754f2775b4c2410fddc9c7c7 Mon Sep 17 00:00:00 2001 From: atai1 Date: Thu, 1 Aug 2019 09:48:13 +0300 Subject: [PATCH 3/8] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=20=D1=81=D1=81=D1=8B=D0=BB=D0=BA=D1=83=20=D0=BD=D0=B0=20=D0=B8?= =?UTF-8?q?=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=86=D0=B8=D1=8E=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8E=20=D0=B4=D0=B8=D0=B0=D0=B3=D0=BD=D0=BE=D1=81=D1=82=D0=B8?= =?UTF-8?q?=D0=BA=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CONTRIBUTING.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f3915ffaf2c..1ce364f2896 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,3 +17,6 @@ * Annotation Processors * Enable annotation processing - checked +## Добавление диагностики + +Пример добавления диагностики в [WIKI проекта](https://github.com/1c-syntax/bsl-language-server/wiki/%D0%94%D0%BE%D0%B1%D0%B0%D0%B2%D0%BB%D0%B5%D0%BD%D0%B8%D0%B5-%D0%B4%D0%B8%D0%B0%D0%B3%D0%BD%D0%BE%D1%81%D1%82%D0%B8%D0%BA%D0%B8) From 791d29f1e1a242ca30f032098ac9aad37cb13551 Mon Sep 17 00:00:00 2001 From: atai1 Date: Fri, 2 Aug 2019 00:12:49 +0300 Subject: [PATCH 4/8] =?UTF-8?q?=D0=A4=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B.=20=D0=94?= =?UTF-8?q?=D0=B8=D0=B0=D0=B3=D0=BD=D0=BE=D1=81=D1=82=D0=B8=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=BD=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= =?UTF-8?q?.=20=D0=9D=D1=83=D0=B6=D0=BD=D0=BE=20=D1=80=D0=B0=D0=B7=D0=BE?= =?UTF-8?q?=D0=B1=D1=80=D0=B0=D1=82=D1=8C=D1=81=D1=8F=20=D1=87=D1=82=D0=BE?= =?UTF-8?q?=20=D1=82=D0=B0=D0=BA=D0=BE=D0=B5=20=D0=B0=D1=81=D1=82=20=D0=B8?= =?UTF-8?q?=20=D0=BA=D0=B0=D0=BA=20=D0=BF=D0=BE=20=D0=BD=D0=B5=D0=BC=D1=83?= =?UTF-8?q?=20=D0=B1=D0=B5=D0=B3=D0=B0=D1=82=D1=8C=20=D0=B8=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B5=D1=80=D1=8F=D1=82=D1=8C.?= 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 ++++ docs/en/index.md | 1 + .../diagnostics/YodaStyleDiagnostic.java | 68 +++++++++++++++++++ .../YodaStyleDiagnostic_en.properties | 2 + .../YodaStyleDiagnostic_ru.properties | 2 + .../diagnostics/YodaStyleDiagnosticTest.java | 46 +++++++++++++ .../diagnostics/YodaStyleDiagnostic.bsl | 4 ++ 8 files changed, 153 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/docs/en/index.md b/docs/en/index.md index 01d39b71c76..0e881553e2f 100644 --- a/docs/en/index.md +++ b/docs/en/index.md @@ -165,4 +165,5 @@ Some of diagnostics are disabled by default. Use config | [UsingFindElementByString](diagnostics/UsingFindElementByString.md) | Restriction on the use of "FindByDescription" and "FindByCode" methods | Yes | | [UsingGoto](diagnostics/UsingGoto.md) | "goto" statement should not be used | Yes | | [UsingServiceTag](diagnostics/UsingServiceTag.md) | Using service tags | Yes | +| [YodaStyleDiagnostic](diagnostics/YodaStyle.md) | Using Yoda style for comparing values | Yes | | [YoLetterUsageDiagnostic](diagnostics/YoLetterUsage.md) | Using "Ё" letter in code | Yes | 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..bcfae8f159f --- /dev/null +++ b/src/main/java/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnostic.java @@ -0,0 +1,68 @@ +/* + * 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.DiagnosticType; +import org.github._1c_syntax.bsl.languageserver.utils.RangeHelper; +import org.github._1c_syntax.bsl.parser.BSLParser; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.stream.Collectors; + +@DiagnosticMetadata( + type = DiagnosticType.CODE_SMELL, + severity = DiagnosticSeverity.MINOR, + scope = DiagnosticScope.BSL, + minutesToFix = 2 +) +public class YodaStyleDiagnostic implements BSLDiagnostic { + + @Override + public List getDiagnostics(DocumentContext documentContext) { + + List wrongIdentifiers = documentContext.getTokensFromDefaultChannel() + .parallelStream() + .filter((Token t) -> + t.getType() == BSLParser.IDENTIFIER && + t.getText().toUpperCase(Locale.ENGLISH).contains("Ё")) + .collect((Collectors.toList())); + + List diagnostics = new ArrayList<>(); + + for (Token token : wrongIdentifiers) { + diagnostics.add(BSLDiagnostic.createDiagnostic( + this, + RangeHelper.newRange(token), + getDiagnosticMessage())); + } + + return diagnostics; + + } +} 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..8feb8cd0233 --- /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..d0bdf843f86 --- /dev/null +++ b/src/test/java/org/github/_1c_syntax/bsl/languageserver/diagnostics/YodaStyleDiagnosticTest.java @@ -0,0 +1,46 @@ +/* + * 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.get(0).getRange()).isEqualTo(RangeHelper.newRange(2, 5, 2, 33)); + } +} diff --git a/src/test/resources/diagnostics/YodaStyleDiagnostic.bsl b/src/test/resources/diagnostics/YodaStyleDiagnostic.bsl new file mode 100644 index 00000000000..e7aa38d031a --- /dev/null +++ b/src/test/resources/diagnostics/YodaStyleDiagnostic.bsl @@ -0,0 +1,4 @@ +Процедура СмешноПереставляетСлова() + Если 100 = ЙодаГоворит Тогда // Здесь должна сработать диагностика + КонецЕсли; +КонецПроцедуры From 14783a20e4e57c7e6f195f2bf255b4520b09d61d Mon Sep 17 00:00:00 2001 From: atai1 Date: Fri, 2 Aug 2019 19:10:24 +0300 Subject: [PATCH 5/8] =?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 --- .idea/misc.xml | 3 ++ .../diagnostics/YodaStyleDiagnostic.java | 28 ++++++------------- .../YodaStyleDiagnostic_ru.properties | 2 +- .../diagnostics/YodaStyleDiagnosticTest.java | 3 +- .../diagnostics/YodaStyleDiagnostic.bsl | 9 ++++-- 5 files changed, 21 insertions(+), 24 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 84da703c3b6..cc42a578650 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,8 @@ + + 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 bcfae8f159f..cd961b04470 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 @@ -26,9 +26,12 @@ 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; @@ -37,32 +40,19 @@ @DiagnosticMetadata( type = DiagnosticType.CODE_SMELL, - severity = DiagnosticSeverity.MINOR, scope = DiagnosticScope.BSL, + severity = DiagnosticSeverity.MINOR, minutesToFix = 2 ) -public class YodaStyleDiagnostic implements BSLDiagnostic { +public class YodaStyleDiagnostic extends AbstractVisitorDiagnostic{ @Override - public List getDiagnostics(DocumentContext documentContext) { - - List wrongIdentifiers = documentContext.getTokensFromDefaultChannel() - .parallelStream() - .filter((Token t) -> - t.getType() == BSLParser.IDENTIFIER && - t.getText().toUpperCase(Locale.ENGLISH).contains("Ё")) - .collect((Collectors.toList())); + public ParseTree visitIfStatement(BSLParser.IfStatementContext ctx) { - List diagnostics = new ArrayList<>(); - - for (Token token : wrongIdentifiers) { - diagnostics.add(BSLDiagnostic.createDiagnostic( - this, - RangeHelper.newRange(token), - getDiagnosticMessage())); + if (ctx.getToken(BSLLexer.ELSIF_KEYWORD, 0) != null && ctx.getToken(BSLLexer.ELSE_KEYWORD, 0) == null) { + diagnosticStorage.addDiagnostic(ctx.getStop()); } - return diagnostics; - + return super.visitIfStatement(ctx); } } 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 index 8feb8cd0233..79b46e65631 100644 --- 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 @@ -1,2 +1,2 @@ -diagnosticMessage= , . +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 index d0bdf843f86..1a55efc22fd 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 @@ -41,6 +41,7 @@ void test() { List diagnostics = getDiagnostics(); // then assertThat(diagnostics).hasSize(1); - assertThat(diagnostics.get(0).getRange()).isEqualTo(RangeHelper.newRange(2, 5, 2, 33)); + 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 index e7aa38d031a..9a1a043e3ab 100644 --- a/src/test/resources/diagnostics/YodaStyleDiagnostic.bsl +++ b/src/test/resources/diagnostics/YodaStyleDiagnostic.bsl @@ -1,4 +1,7 @@ -Процедура СмешноПереставляетСлова() - Если 100 = ЙодаГоворит Тогда // Здесь должна сработать диагностика + // Выражение с ошибкой + Если 100 = ЙодаГоворит Тогда КонецЕсли; -КонецПроцедуры + + // Корректное выражение + Если ЙодаГоворит = 100 Тогда + КонецЕсли; \ No newline at end of file From d34fe26c9d375b15edb44203b471dd389aac866a Mon Sep 17 00:00:00 2001 From: atai1 Date: Fri, 2 Aug 2019 23:52:53 +0300 Subject: [PATCH 6/8] =?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 7c71fd1190fcd2768faf85e28f01cf5fb5d1e558 Mon Sep 17 00:00:00 2001 From: atai1 Date: Sat, 3 Aug 2019 10:38:08 +0300 Subject: [PATCH 7/8] =?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 --- .idea/compiler.xml | 2 -- docs/diagnostics/YodaStyle.md | 2 +- docs/en/diagnostics/YodaStyle.md | 2 +- .../resources/diagnostics/YodaStyleDiagnostic.bsl | 12 ++---------- 4 files changed, 4 insertions(+), 14 deletions(-) diff --git a/.idea/compiler.xml b/.idea/compiler.xml index ebbf0621394..d56e18d2bc5 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -5,8 +5,6 @@ - - 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 42c36c6758da5bece3f9118ee93b6a445b5df250 Mon Sep 17 00:00:00 2001 From: atai1 Date: Sat, 3 Aug 2019 22:01:44 +0300 Subject: [PATCH 8/8] =?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 29109f859a8..0149b66ce65 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)