1
0
mirror of https://github.com/mgechev/revive.git synced 2025-11-23 22:04:49 +02:00

feature: new rule identical-switch-conditions (#1451)

This commit is contained in:
chavacava
2025-08-02 08:04:18 +02:00
committed by GitHub
parent 68ac5514f5
commit 3f4591cd9a
6 changed files with 154 additions and 0 deletions

55
testdata/identical_switch_conditions.go vendored Normal file
View File

@@ -0,0 +1,55 @@
package fixtures
func enforceSwitchStyle3() {
switch expression { // skipt tagged switch
case value:
default:
}
switch {
case a > 0, a < 0:
case a == 0:
case a < 0: // MATCH /case clause at line 11 has the same condition/
default:
}
switch {
case a > 0, a < 0, a > 0: // MATCH /case clause at line 18 has the same condition/
case a == 0:
case a < 0: // MATCH /case clause at line 18 has the same condition/
default:
}
switch something {
case 1:
switch {
case a > 0, a < 0, a > 0: // MATCH /case clause at line 27 has the same condition/
case a == 0:
}
default:
}
switch {
case a == 0:
switch {
case a > 0, a < 0, a > 0: // MATCH /case clause at line 36 has the same condition/
case a == 0:
}
default:
}
switch {
case lnOpts.IsSocketOpts():
// ...
// check for timeout
fallthrough
case lnOpts.IsTimeout(), lnOpts.IsSocketOpts(): // MATCH /case clause at line 43 has the same condition/
// timeout listener with socket options.
// ...
case lnOpts.IsTimeout(): // MATCH /case clause at line 47 has the same condition/
// ...
default:
// ...
}
}