-
Notifications
You must be signed in to change notification settings - Fork 121
WIP: Йода-синтаксис. Fix #291 #297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6612fa5
a1032d3
5784a8a
791d29f
14783a2
d34fe26
7c71fd1
42c36c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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/ | ||
|
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,22 @@ | ||
| # Руководство контрибьютора | ||
|
|
||
| ## Требования к окружению | ||
|
|
||
| * 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 | ||
|
|
||
| ## Добавление диагностики | ||
|
|
||
| Пример добавления диагностики в [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) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # В операциях сравнения переменная должна быть слева от оператора, значение должно быть справа | ||
|
|
||
| Сравнивая значения и переменные помни: переменные слева быть должны (С) Yoda | ||
|
|
||
| Плохо: | ||
| ```BSL | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. надо исправить на
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Описание стоит скорректировать по шаблону
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. и файлы переименовать по шаблону
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. оно начиналось еще в августе. тут многое уже надо дотянуть до шаблона :) |
||
| Если 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) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # In comparison operations, the variable must be to the left of the operator, the value must be to the right | ||
|
|
||
| Compare values and 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/) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * This file is a part of BSL Language Server. | ||
| * | ||
| * Copyright © 2018-2019 | ||
| * Alexey Sosnoviy <[email protected]>, Nikita Gryzlov <[email protected]> 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.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 | ||
| ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. нужны тэги |
||
|
|
||
| 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 visitGlobalMethodCall(BSLParser.GlobalMethodCallContext ctx) { | ||
|
|
||
| if (messagePattern.matcher(ctx.methodName().getText()).matches()) { | ||
| diagnosticStorage.addDiagnostic(ctx); | ||
| } | ||
|
|
||
| return super.visitGlobalMethodCall(ctx); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| diagnosticMessage=The Yoda style is not allowed in the texts of the modules. | ||
| diagnosticName=Using Yoda style in code |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| diagnosticMessage=� ������� �������, ��� �������� ���������� ������� ���������� ������ ���� ����� �� ����� ���������� ��������, � �������� ������. | ||
| diagnosticName=������������� yoda style ��� �������� ���������� |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * This file is a part of BSL Language Server. | ||
| * | ||
| * Copyright © 2018-2019 | ||
| * Alexey Sosnoviy <[email protected]>, Nikita Gryzlov <[email protected]> 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<YodaStyleDiagnostic> { | ||
|
|
||
| YodaStyleDiagnosticTest() { | ||
| super(YodaStyleDiagnostic.class); | ||
| } | ||
|
|
||
| @Test | ||
| void test() { | ||
| // when | ||
| List<Diagnostic> 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))); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| Процедура А() | ||
|
|
||
| // Выражение с ошибкой | ||
| Если 100 = ЙодаГоворит Тогда | ||
| КонецЕсли; | ||
|
|
||
| // Выражение с ошибкой | ||
| Если 100 + 10 = ЙодаГоворит Тогда | ||
| КонецЕсли; | ||
|
|
||
| // Выражение с ошибкой | ||
| Если "МолчитИода" = ЙодаГоворит Тогда | ||
| КонецЕсли; | ||
|
|
||
| // Корректное выражение | ||
| Если ЙодаГоворит = 100 Тогда | ||
| КонецЕсли; | ||
|
|
||
| // Корректное выражение | ||
| Если ЙодаГоворит = 100 + 10 Тогда | ||
| КонецЕсли; | ||
|
|
||
| // Корректное выражение | ||
| Если ЙодаГоворит = "МолчитИода" Тогда | ||
| КонецЕсли; | ||
|
|
||
| КонецПроцедуры; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это лишнее, есть отдельный раздел с документацией