-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1232 from alkoleft/feature/exportVariables
Feature/export variables
- Loading branch information
Showing
17 changed files
with
383 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Запрет экспортных глобальных переменных модуля (ExportVariables) | ||
|
||
| Тип | Поддерживаются<br/>языки | Важность | Включена<br/>по умолчанию | Время на<br/>исправление (мин) | Тэги | | ||
| :-: | :-: | :-: | :-: | :-: | :-: | | ||
| `Дефект кода` | `BSL`<br/>`OS` | `Важный` | `Да` | `5` | `standard`<br/>`design`<br/>`unpredictable` | | ||
|
||
<!-- Блоки выше заполняются автоматически, не трогать --> | ||
## Описание диагностики | ||
|
||
В большинстве случаев, вместо переменных программных модулей следует использовать более подходящие средства разработки платформы 1С:Предприятие. | ||
Поскольку область видимости (использования) таких переменных сложно контролировать, | ||
то они зачастую становятся источником трудновоспроизводимых ошибок. | ||
|
||
## Примеры | ||
<!-- В данном разделе приводятся примеры, на которые диагностика срабатывает, а также можно привести пример, как можно исправить ситуацию --> | ||
|
||
```bsl | ||
Перем КонвертацияФайлов Экспорт; | ||
Процедура ПередЗаписью(Отказ) | ||
Если КонвертацияФайлов Тогда | ||
... | ||
КонецПроцедуры | ||
``` | ||
|
||
Для передачи параметров между обработчиками подписок на события и в обработчики событий модуля объекта из внешнего кода | ||
рекомендуется использовать свойство объекта ДополнительныеСвойства | ||
|
||
```bsl | ||
Процедура ПередЗаписью(Отказ) | ||
Если ДополнительныеСвойства.Свойство("КонвертацияФайлов") Тогда | ||
... | ||
КонецПроцедуры | ||
// вызывающий код | ||
ФайлОбъект.ДополнительныеСвойства.Вставить("КонвертацияФайлов", Истина); | ||
ФайлОбъект.Записать(); | ||
``` | ||
|
||
## Источники | ||
<!-- Необходимо указывать ссылки на все источники, из которых почерпнута информация для создания диагностики --> | ||
<!-- Примеры источников --> | ||
|
||
[Стандарт: Использование переменных в программных модулях](https://its.1c.ru/db/v8std#content:639:hdoc) | ||
|
||
## Сниппеты | ||
|
||
<!-- Блоки ниже заполняются автоматически, не трогать --> | ||
### Экранирование кода | ||
|
||
```bsl | ||
// BSLLS:ExportVariables-off | ||
// BSLLS:ExportVariables-on | ||
``` | ||
|
||
### Параметр конфигурационного файла | ||
|
||
```json | ||
"ExportVariables": false | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Ban export global module variables (ExportVariables) | ||
|
||
| Type | Scope | Severity | Activated<br/>by default | Minutes<br/>to fix | Tags | | ||
| :-: | :-: | :-: | :-: | :-: | :-: | | ||
| `Code smell` | `BSL`<br/>`OS` | `Major` | `Yes` | `5` | `standard`<br/>`design`<br/>`unpredictable` | | ||
|
||
<!-- Блоки выше заполняются автоматически, не трогать --> | ||
## Description | ||
|
||
In most scenarios, we recommend that you do not use global variables and use other 1C:Enterprise script tools instead. | ||
Since monitoring the visibility (usage) areas of such variables is tricky, | ||
they often might cause issues that cannot be easily located. | ||
|
||
## Examples | ||
<!-- В данном разделе приводятся примеры, на которые диагностика срабатывает, а также можно привести пример, как можно исправить ситуацию --> | ||
|
||
```bsl | ||
Variable FileConversion Export; | ||
Procedure BeforeWrite(Cancel) | ||
If FileConversion Then | ||
... | ||
EndProcedure | ||
``` | ||
|
||
We recommend that you use the AdditionalProperties object property for passing parameters between event subscription handlers | ||
and for passing parameters from external script to object module event handlers. | ||
|
||
```bsl | ||
Procedure BeforeWrite(Cancel) | ||
If AdditionalProperties.Property("FileConversion") Then | ||
... | ||
EndProcedure | ||
// script that calls the procedure | ||
FileObject.AdditionalProperties.Insert("FileConversion", True); | ||
FileObject.Write(); | ||
``` | ||
|
||
## Sources | ||
<!-- Необходимо указывать ссылки на все источники, из которых почерпнута информация для создания диагностики --> | ||
<!-- Примеры источников --> | ||
|
||
* [Standard: Using global variables in modules](https://1c-dn.com/library/using_global_variables_in_modules/) | ||
* [Standard: Using global variables in modules(RU)](https://its.1c.ru/db/v8std#content:639:hdoc) | ||
|
||
## Snippets | ||
|
||
<!-- Блоки ниже заполняются автоматически, не трогать --> | ||
### Diagnostic ignorance in code | ||
|
||
```bsl | ||
// BSLLS:ExportVariables-off | ||
// BSLLS:ExportVariables-on | ||
``` | ||
|
||
### Parameter for config | ||
|
||
```json | ||
"ExportVariables": false | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/com/github/_1c_syntax/bsl/languageserver/context/symbol/SymbolTreeVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* This file is a part of BSL Language Server. | ||
* | ||
* Copyright © 2018-2020 | ||
* Alexey Sosnoviy <labotamy@gmail.com>, Nikita Gryzlov <nixel2007@gmail.com> 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 com.github._1c_syntax.bsl.languageserver.context.symbol; | ||
|
||
public interface SymbolTreeVisitor { | ||
void visitRegion(RegionSymbol region); | ||
|
||
void visitMethod(MethodSymbol method); | ||
|
||
void visitVariable(VariableSymbol variable); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...va/com/github/_1c_syntax/bsl/languageserver/diagnostics/AbstractSymbolTreeDiagnostic.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* This file is a part of BSL Language Server. | ||
* | ||
* Copyright © 2018-2020 | ||
* Alexey Sosnoviy <labotamy@gmail.com>, Nikita Gryzlov <nixel2007@gmail.com> 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 com.github._1c_syntax.bsl.languageserver.diagnostics; | ||
|
||
import com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol; | ||
import com.github._1c_syntax.bsl.languageserver.context.symbol.RegionSymbol; | ||
import com.github._1c_syntax.bsl.languageserver.context.symbol.Symbol; | ||
import com.github._1c_syntax.bsl.languageserver.context.symbol.SymbolTreeVisitor; | ||
import com.github._1c_syntax.bsl.languageserver.context.symbol.VariableSymbol; | ||
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo; | ||
|
||
import java.util.List; | ||
|
||
public abstract class AbstractSymbolTreeDiagnostic extends AbstractDiagnostic implements SymbolTreeVisitor { | ||
public AbstractSymbolTreeDiagnostic(DiagnosticInfo info) { | ||
super(info); | ||
} | ||
|
||
@Override | ||
protected void check() { | ||
visitChildren(documentContext.getSymbolTree().getChildren()); | ||
} | ||
|
||
void visitChildren(List<Symbol> children) { | ||
children.forEach(this::visit); | ||
} | ||
|
||
void visit(Symbol symbol){ | ||
symbol.accept(this); | ||
} | ||
|
||
@Override | ||
public void visitRegion(RegionSymbol region) { | ||
visitChildren(region.getChildren()); | ||
} | ||
|
||
@Override | ||
public void visitMethod(MethodSymbol method) { | ||
visitChildren(method.getChildren()); | ||
} | ||
|
||
@Override | ||
public void visitVariable(VariableSymbol variable) { | ||
visitChildren(variable.getChildren()); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
.../java/com/github/_1c_syntax/bsl/languageserver/diagnostics/ExportVariablesDiagnostic.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* This file is a part of BSL Language Server. | ||
* | ||
* Copyright © 2018-2020 | ||
* Alexey Sosnoviy <labotamy@gmail.com>, Nikita Gryzlov <nixel2007@gmail.com> 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 com.github._1c_syntax.bsl.languageserver.diagnostics; | ||
|
||
import com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol; | ||
import com.github._1c_syntax.bsl.languageserver.context.symbol.VariableSymbol; | ||
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo; | ||
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; | ||
|
||
@DiagnosticMetadata( | ||
type = DiagnosticType.CODE_SMELL, | ||
severity = DiagnosticSeverity.MAJOR, | ||
minutesToFix = 5, | ||
scope = DiagnosticScope.ALL, | ||
tags = { | ||
DiagnosticTag.STANDARD, | ||
DiagnosticTag.DESIGN, | ||
DiagnosticTag.UNPREDICTABLE | ||
} | ||
) | ||
public class ExportVariablesDiagnostic extends AbstractSymbolTreeDiagnostic { | ||
public ExportVariablesDiagnostic(DiagnosticInfo info) { | ||
super(info); | ||
} | ||
|
||
@Override | ||
public void visitVariable(VariableSymbol variable) { | ||
if (variable.isExport()) { | ||
diagnosticStorage.addDiagnostic(variable.getRange()); | ||
} | ||
} | ||
|
||
@Override | ||
public void visitMethod(MethodSymbol method) { | ||
// skip content of methods | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.