Skip to content

Commit e841150

Browse files
authored
chore: add forbidgo linter (italia#244)
1 parent 1d792f9 commit e841150

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

.golangci.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ linters:
3737
- err113
3838
- errname
3939
- errorlint
40-
- forbidigo
4140
- forcetypeassert
4241
- funlen
4342
- gochecknoglobals
@@ -90,6 +89,10 @@ linters:
9089
os-setenv: true
9190
os-create-temp: true
9291
os-temp-dir: false
92+
forbidigo:
93+
forbid:
94+
- pattern: ^(fmt\.Print(|f|ln)|print|println)$
95+
- pattern: ^panic$
9396

9497
exclusions:
9598
generated: lax
@@ -102,6 +105,12 @@ linters:
102105
- third_party$
103106
- builtin$
104107
- examples$
108+
rules:
109+
# Allow prints and panics in publiccode-parser/, as it's the
110+
# CLI tool.
111+
- path: publiccode-parser/
112+
linters:
113+
- forbidigo
105114

106115
formatters:
107116
enable:

validators/common.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func isHTTPURL(fl validator.FieldLevel) bool {
5151
return err == nil
5252
}
5353

54+
//nolint:forbidigo // If we hit this, it's a programming error caught at runtime, it's good to panic.
5455
panic(fmt.Sprintf("Bad field type for %T. Must be implement fmt.Stringer", fl.Field().Interface()))
5556
}
5657

@@ -65,6 +66,7 @@ func isURL(fl validator.FieldLevel) bool {
6566
return err == nil
6667
}
6768

69+
//nolint:forbidigo // If we hit this, it's a programming error caught at runtime, it's good to panic.
6870
panic(fmt.Sprintf("Bad field type for %T. Must be implement fmt.Stringer", fl.Field().Interface()))
6971
}
7072

@@ -73,6 +75,7 @@ func bcp47_keys(fl validator.FieldLevel) bool {
7375
validate := validator.New(validator.WithRequiredStructEnabled())
7476

7577
if fl.Field().Kind() != reflect.Map {
78+
//nolint:forbidigo // If we hit this, it's a programming error caught at runtime, it's good to panic.
7679
panic(fmt.Sprintf("Bad field type for %T. Must be a map", fl.Field().Interface()))
7780
}
7881

0 commit comments

Comments
 (0)