1
0
mirror of https://github.com/mgechev/revive.git synced 2025-10-30 23:37:49 +02:00
This commit is contained in:
chavacava
2025-09-19 07:38:09 +02:00
parent 4f4d390e67
commit 7359bf9a2e
2 changed files with 35 additions and 0 deletions

View File

@@ -591,6 +591,7 @@ List of all available rules. The rules ported from `golint` are left unchanged a
| [`unexported-naming`](./RULES_DESCRIPTIONS.md#unexported-naming) | n/a | Warns on wrongly named un-exported symbols | no | no |
| [`unexported-return`](./RULES_DESCRIPTIONS.md#unexported-return) | n/a | Warns when a public return is from unexported type. | yes | yes |
| [`unhandled-error`](./RULES_DESCRIPTIONS.md#unhandled-error) | []string | Warns on unhandled errors returned by function calls | no | yes |
| [`unnecessary-conditional`](./RULES_DESCRIPTIONS.md#unnecessary-conditional) | n/a | Identifies `if-else` statements that can be replaced by simpler statements | no | no |
| [`unnecessary-format`](./RULES_DESCRIPTIONS.md#unnecessary-format) | n/a | Identifies calls to formatting functions where the format string does not contain any formatting verbs | no | no |
| [`unnecessary-stmt`](./RULES_DESCRIPTIONS.md#unnecessary-stmt) | n/a | Suggests removing or simplifying unnecessary statements | no | no |
| [`unreachable-code`](./RULES_DESCRIPTIONS.md#unreachable-code) | n/a | Warns on unreachable code | no | no |

View File

@@ -87,6 +87,7 @@ List of all available rules.
- [unexported-naming](#unexported-naming)
- [unexported-return](#unexported-return)
- [unhandled-error](#unhandled-error)
- [unnecessary-conditional](#unnecessary-conditional)
- [unnecessary-format](#unnecessary-format)
- [unnecessary-stmt](#unnecessary-stmt)
- [unreachable-code](#unreachable-code)
@@ -1499,6 +1500,39 @@ arguments = [
]
```
## unnecessary-conditional
_Description_: Detects unnecessary `if-else` statements that return or assign a boolean value
based on a condition and suggests a simplified, direct return or assignment.
The `if-else` block is redundant because the condition itself is already a boolean expression.
The simplified version is immediately clearer, more idiomatic, and reduces cognitive load for the reader.
### Examples (unnecessary-conditional)
```go
if y <= 0 {
z = true
} else {
z = false
}
if x > 10 {
return false
} else {
return true
}
```
Fixed code:
```go
z = y <= 0
return x <= 10
```
_Configuration_: N/A
## unnecessary-format
_Description_: This rule identifies calls to formatting functions where the format string does not contain any formatting verbs