Skip to content

Commit 432bbc7

Browse files
authored
Merge pull request #3408 from 1c-syntax/feature/ProtectedModule
Feature/protected module
2 parents 9cac003 + 3c8401f commit 432bbc7

File tree

11 files changed

+209
-2
lines changed

11 files changed

+209
-2
lines changed

docs/diagnostics/ProtectedModule.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Защищенные модули (ProtectedModule)
2+
3+
<!-- Блоки выше заполняются автоматически, не трогать -->
4+
## Описание диагностики
5+
<!-- Описание диагностики заполняется вручную. Необходимо понятным языком описать смысл и схему работу -->
6+
Отсутствие исходников модуля в конфигурации не рекомендуется.
7+
В случае закрытого, запароленного модуля понижается качество кода, нельзя сделать ревью кода, версионирование изменений не ведется.
8+
9+
## Примеры
10+
<!-- В данном разделе приводятся примеры, на которые диагностика срабатывает, а также можно привести пример, как можно исправить ситуацию -->
11+
12+
## Источники
13+
<!-- Необходимо указывать ссылки на все источники, из которых почерпнута информация для создания диагностики -->
14+
<!-- Примеры источников
15+
16+
* Источник: [Стандарт: Тексты модулей](https://its.1c.ru/db/v8std#content:456:hdoc)
17+
* Полезная информация: [Отказ от использования модальных окон](https://its.1c.ru/db/metod8dev#content:5272:hdoc)
18+
* Источник: [Cognitive complexity, ver. 1.4](https://www.sonarsource.com/docs/CognitiveComplexity.pdf) -->
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Protected modules (ProtectedModule)
2+
3+
<!-- Блоки выше заполняются автоматически, не трогать -->
4+
## Description
5+
<!-- Описание диагностики заполняется вручную. Необходимо понятным языком описать смысл и схему работу -->
6+
7+
## Examples
8+
<!-- В данном разделе приводятся примеры, на которые диагностика срабатывает, а также можно привести пример, как можно исправить ситуацию -->
9+
10+
## Sources
11+
<!-- Необходимо указывать ссылки на все источники, из которых почерпнута информация для создания диагностики -->
12+
<!-- Примеры источников
13+
14+
* Источник: [Стандарт: Тексты модулей](https://its.1c.ru/db/v8std#content:456:hdoc)
15+
* Полезная информация: [Отказ от использования модальных окон](https://its.1c.ru/db/metod8dev#content:5272:hdoc)
16+
* Источник: [Cognitive complexity, ver. 1.4](https://www.sonarsource.com/docs/CognitiveComplexity.pdf) -->
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* This file is a part of BSL Language Server.
3+
*
4+
* Copyright (c) 2018-2025
5+
* Alexey Sosnoviy <labotamy@gmail.com>, Nikita Fedkin <nixel2007@gmail.com> and contributors
6+
*
7+
* SPDX-License-Identifier: LGPL-3.0-or-later
8+
*
9+
* BSL Language Server is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 3.0 of the License, or (at your option) any later version.
13+
*
14+
* BSL Language Server is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with BSL Language Server.
21+
*/
22+
package com.github._1c_syntax.bsl.languageserver.diagnostics;
23+
24+
25+
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticMetadata;
26+
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticScope;
27+
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticSeverity;
28+
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticTag;
29+
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticType;
30+
import com.github._1c_syntax.bsl.languageserver.utils.MdoRefBuilder;
31+
import com.github._1c_syntax.bsl.languageserver.utils.Ranges;
32+
import com.github._1c_syntax.bsl.mdo.Module;
33+
import com.github._1c_syntax.bsl.mdo.ModuleOwner;
34+
import com.github._1c_syntax.bsl.types.ConfigurationSource;
35+
import com.github._1c_syntax.bsl.types.ModuleType;
36+
import org.eclipse.lsp4j.Range;
37+
38+
@DiagnosticMetadata(
39+
type = DiagnosticType.CODE_SMELL,
40+
severity = DiagnosticSeverity.MAJOR,
41+
minutesToFix = 5,
42+
tags = {
43+
DiagnosticTag.BADPRACTICE,
44+
DiagnosticTag.SUSPICIOUS
45+
},
46+
modules = {
47+
ModuleType.SessionModule
48+
},
49+
scope = DiagnosticScope.BSL,
50+
canLocateOnProject = true
51+
)
52+
53+
public class ProtectedModuleDiagnostic extends AbstractDiagnostic {
54+
55+
/**
56+
* Рендж на который будут повешены замечания
57+
* Костыль, но пока так
58+
*/
59+
private Range diagnosticRange;
60+
61+
@Override
62+
protected void check() {
63+
64+
var configuration = documentContext.getServerContext().getConfiguration();
65+
if (configuration.getConfigurationSource() == ConfigurationSource.EMPTY) {
66+
return;
67+
}
68+
69+
diagnosticRange = documentContext.getSymbolTree().getModule().getSelectionRange();
70+
if (Ranges.isEmpty(diagnosticRange)) {
71+
return;
72+
}
73+
74+
configuration.getChildren().stream()
75+
.filter(md -> md instanceof ModuleOwner)
76+
.map(md -> (ModuleOwner) md)
77+
.forEach((ModuleOwner moduleOwner) -> {
78+
var hasProtected = moduleOwner.getModules().stream()
79+
.filter(Module::isProtected)
80+
.findAny();
81+
if (hasProtected.isPresent()) {
82+
addDiagnostic(moduleOwner);
83+
}
84+
});
85+
}
86+
87+
private void addDiagnostic(ModuleOwner moduleOwner) {
88+
var ownerMDOName = MdoRefBuilder.getLocaleOwnerMdoName(documentContext, moduleOwner);
89+
diagnosticStorage.addDiagnostic(diagnosticRange, info.getMessage(ownerMDOName));
90+
}
91+
}

src/main/resources/com/github/_1c_syntax/bsl/languageserver/configuration/parameters-schema.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,16 @@
15921592
"title": "Procedure should not return Value",
15931593
"$id": "#/definitions/ProcedureReturnsValue"
15941594
},
1595+
"ProtectedModule": {
1596+
"description": "Protected modules",
1597+
"default": true,
1598+
"type": [
1599+
"boolean",
1600+
"object"
1601+
],
1602+
"title": "Protected modules",
1603+
"$id": "#/definitions/ProtectedModule"
1604+
},
15951605
"PublicMethodsDescription": {
15961606
"description": "All public methods must have a description",
15971607
"default": true,

src/main/resources/com/github/_1c_syntax/bsl/languageserver/configuration/schema.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@
371371
"ProcedureReturnsValue": {
372372
"$ref": "parameters-schema.json#/definitions/ProcedureReturnsValue"
373373
},
374+
"ProtectedModule": {
375+
"$ref": "parameters-schema.json#/definitions/ProtectedModule"
376+
},
374377
"PublicMethodsDescription": {
375378
"$ref": "parameters-schema.json#/definitions/PublicMethodsDescription"
376379
},
@@ -694,7 +697,7 @@
694697
"type": "string"
695698
},
696699
"default": [
697-
"Тест",
700+
"\u0422\u0435\u0441\u0442",
698701
"Test"
699702
]
700703
},
@@ -713,7 +716,7 @@
713716
"getTestsByTestRunner": {
714717
"$id": "#/properties/codeLens/testRunner/getTestsByTestRunner",
715718
"type": "boolean",
716-
"title": "Use testrunner to get test method names. By default, use internal parser to find methods annotated with &Тест.",
719+
"title": "Use testrunner to get test method names. By default, use internal parser to find methods annotated with &\u0422\u0435\u0441\u0442.",
717720
"default": true
718721
},
719722
"getTestsArguments": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
diagnosticMessage=The source code of the module is missing due to password protection. %s
2+
diagnosticName=Protected modules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
diagnosticMessage=Исходный код модуля отсутствует из-за защиты паролем. %s
2+
diagnosticName=Защищенные модули
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* This file is a part of BSL Language Server.
3+
*
4+
* Copyright (c) 2018-2025
5+
* Alexey Sosnoviy <labotamy@gmail.com>, Nikita Fedkin <nixel2007@gmail.com> and contributors
6+
*
7+
* SPDX-License-Identifier: LGPL-3.0-or-later
8+
*
9+
* BSL Language Server is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 3.0 of the License, or (at your option) any later version.
13+
*
14+
* BSL Language Server is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with BSL Language Server.
21+
*/
22+
package com.github._1c_syntax.bsl.languageserver.diagnostics;
23+
24+
import com.github._1c_syntax.bsl.languageserver.utils.Ranges;
25+
import com.github._1c_syntax.bsl.types.ModuleType;
26+
import com.github._1c_syntax.utils.Absolute;
27+
import org.eclipse.lsp4j.Diagnostic;
28+
import org.eclipse.lsp4j.Range;
29+
import org.junit.jupiter.api.Test;
30+
31+
import java.util.List;
32+
33+
import static com.github._1c_syntax.bsl.languageserver.util.Assertions.assertThat;
34+
import static org.mockito.Mockito.spy;
35+
import static org.mockito.Mockito.when;
36+
37+
class ProtectedModuleDiagnosticTest extends AbstractDiagnosticTest<ProtectedModuleDiagnostic> {
38+
ProtectedModuleDiagnosticTest() {
39+
super(ProtectedModuleDiagnostic.class);
40+
}
41+
42+
private static final String PATH_TO_METADATA = "src/test/resources/metadata/subSystemFilter";
43+
44+
@Test
45+
void test() {
46+
initServerContext(Absolute.path(PATH_TO_METADATA));
47+
var documentContext = spy(getDocumentContext());
48+
when(documentContext.getModuleType()).thenReturn(ModuleType.SessionModule);
49+
50+
List<Diagnostic> diagnostics = getDiagnostics(documentContext);
51+
assertThat(diagnostics, true)
52+
.hasSize(1)
53+
.allMatch(
54+
diagnostic -> diagnostic.getRange().equals(getRange()))
55+
.anyMatch(diagnostic -> diagnostic.getMessage()
56+
.equals("Исходный код модуля отсутствует из-за защиты паролем. ОбщийМодуль.ОбщийМодуль1"))
57+
;
58+
}
59+
60+
private static Range getRange() {
61+
return Ranges.create(0, 0, 9);
62+
}
63+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Процедура Метод()
2+
КонецПроцедуры

src/test/resources/metadata/subSystemFilter/CommonModules/ОбщийМодуль1/Ext/Module.bin

Whitespace-only changes.

0 commit comments

Comments
 (0)