1
0
mirror of https://github.com/mgechev/revive.git synced 2025-10-08 22:41:54 +02:00
Commit Graph

10 Commits

Author SHA1 Message Date
Oleksandr Redko
809768cffe chore: enable formatters in golangci-lint config (#1421) 2025-07-12 07:32:39 -07:00
AxiomaticFixedChimpanzee
b77bb1a9db fix: cognitive complexity nesting with if-else chains (#1268)
* test: prove bug in cognitive complexity rule

* fix: cognitive complexity nesting with if-else chains

Currently, an if-else chain will increase the nesting level and add the
nesting increment for every addition `else if` statement in an if-else
chain. This is incorrect behaviour; an `else if` statement should
increment complexity by 1 (regardless of current nesting level) and
leave the nesting level as-is.

For example, the following should yield a total complexity of 5:
```
for { // +1
    if a { // +2 (nesting = 1)
        foo()
    } else if b { // +1
        bar()
    } else if c { // +1
        baz()
    }
}
```

but the current implementation incorrectly increments the nesting level
with each `else if` and adds the nesting increment where it shouldn't:
```
for { // +1
    if a { // +2 (nesting = 1)
        foo()
    } else if b { // +3 (nesting = 2)
        bar()
    } else if c { // +4 (nesting = 3)
        baz()
    }
}
```
2025-03-13 08:31:26 +01:00
Oleksandr Redko
395f7902d3 refactor: replace failure Category raw string with constant (#1196)
* refactor: replace Category raw strings with constants

* Add type FailureCategory; add comments for constants
2025-01-18 12:16:19 +01:00
Denis Voytyuk
4b2c76e8b9 chore: cleanup code in rules (#1197) 2024-12-31 12:33:51 +01:00
ccoVeille
3d1115dacd refactor: rule configuration and error management (#1185)
* refactor: avoid running rule once configuration failed

* refactor: remove deep-exit in lint/linter.go
2024-12-13 21:38:46 +01:00
Marcin Federowicz
9b15f3fcb6 refactor: replace panic with error in rules (#1126)
Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
Co-authored-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2024-12-11 19:35:58 +01:00
Oleksandr Redko
d181862481 docs: fix rule descriptions (#1147) 2024-12-01 16:44:41 +01:00
Oleksandr Redko
bb9e681da6 cognitive-complexity: handle direct recursion (#1149) 2024-12-01 12:16:06 +01:00
Oleksandr Redko
3378f7033b refactor: replace mutex with sync.Once for rule configuration (#1118) 2024-11-15 12:03:59 +01:00
Oleksandr Redko
be95bfa705 refactor: rename files to follow Go convention 2024-11-11 19:31:18 +01:00