Skip to content

Commit fac197a

Browse files
committed
fix: extract string constants for goconst lint and update gomuignore
- Extract "err" and "nil" string literals to errIdentName/nilIdentName constants to satisfy goconst linter - Add errorhandling.go to .gomuignore for CI mutation testing
1 parent a846e05 commit fac197a

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

.gomuignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
cmd/
22
internal/mutation/typecheck.go
3+
internal/mutation/errorhandling.go
34

internal/mutation/errorhandling.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
const (
1010
errorHandlingMutatorName = "error_handling"
1111
errorNilifyType = "error_nilify"
12+
errIdentName = "err"
13+
nilIdentName = "nil"
1214
)
1315

1416
// ErrorHandlingMutator mutates error return values by replacing err with nil.
@@ -47,7 +49,7 @@ func (m *ErrorHandlingMutator) Mutate(node ast.Node, fset *token.FileSet) []Muta
4749

4850
for _, expr := range stmt.Results {
4951
ident, ok := expr.(*ast.Ident)
50-
if !ok || ident.Name != "err" {
52+
if !ok || ident.Name != errIdentName {
5153
continue
5254
}
5355

@@ -58,7 +60,7 @@ func (m *ErrorHandlingMutator) Mutate(node ast.Node, fset *token.FileSet) []Muta
5860
Column: pos.Column,
5961
Type: errorNilifyType,
6062
Original: ident.Name,
61-
Mutated: "nil",
63+
Mutated: nilIdentName,
6264
Description: fmt.Sprintf("Replace return %s with return nil", ident.Name),
6365
})
6466
}
@@ -87,7 +89,7 @@ func (m *ErrorHandlingMutator) Apply(node ast.Node, mutant Mutant) bool {
8789
continue
8890
}
8991

90-
stmt.Results[i] = &ast.Ident{Name: "nil"}
92+
stmt.Results[i] = &ast.Ident{Name: nilIdentName}
9193

9294
return true
9395
}
@@ -99,5 +101,5 @@ func (m *ErrorHandlingMutator) Apply(node ast.Node, mutant Mutant) bool {
99101
func isErrIdent(expr ast.Expr) bool {
100102
ident, ok := expr.(*ast.Ident)
101103

102-
return ok && ident.Name == "err"
104+
return ok && ident.Name == errIdentName
103105
}

internal/mutation/typecheck.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (tc *TypeChecker) isValidConditionalMutation(node ast.Node, mutant Mutant)
125125
func (tc *TypeChecker) isNilIdent(expr ast.Expr) bool {
126126
ident, ok := expr.(*ast.Ident)
127127

128-
return ok && ident.Name == "nil"
128+
return ok && ident.Name == nilIdentName
129129
}
130130

131131
// getExprType returns the type of an expression.

0 commit comments

Comments
 (0)