diff --git a/docs/diagnostics/DisableAllDiagnostics.md b/docs/diagnostics/DisableAllDiagnostics.md new file mode 100644 index 00000000000..df19ba1626f --- /dev/null +++ b/docs/diagnostics/DisableAllDiagnostics.md @@ -0,0 +1,23 @@ +# Отключение всех проверок модуля (DisableAllDiagnostics) + + +## Описание диагностики + +Правило срабатывает на отключение проверки кода всего модуля через специальный комментарий `// BSLLS-off` или `BSLLS-выкл` +Подобные отключения могут привести к пропуску важных и полезных замечаний по коду всего модуля и понижению качества решения на 1С. + +Рекомендуется точечно отключать срабатывания конкретных правил на нужных строках через `// BSLLS:КлючДиагностики-off` или `// BSLLS:КлючДиагностики-выкл` +Например, `// BSLLS:MethodSize-off или // BSLLS:MethodSize-выкл` + +Более подробную информацию смотрите в разделе документации [Экранирование кода от диагностик](https://1c-syntax.github.io/bsl-language-server/features/DiagnosticIgnorance/) + +## Примеры + + +## Источники + + diff --git a/docs/en/diagnostics/DisableAllDiagnostics.md b/docs/en/diagnostics/DisableAllDiagnostics.md new file mode 100644 index 00000000000..185d915f199 --- /dev/null +++ b/docs/en/diagnostics/DisableAllDiagnostics.md @@ -0,0 +1,16 @@ +# Disable all diagnostics for module (DisableAllDiagnostics) + + +## Description + + +## Examples + + +## Sources + + diff --git a/src/main/java/com/github/_1c_syntax/bsl/languageserver/context/computer/DiagnosticIgnoranceComputer.java b/src/main/java/com/github/_1c_syntax/bsl/languageserver/context/computer/DiagnosticIgnoranceComputer.java index dc28b5f33ba..098e8208fb9 100644 --- a/src/main/java/com/github/_1c_syntax/bsl/languageserver/context/computer/DiagnosticIgnoranceComputer.java +++ b/src/main/java/com/github/_1c_syntax/bsl/languageserver/context/computer/DiagnosticIgnoranceComputer.java @@ -26,6 +26,7 @@ import com.github._1c_syntax.bsl.languageserver.context.symbol.annotations.Annotation; import com.github._1c_syntax.bsl.languageserver.context.symbol.annotations.AnnotationKind; import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticCode; +import com.github._1c_syntax.bsl.languageserver.utils.Ranges; import com.github._1c_syntax.bsl.parser.BSLLexer; import com.github._1c_syntax.utils.CaseInsensitivePattern; import edu.umd.cs.findbugs.annotations.Nullable; @@ -37,6 +38,7 @@ import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Deque; import java.util.HashMap; import java.util.List; @@ -74,6 +76,7 @@ public class DiagnosticIgnoranceComputer implements Computer>> diagnosticIgnorance = new HashMap<>(); private final Map> ignoranceStack = new HashMap<>(); + private final List ignoreOffList = new ArrayList<>(); public DiagnosticIgnoranceComputer(DocumentContext documentContext) { this.documentContext = documentContext; @@ -86,14 +89,12 @@ public Data compute() { ignoranceStack.clear(); List codeTokens = documentContext.getTokensFromDefaultChannel(); - if (codeTokens.isEmpty()) { - return new Data(diagnosticIgnorance); + if (!codeTokens.isEmpty()) { + computeCommentsIgnorance(codeTokens); + computeExtensionIgnorance(); } + return new Data(diagnosticIgnorance, ignoreOffList); - computeCommentsIgnorance(codeTokens); - computeExtensionIgnorance(); - - return new Data(diagnosticIgnorance); } private void computeExtensionIgnorance() { @@ -197,6 +198,10 @@ private DiagnosticCode checkIgnoreOff( Deque stack = ignoranceStack.computeIfAbsent(key, s -> new ArrayDeque<>()); stack.push(comment.getLine()); + if (ignoreOff.equals(IGNORE_ALL_OFF)){ + ignoreOffList.add(Ranges.create(comment)); + } + return key; } @@ -245,6 +250,11 @@ private static DiagnosticCode getKey(Matcher matcher) { @AllArgsConstructor public static class Data { private final Map>> diagnosticIgnorance; + private final List ignoreOffList; + + public List getIgnoreOffList() { + return Collections.unmodifiableList(ignoreOffList); + } public boolean diagnosticShouldBeIgnored(Diagnostic diagnostic) { if (diagnosticIgnorance.isEmpty()) { diff --git a/src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/DisableAllDiagnosticsDiagnostic.java b/src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/DisableAllDiagnosticsDiagnostic.java new file mode 100644 index 00000000000..bddd4222d91 --- /dev/null +++ b/src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/DisableAllDiagnosticsDiagnostic.java @@ -0,0 +1,46 @@ +/* + * This file is a part of BSL Language Server. + * + * Copyright (c) 2018-2023 + * Alexey Sosnoviy , Nikita Fedkin 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.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 = 1, + tags = { + DiagnosticTag.BADPRACTICE, + DiagnosticTag.SUSPICIOUS + } + +) +public class DisableAllDiagnosticsDiagnostic extends AbstractDiagnostic { + + @Override + protected void check() { + documentContext.getDiagnosticIgnorance().getIgnoreOffList() + .forEach(diagnosticStorage::addDiagnostic); + } +} diff --git a/src/main/resources/com/github/_1c_syntax/bsl/languageserver/configuration/parameters-schema.json b/src/main/resources/com/github/_1c_syntax/bsl/languageserver/configuration/parameters-schema.json index 2652d6eed1e..ae66a17fd0a 100644 --- a/src/main/resources/com/github/_1c_syntax/bsl/languageserver/configuration/parameters-schema.json +++ b/src/main/resources/com/github/_1c_syntax/bsl/languageserver/configuration/parameters-schema.json @@ -500,6 +500,16 @@ "title": "Deprecated ManagedForm type", "$id": "#/definitions/DeprecatedTypeManagedForm" }, + "DisableAllDiagnostics": { + "description": "Disable all diagnostics for module", + "default": true, + "type": [ + "boolean", + "object" + ], + "title": "Disable all diagnostics for module", + "$id": "#/definitions/DisableAllDiagnostics" + }, "DuplicateRegion": { "description": "Duplicate regions", "default": true, diff --git a/src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/DisableAllDiagnosticsDiagnostic_en.properties b/src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/DisableAllDiagnosticsDiagnostic_en.properties new file mode 100644 index 00000000000..05268286b4f --- /dev/null +++ b/src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/DisableAllDiagnosticsDiagnostic_en.properties @@ -0,0 +1,2 @@ +diagnosticMessage=Check disabling the analysis of the entire module +diagnosticName=Disable all diagnostics for module diff --git a/src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/DisableAllDiagnosticsDiagnostic_ru.properties b/src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/DisableAllDiagnosticsDiagnostic_ru.properties new file mode 100644 index 00000000000..4775e39a624 --- /dev/null +++ b/src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/DisableAllDiagnosticsDiagnostic_ru.properties @@ -0,0 +1,2 @@ +diagnosticMessage=Проверьте отключение анализа всего модуля +diagnosticName=Отключение всех проверок модуля diff --git a/src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/DisableAllDiagnosticsDiagnosticTest.java b/src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/DisableAllDiagnosticsDiagnosticTest.java new file mode 100644 index 00000000000..31036c4ee2a --- /dev/null +++ b/src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/DisableAllDiagnosticsDiagnosticTest.java @@ -0,0 +1,60 @@ +/* + * This file is a part of BSL Language Server. + * + * Copyright (c) 2018-2023 + * Alexey Sosnoviy , Nikita Fedkin 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 org.eclipse.lsp4j.Diagnostic; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static com.github._1c_syntax.bsl.languageserver.util.Assertions.assertThat; +import static com.github._1c_syntax.bsl.languageserver.util.TestUtils.getDocumentContextFromFile; + +class DisableAllDiagnosticsDiagnosticTest extends AbstractDiagnosticTest { + DisableAllDiagnosticsDiagnosticTest() { + super(DisableAllDiagnosticsDiagnostic.class); + } + + @Test + void test() { + + String filePath = "./src/test/resources/context/computer/DiagnosticIgnoranceComputerTest.bsl"; + final var documentContext = getDocumentContextFromFile(filePath); + + List diagnostics = getDiagnostics(documentContext); + + assertThat(diagnostics).hasSize(2); + assertThat(diagnostics, true) + .hasRange(0, 0, 12) + .hasRange(33, 0, 13); + } + + @Test + void testOnAndOff() { + + List diagnostics = getDiagnostics(); + + assertThat(diagnostics).hasSize(1); + assertThat(diagnostics, true) + .hasRange(9, 0, 13); + } +} diff --git a/src/test/resources/diagnostics/DisableAllDiagnosticsDiagnostic.bsl b/src/test/resources/diagnostics/DisableAllDiagnosticsDiagnostic.bsl new file mode 100644 index 00000000000..02695fb951d --- /dev/null +++ b/src/test/resources/diagnostics/DisableAllDiagnosticsDiagnostic.bsl @@ -0,0 +1,11 @@ +// + +Если Истина Тогда + //а + А = 0 +КонецЕсли; + +// BSLLS-on + +// BSLLS-выкл +// BSLLS-вкл