Skip to content
Open
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
27 changes: 27 additions & 0 deletions docs/diagnostics/MissingSuppressionComment.md
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`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не увидел, где реализуется эта особенность

- Проверяет как русские (`выкл`), так и английские (`off`) формы
27 changes: 27 additions & 0 deletions docs/en/diagnostics/MissingSuppressionComment.md
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
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(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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("//")) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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());
}
}
}

}
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
diagnosticMessage=Укажите причину подавления диагностики в комментарии
diagnosticName=Подавление диагностики без пояснения
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
}
}
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

// обычный комментарий
Процедура Тест()
КонецПроцедуры
Loading