-
Notifications
You must be signed in to change notification settings - Fork 116
Неиспользуемая локальная переменная #920
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
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f73d89a
первая итерация
qtLex 59e91cf
Добавил учет параметров методов
qtLex 6716735
лицензия и дока
qtLex 51f70da
Переделал на использование символов
qtLex eca93cb
Убрал табы
qtLex 5fc1b29
precommit
qtLex c86caa6
Параметры больше не воспринимаются как переменные
qtLex a729c64
Подправил ошибку определения использования
qtLex 69042a4
Исправил определение переменной если заполняется свойство
qtLex 5aea25b
rebase and fix
qtLex 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,28 @@ | ||
# Неиспользуемая локальная переменная (UnusedLocalVariable) | ||
|
||
| Тип | Поддерживаются<br/>языки | Важность | Включена<br/>по умолчанию | Время на<br/>исправление (мин) | Тэги | | ||
| :-: | :-: | :-: | :-: | :-: | :-: | | ||
| `Дефект кода` | `BSL`<br/>`OS` | `Важный` | `Да` | `1` | `brainoverload`<br/>`badpractice` | | ||
|
||
<!-- Блоки выше заполняются автоматически, не трогать --> | ||
## Описание диагностики | ||
Программные модули не должны иметь неиспользуемых переменных. | ||
|
||
Если локальная переменная объявлена, но не используется, это мертвый код, который следует удалить. | ||
Это улучшит удобство обслуживания, поскольку разработчики не будут удивляться, для чего используется переменная. | ||
|
||
## Сниппеты | ||
|
||
<!-- Блоки ниже заполняются автоматически, не трогать --> | ||
### Экранирование кода | ||
|
||
```bsl | ||
// BSLLS:UnusedLocalVariable-off | ||
// BSLLS:UnusedLocalVariable-on | ||
``` | ||
|
||
### Параметр конфигурационного файла | ||
|
||
```json | ||
"UnusedLocalVariable": false | ||
``` |
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
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,28 @@ | ||
# Unused local variable (UnusedLocalVariable) | ||
|
||
| Type | Scope | Severity | Activated<br/>by default | Minutes<br/>to fix | Tags | | ||
| :-: | :-: | :-: | :-: | :-: | :-: | | ||
| `Code smell` | `BSL`<br/>`OS` | `Major` | `Yes` | `1` | `brainoverload`<br/>`badpractice` | | ||
|
||
<!-- Блоки выше заполняются автоматически, не трогать --> | ||
## Description | ||
Unused local variables should be removed | ||
|
||
If a local variable is declared but not used, it is dead code and should be removed. | ||
Doing so will improve maintainability because developers will not wonder what the variable is used for. | ||
|
||
## Snippets | ||
|
||
<!-- Блоки ниже заполняются автоматически, не трогать --> | ||
### Diagnostic ignorance in code | ||
|
||
```bsl | ||
// BSLLS:UnusedLocalVariable-off | ||
// BSLLS:UnusedLocalVariable-on | ||
``` | ||
|
||
### Parameter for config | ||
|
||
```json | ||
"UnusedLocalVariable": false | ||
``` |
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
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
37 changes: 37 additions & 0 deletions
37
src/main/java/com/github/_1c_syntax/bsl/languageserver/context/symbol/Usage.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,37 @@ | ||
/* | ||
* This file is a part of BSL Language Server. | ||
* | ||
* Copyright © 2018-2020 | ||
* Alexey Sosnoviy <[email protected]>, Nikita Gryzlov <[email protected]> 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.context.symbol; | ||
|
||
import org.eclipse.lsp4j.Range; | ||
|
||
public interface Usage { | ||
|
||
Range getRange(); | ||
|
||
Kind getKind(); | ||
|
||
enum Kind { | ||
OTHER, | ||
OBJECT | ||
} | ||
|
||
} |
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
35 changes: 35 additions & 0 deletions
35
src/main/java/com/github/_1c_syntax/bsl/languageserver/context/symbol/VariableUsage.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,35 @@ | ||
/* | ||
* This file is a part of BSL Language Server. | ||
* | ||
* Copyright © 2018-2020 | ||
* Alexey Sosnoviy <[email protected]>, Nikita Gryzlov <[email protected]> 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.context.symbol; | ||
|
||
import lombok.Builder; | ||
import lombok.Value; | ||
import org.eclipse.lsp4j.Range; | ||
|
||
@Value | ||
@Builder | ||
public class VariableUsage implements Usage { | ||
|
||
Range range; | ||
Kind kind; | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
...a/com/github/_1c_syntax/bsl/languageserver/diagnostics/UnusedLocalVariableDiagnostic.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,64 @@ | ||
/* | ||
* This file is a part of BSL Language Server. | ||
* | ||
* Copyright © 2018-2020 | ||
* Alexey Sosnoviy <[email protected]>, Nikita Gryzlov <[email protected]> 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.context.symbol.VariableSymbol; | ||
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo; | ||
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; | ||
import com.github._1c_syntax.mdclasses.metadata.additional.ModuleType; | ||
|
||
@DiagnosticMetadata( | ||
type = DiagnosticType.CODE_SMELL, | ||
severity = DiagnosticSeverity.MAJOR, | ||
minutesToFix = 1, | ||
tags = { | ||
DiagnosticTag.BRAINOVERLOAD, | ||
DiagnosticTag.BADPRACTICE | ||
}, | ||
modules = { | ||
ModuleType.CommandModule, | ||
ModuleType.CommonModule, | ||
ModuleType.ManagerModule, | ||
ModuleType.ValueManagerModule, | ||
ModuleType.SessionModule, | ||
} | ||
) | ||
public class UnusedLocalVariableDiagnostic extends AbstractDiagnostic { | ||
|
||
public UnusedLocalVariableDiagnostic(DiagnosticInfo info) { | ||
super(info); | ||
} | ||
|
||
@Override | ||
protected void check() { | ||
documentContext | ||
.getSymbolTree() | ||
.getChildrenFlat(VariableSymbol.class) | ||
.stream() | ||
.filter(v -> v.getUsages().isEmpty()) | ||
.filter(v -> !v.isExport()) | ||
.forEach(v -> diagnosticStorage.addDiagnostic(v.getRange())); | ||
} | ||
} |
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
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.
предлагаю List вместо ArrayList
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.
Обязательно использовать
List
)