Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 65 additions & 63 deletions .gitignore
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/

3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 22 additions & 14 deletions CONTRIBUTING.md
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

## Добавление диагностики
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это лишнее, есть отдельный раздел с документацией


Пример добавления диагностики в [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)
15 changes: 15 additions & 0 deletions docs/diagnostics/YodaStyle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# В операциях сравнения переменная должна быть слева от оператора, значение должно быть справа

Сравнивая значения и переменные помни: переменные слева быть должны (С) Yoda

Плохо:
```BSL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

надо исправить на bsl

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Описание стоит скорректировать по шаблону

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

и файлы переименовать по шаблону

Copy link
Member

Choose a reason for hiding this comment

The 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)
15 changes: 15 additions & 0 deletions docs/en/diagnostics/YodaStyle.md
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/)
1 change: 1 addition & 0 deletions docs/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,5 @@ Some of diagnostics are disabled by default. Use <a href="#configuration">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 |
5 changes: 5 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
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
)
Copy link
Member

Choose a reason for hiding this comment

The 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)));
}
}
27 changes: 27 additions & 0 deletions src/test/resources/diagnostics/YodaStyleDiagnostic.bsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Процедура А()

// Выражение с ошибкой
Если 100 = ЙодаГоворит Тогда
КонецЕсли;

// Выражение с ошибкой
Если 100 + 10 = ЙодаГоворит Тогда
КонецЕсли;

// Выражение с ошибкой
Если "МолчитИода" = ЙодаГоворит Тогда
КонецЕсли;

// Корректное выражение
Если ЙодаГоворит = 100 Тогда
КонецЕсли;

// Корректное выражение
Если ЙодаГоворит = 100 + 10 Тогда
КонецЕсли;

// Корректное выражение
Если ЙодаГоворит = "МолчитИода" Тогда
КонецЕсли;

КонецПроцедуры;