-
Notifications
You must be signed in to change notification settings - Fork 137
feat: new diagnostic MissingSuppressionComment #4400
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
Open
pravets
wants to merge
1
commit into
1c-syntax:develop
Choose a base branch
from
pravets:feat/new-diagnostic-missing-suppression-comment
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,27 @@ | ||
| # Подавление диагностики без пояснения (MissingSuppressionComment) | ||
|
|
||
| <!-- Блоки выше заполняются автоматически, не трогать --> | ||
| ## Описание диагностики | ||
|
|
||
| Комментарий подавления диагностики (`// BSLLS:ИмяДиагностики-off` или `// BSLLS-off`) не содержит пояснения причины. Разработчики, читающие код позже, не понимают, почему диагностика была отключена и можно ли её вернуть. | ||
|
|
||
| ## Примеры | ||
|
|
||
| ### Неправильно | ||
|
|
||
| ```bsl | ||
| // BSLLS:DeprecatedMethodCall-off | ||
| Процедура СтарыйКод() | ||
| ``` | ||
|
|
||
| ### Правильно | ||
|
|
||
| ```bsl | ||
| // BSLLS:DeprecatedMethodCall-off — легаси, трогать нельзя до версии 3.0 | ||
| Процедура СтарыйКод() | ||
| ``` | ||
|
|
||
| ## Особенности | ||
|
|
||
| - Диагностика сама **не подавляема** через `// BSLLS:MissingSuppressionComment-off` | ||
| - Проверяет как русские (`выкл`), так и английские (`off`) формы | ||
This file contains hidden or 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,27 @@ | ||
| # Diagnostic suppression without explanation (MissingSuppressionComment) | ||
|
|
||
| <!-- Блоки выше заполняются автоматически, не трогать --> | ||
| ## Diagnostic description | ||
|
|
||
| A diagnostic suppression comment (`// BSLLS:DiagnosticName-off` or `// BSLLS-off`) lacks an explanation. Future developers won't understand why the diagnostic was disabled or whether it can be re-enabled. | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Incorrect | ||
|
|
||
| ```bsl | ||
| // BSLLS:DeprecatedMethodCall-off | ||
| Procedure OldCode() | ||
| ``` | ||
|
|
||
| ### Correct | ||
|
|
||
| ```bsl | ||
| // BSLLS:DeprecatedMethodCall-off — legacy, do not touch until v3.0 | ||
| Procedure OldCode() | ||
| ``` | ||
|
|
||
| ## Notes | ||
|
|
||
| - This diagnostic is **not suppressable** via `// BSLLS:MissingSuppressionComment-off` | ||
| - Supports both Russian (`выкл`) and English (`off`) forms |
85 changes: 85 additions & 0 deletions
85
...github/_1c_syntax/bsl/languageserver/diagnostics/MissingSuppressionCommentDiagnostic.java
This file contains hidden or 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,85 @@ | ||
| /* | ||
| * This file is a part of BSL Language Server. | ||
| * | ||
| * Copyright (c) 2018-2026 | ||
| * 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.Ranges; | ||
| import com.github._1c_syntax.bsl.parser.BSLLexer; | ||
|
|
||
| import java.util.regex.Pattern; | ||
|
|
||
| /** | ||
| * Диагностика-матрёшка: проверяет, что у комментариев подавления диагностик | ||
| * {@code // BSLLS:...-off} есть пояснение причины. | ||
| * <p> | ||
| * Голое подавление без объяснения — плохая практика: следующие разработчики | ||
| * не понимают, почему диагностика отключена и можно ли её вернуть. | ||
| * <p> | ||
| * Сама диагностика не подавляема. | ||
| */ | ||
| @DiagnosticMetadata( | ||
| type = DiagnosticType.CODE_SMELL, | ||
| severity = DiagnosticSeverity.MAJOR, | ||
| scope = DiagnosticScope.BSL, | ||
| minutesToFix = 1, | ||
| tags = { | ||
| DiagnosticTag.BADPRACTICE, | ||
| DiagnosticTag.SUSPICIOUS | ||
| } | ||
| ) | ||
| public class MissingSuppressionCommentDiagnostic extends AbstractDiagnostic { | ||
|
|
||
| /** Строка начинается с {@code // BSLLS:...-off} или {@code // BSLLS-off}. */ | ||
| private static final Pattern SUPPRESSION_PATTERN = Pattern.compile( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. возможно вместо повторного парсинга имеет смысл заглянуть в DiagnosticIgnoranceData |
||
| "^\\s*//\\s*BSLLS(?::\\w+)?\\s*-\\s*(?:off|выкл)", | ||
| Pattern.CASE_INSENSITIVE | ||
| ); | ||
|
|
||
| /** Голое подавление: после {@code -off} нет поясняющего текста. */ | ||
| private static final Pattern BARE_SUPPRESSION_PATTERN = Pattern.compile( | ||
| "^\\s*//\\s*BSLLS(?::\\w+)?\\s*-\\s*(?:off|выкл)\\s*$", | ||
| Pattern.CASE_INSENSITIVE | ||
| ); | ||
|
|
||
| @Override | ||
| public void check() { | ||
| var content = documentContext.getContentList(); | ||
|
|
||
| for (int i = 0; i < content.length; i++) { | ||
| var line = content[i].stripTrailing(); | ||
| if (!line.stripLeading().startsWith("//")) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А почему висячие комментарии не проверяются? |
||
| continue; | ||
| } | ||
|
|
||
| if (SUPPRESSION_PATTERN.matcher(line).find() | ||
| && BARE_SUPPRESSION_PATTERN.matcher(line).matches()) { | ||
| diagnosticStorage.addDiagnostic( | ||
| i, 0, i, line.length()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
2 changes: 2 additions & 0 deletions
2
...c_syntax/bsl/languageserver/diagnostics/MissingSuppressionCommentDiagnostic_en.properties
This file contains hidden or 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,2 @@ | ||
| diagnosticMessage=Add an explanation for the diagnostic suppression comment | ||
| diagnosticName=Diagnostic suppression without explanation |
2 changes: 2 additions & 0 deletions
2
...c_syntax/bsl/languageserver/diagnostics/MissingSuppressionCommentDiagnostic_ru.properties
This file contains hidden or 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,2 @@ | ||
| diagnosticMessage=Укажите причину подавления диагностики в комментарии | ||
| diagnosticName=Подавление диагностики без пояснения |
49 changes: 49 additions & 0 deletions
49
...ub/_1c_syntax/bsl/languageserver/diagnostics/MissingSuppressionCommentDiagnosticTest.java
This file contains hidden or 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,49 @@ | ||
| /* | ||
| * This file is a part of BSL Language Server. | ||
| * | ||
| * Copyright (c) 2018-2026 | ||
| * 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 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; | ||
|
|
||
| class MissingSuppressionCommentDiagnosticTest | ||
| extends AbstractDiagnosticTest<MissingSuppressionCommentDiagnostic> { | ||
|
|
||
| MissingSuppressionCommentDiagnosticTest() { | ||
| super(MissingSuppressionCommentDiagnostic.class); | ||
| } | ||
|
|
||
| @Test | ||
| void test() { | ||
| List<Diagnostic> diagnostics = getDiagnostics(); | ||
|
|
||
| // Срабатывает на голых подавлениях без пояснения | ||
| // Не срабатывает на подавлениях с пояснением | ||
| assertThat(diagnostics).hasSize(2); | ||
| assertThat(diagnostics, true) | ||
| .hasRange(0, 0, 0, 12) // BSLLS-off | ||
| .hasRange(4, 0, 4, 33); // BSLLS:DeprecatedMethodCall-off | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/test/resources/diagnostics/MissingSuppressionCommentDiagnostic.bsl
This file contains hidden or 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,11 @@ | ||
| // BSLLS-off | ||
|
|
||
| // BSLLS-off — legacy code, do not touch | ||
|
|
||
| // BSLLS:DeprecatedMethodCall-off | ||
|
|
||
| // BSLLS:DeprecatedMethodCall-off — too many changes needed | ||
|
|
||
| // обычный комментарий | ||
| Процедура Тест() | ||
| КонецПроцедуры |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не увидел, где реализуется эта особенность