Skip to content

Commit d1bdbf3

Browse files
Update linter config
1 parent 3d131fe commit d1bdbf3

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

.golangci.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ linters:
3636
- nestif # cyclop does this
3737
- nlreturn # Similar to wsl, I think best left to judgement
3838
- nonamedreturns # Named returns are often helpful, it's naked returns that are the issue
39+
- noinlineerr # This is more readable in some cases
3940
- paralleltest # I've never had Go tests take longer than a few seconds, it's fine
4041
- unparam # gopls is better and more subtle
4142
- varnamelen # Lots of false positives of things that are fine
@@ -56,8 +57,8 @@ linters:
5657

5758
- path: examples
5859
linters:
59-
- gosec
6060
- mnd
61+
- gosec
6162

6263
settings:
6364
cyclop:
@@ -157,7 +158,12 @@ linters:
157158
disabled: true # predeclared does this
158159

159160
- name: unhandled-error
160-
disabled: true # errcheck does this
161+
arguments:
162+
- fmt\.(Fp|P)rint(ln|f)?
163+
- strings.Builder.Write(String|Byte)?
164+
- bytes.Buffer.Write(String|Byte)?
165+
- bytes.Buffer.WriteTo?
166+
- os.File.Close?
161167

162168
- name: flag-parameter
163169
disabled: true # As far as I can work out this just doesn't like bools

examples/prefix/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"math/rand/v2"
5+
"net/http"
56
"os"
67
"time"
78

@@ -17,9 +18,9 @@ func main() {
1718

1819
prefixed.Warn("Slow endpoint", "endpoint", "users/slow", "duration", 10*time.Second)
1920
sleep()
20-
prefixed.Info("Response from get repos", "status", 200, "duration", 500*time.Millisecond)
21+
prefixed.Info("Response from get repos", "status", http.StatusOK, "duration", 500*time.Millisecond)
2122
sleep()
22-
prefixed.Error("Response from something else", "status", 400, "duration", 33*time.Millisecond)
23+
prefixed.Error("Response from something else", "status", http.StatusBadRequest, "duration", 33*time.Millisecond)
2324
}
2425

2526
func sleep() {

log.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// intended to be human readable and easy on the eye with a good choice of colours, ideal for command line
55
// applications that have a --debug or --verbose flag that enables extra logging.
66
//
7-
// log emphasis simplicity and efficiency so there aren't too many knobs to twiddle, you just get a consistent,
7+
// log emphasises simplicity and efficiency so there aren't too many knobs to twiddle, you just get a consistent,
88
// easy to use, simple logger with minimal overhead.
99
package log // import "go.followtheprocess.codes/log"
1010

@@ -106,6 +106,7 @@ func (l *Logger) With(kv ...any) *Logger {
106106
sub := l.clone()
107107

108108
sub.kv = slices.Concat(sub.kv, kv)
109+
109110
return sub
110111
}
111112

@@ -116,6 +117,7 @@ func (l *Logger) Prefixed(prefix string) *Logger {
116117
sub := l.clone()
117118

118119
sub.prefix = prefix
120+
119121
return sub
120122
}
121123

@@ -155,15 +157,18 @@ func (l *Logger) log(level Level, msg string, kv ...any) {
155157
buf.WriteString(timestampStyle.Text(l.timeFunc().Format(l.timeFormat)))
156158
buf.WriteByte(' ')
157159
buf.WriteString(level.styled())
160+
158161
if l.prefix != "" {
159162
buf.WriteString(" " + prefixStyle.Text(l.prefix))
160163
}
164+
161165
buf.WriteByte(':')
162166
buf.WriteByte(' ')
163167
buf.WriteString(msg)
164168

165169
if numKVs := len(l.kv) + len(kv); numKVs != 0 {
166170
kvs := make([]any, 0, numKVs)
171+
167172
kvs = append(kvs, l.kv...)
168173
if len(kvs)%2 != 0 {
169174
kvs = append(kvs, missingValue)
@@ -176,6 +181,7 @@ func (l *Logger) log(level Level, msg string, kv ...any) {
176181

177182
for i := 0; i < len(kvs); i += 2 {
178183
buf.WriteByte(' ')
184+
179185
key := keyStyle.Sprint(kvs[i])
180186
val := fmt.Sprintf("%+v", kvs[i+1])
181187

@@ -194,6 +200,7 @@ func (l *Logger) log(level Level, msg string, kv ...any) {
194200
// WriteTo drains the buffer
195201
l.mu.Lock()
196202
defer l.mu.Unlock()
203+
197204
buf.WriteTo(l.w) //nolint: errcheck // Just like printing
198205
}
199206

@@ -226,6 +233,7 @@ var bufPool = sync.Pool{
226233
func getBuffer() *bytes.Buffer {
227234
buf := bufPool.Get().(*bytes.Buffer) //nolint:revive,errcheck,forcetypeassert // We are in total control of this
228235
buf.Reset()
236+
229237
return buf
230238
}
231239

log_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,17 +189,21 @@ func TestRace(t *testing.T) {
189189

190190
var wg sync.WaitGroup
191191
wg.Add(n)
192+
192193
for i := range n {
193194
go func(wg *sync.WaitGroup, i int) {
194195
defer wg.Done()
196+
195197
logger.Info(fmt.Sprintf("Something: %d", i))
196198
}(&wg, i)
197199
}
198200

199201
wg.Add(n)
202+
200203
for i := range n {
201204
go func(wg *sync.WaitGroup, i int) {
202205
defer wg.Done()
206+
203207
sub.Info(fmt.Sprintf("Other: %d", i))
204208
}(&wg, i)
205209
}

0 commit comments

Comments
 (0)