mirror of
				https://github.com/mgechev/revive.git
				synced 2025-10-30 23:37:49 +02:00 
			
		
		
		
	add doc
This commit is contained in:
		| @@ -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   | | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user