Skip to content
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

Правило "ProtectedModule" - защищенные, запароленные модули - зависит от исправлений в mdclasses #3081

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
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
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ dependencies {
exclude("org.glassfish", "javax.json")
}
api("com.github.1c-syntax", "utils", "0.5.1")
api("com.github.1c-syntax", "mdclasses", "0.10.3")
// TODO временно для реализации https://github.com/1c-syntax/bsl-language-server/pull/3081
implementation("com.github.artbear", "mdclasses", "protected-modules-SNAPSHOT")
// api("com.github.1c-syntax", "mdclasses", "0.10.3")
api("io.github.1c-syntax", "bsl-common-library", "0.3.0")
api("io.github.1c-syntax", "supportconf", "0.1.1")

Expand Down
18 changes: 18 additions & 0 deletions docs/diagnostics/ProtectedModule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Защищенные модули (ProtectedModule)

<!-- Блоки выше заполняются автоматически, не трогать -->
## Описание диагностики
<!-- Описание диагностики заполняется вручную. Необходимо понятным языком описать смысл и схему работу -->
Отсутствие исходников модуля в конфигурации не рекомендуется.
В случае закрытого, запароленного модуля понижается качество кода, нельзя сделать ревью кода, версионирование изменений не ведется.

## Примеры
<!-- В данном разделе приводятся примеры, на которые диагностика срабатывает, а также можно привести пример, как можно исправить ситуацию -->

## Источники
<!-- Необходимо указывать ссылки на все источники, из которых почерпнута информация для создания диагностики -->
<!-- Примеры источников

* Источник: [Стандарт: Тексты модулей](https://its.1c.ru/db/v8std#content:456:hdoc)
* Полезная информация: [Отказ от использования модальных окон](https://its.1c.ru/db/metod8dev#content:5272:hdoc)
* Источник: [Cognitive complexity, ver. 1.4](https://www.sonarsource.com/docs/CognitiveComplexity.pdf) -->
16 changes: 16 additions & 0 deletions docs/en/diagnostics/ProtectedModule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Protected modules (ProtectedModule)

<!-- Блоки выше заполняются автоматически, не трогать -->
## Description
<!-- Описание диагностики заполняется вручную. Необходимо понятным языком описать смысл и схему работу -->

## Examples
<!-- В данном разделе приводятся примеры, на которые диагностика срабатывает, а также можно привести пример, как можно исправить ситуацию -->

## Sources
<!-- Необходимо указывать ссылки на все источники, из которых почерпнута информация для создания диагностики -->
<!-- Примеры источников

* Источник: [Стандарт: Тексты модулей](https://its.1c.ru/db/v8std#content:456:hdoc)
* Полезная информация: [Отказ от использования модальных окон](https://its.1c.ru/db/metod8dev#content:5272:hdoc)
* Источник: [Cognitive complexity, ver. 1.4](https://www.sonarsource.com/docs/CognitiveComplexity.pdf) -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* This file is a part of BSL Language Server.
*
* Copyright (c) 2018-2023
* Alexey Sosnoviy <labotamy@gmail.com>, Nikita Fedkin <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.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;
import com.github._1c_syntax.bsl.languageserver.utils.MdoRefBuilder;
import com.github._1c_syntax.bsl.mdo.ModuleOwner;
import com.github._1c_syntax.bsl.types.MDOType;
import com.github._1c_syntax.bsl.types.ModuleType;
import com.github._1c_syntax.mdclasses.mdo.AbstractMDObjectBase;
import com.github._1c_syntax.mdclasses.mdo.support.MDOModule;

import java.util.List;

@DiagnosticMetadata(
type = DiagnosticType.CODE_SMELL,
severity = DiagnosticSeverity.MAJOR,
minutesToFix = 5,
tags = {
DiagnosticTag.BADPRACTICE,
DiagnosticTag.SUSPICIOUS
},
modules = { ModuleType.SessionModule },
scope = DiagnosticScope.BSL
)

public class ProtectedModuleDiagnostic extends AbstractMetadataDiagnostic {

public ProtectedModuleDiagnostic() {
super(List.of(
MDOType.CONFIGURATION,
MDOType.ACCOUNTING_REGISTER,
MDOType.ACCUMULATION_REGISTER,
MDOType.BUSINESS_PROCESS,
MDOType.CALCULATION_REGISTER,
MDOType.CATALOG,
MDOType.CHART_OF_ACCOUNTS,
MDOType.CHART_OF_CALCULATION_TYPES,
MDOType.CHART_OF_CHARACTERISTIC_TYPES,
MDOType.COMMON_MODULE,
MDOType.CONSTANT,
MDOType.DOCUMENT,
MDOType.DOCUMENT_JOURNAL,
MDOType.ENUM,
MDOType.EXCHANGE_PLAN,
MDOType.FILTER_CRITERION,
MDOType.INFORMATION_REGISTER,
MDOType.TASK
));
}

@Override
protected void checkMetadata(AbstractMDObjectBase mdo) {
if (!(mdo instanceof ModuleOwner)){
return;
}
var moduleOwner = (ModuleOwner) mdo;
moduleOwner.getProtectedModules().forEach((MDOModule mdoModule) ->{
var ownerMDOName = MdoRefBuilder.getLocaleOwnerMdoName(documentContext, mdo);
addDiagnostic(info.getMessage(ownerMDOName));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,16 @@
"title": "Procedure should not return Value",
"$id": "#/definitions/ProcedureReturnsValue"
},
"ProtectedModule": {
"description": "Protected modules",
"default": true,
"type": [
"boolean",
"object"
],
"title": "Protected modules",
"$id": "#/definitions/ProtectedModule"
},
"PublicMethodsDescription": {
"description": "All public methods must have a description",
"default": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
diagnosticMessage=The source code of the module is missing due to password protection. %s
diagnosticName=Protected modules
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
diagnosticMessage=Исходник модуля отсутствует из-за защиты паролем. %s
diagnosticName=Защищенные модули
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* This file is a part of BSL Language Server.
*
* Copyright (c) 2018-2023
* Alexey Sosnoviy <labotamy@gmail.com>, Nikita Fedkin <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.utils.Ranges;
import com.github._1c_syntax.bsl.types.ModuleType;
import com.github._1c_syntax.utils.Absolute;
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.Range;
import org.junit.jupiter.api.Test;

import java.util.List;

import static com.github._1c_syntax.bsl.languageserver.util.Assertions.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

class ProtectedModuleDiagnosticTest extends AbstractDiagnosticTest<ProtectedModuleDiagnostic> {
ProtectedModuleDiagnosticTest() {
super(ProtectedModuleDiagnostic.class);
}

private static final String PATH_TO_METADATA = "src/test/resources/metadata/subSystemFilter";

@Test
void test() {
initServerContext(Absolute.path(PATH_TO_METADATA));

var documentContext = spy(getDocumentContext());
when(documentContext.getModuleType()).thenReturn(ModuleType.SessionModule);

List<Diagnostic> diagnostics = getDiagnostics(documentContext);
assertThat(diagnostics, true)
.allMatch(
diagnostic -> diagnostic.getRange().equals(getRange()))
.anyMatch(diagnostic -> diagnostic.getMessage()
.equals("Исходник модуля отсутствует из-за защиты паролем. ОбщийМодуль.ОбщийМодуль1"))
.hasSize(1)
;
}

private static Range getRange() {
return Ranges.create(0, 0, 9);
}
}
2 changes: 2 additions & 0 deletions src/test/resources/diagnostics/ProtectedModuleDiagnostic.bsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Процедура Метод()
КонецПроцедуры
Loading