Skip to content

Commit 42ff682

Browse files
authored
Deprecate maligned, add govet fieldalignment as replacement (#1765)
1 parent 326d715 commit 42ff682

File tree

5 files changed

+63
-2
lines changed

5 files changed

+63
-2
lines changed

Diff for: .golangci.example.yml

+1
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ linters-settings:
297297
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
298298

299299
# enable or disable analyzers by name
300+
# run `go tool vet help` to see all analyzers
300301
enable:
301302
- atomicalign
302303
enable-all: false

Diff for: pkg/golinters/govet.go

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
_ "golang.org/x/tools/go/analysis/passes/ctrlflow" // unused, internal analyzer
1616
"golang.org/x/tools/go/analysis/passes/deepequalerrors"
1717
"golang.org/x/tools/go/analysis/passes/errorsas"
18+
"golang.org/x/tools/go/analysis/passes/fieldalignment"
1819
"golang.org/x/tools/go/analysis/passes/findcall"
1920
"golang.org/x/tools/go/analysis/passes/httpresponse"
2021
"golang.org/x/tools/go/analysis/passes/ifaceassert"
@@ -55,6 +56,7 @@ var (
5556
copylock.Analyzer,
5657
deepequalerrors.Analyzer,
5758
errorsas.Analyzer,
59+
fieldalignment.Analyzer,
5860
findcall.Analyzer,
5961
httpresponse.Analyzer,
6062
ifaceassert.Analyzer,

Diff for: pkg/lint/lintersdb/manager.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
238238
linter.NewConfig(golinters.NewMaligned()).
239239
WithLoadForGoAnalysis().
240240
WithPresets(linter.PresetPerformance).
241-
WithURL("https://github.com/mdempsky/maligned"),
241+
WithURL("https://github.com/mdempsky/maligned").
242+
Deprecated("The repository of the linter has been archived by the owner. Use govet 'fieldalignment' instead."),
242243
linter.NewConfig(golinters.NewDepguard()).
243244
WithLoadForGoAnalysis().
244245
WithPresets(linter.PresetStyle).

Diff for: test/testdata/govet_fieldalignment.go

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//args: -Egovet
2+
//config: linters-settings.govet.enable=fieldalignment
3+
package testdata
4+
5+
type gvfaGood struct {
6+
y int32
7+
x byte
8+
z byte
9+
}
10+
11+
type gvfaBad struct { // ERROR "struct of size 12 could be 8"
12+
x byte
13+
y int32
14+
z byte
15+
}
16+
17+
type gvfaPointerGood struct {
18+
P *int
19+
buf [1000]uintptr
20+
}
21+
22+
type gvfaPointerBad struct { // ERROR "struct with 8008 pointer bytes could be 8"
23+
buf [1000]uintptr
24+
P *int
25+
}
26+
27+
type gvfaPointerSorta struct {
28+
a struct {
29+
p *int
30+
q uintptr
31+
}
32+
b struct {
33+
p *int
34+
q [2]uintptr
35+
}
36+
}
37+
38+
type gvfaPointerSortaBad struct { // ERROR "struct with 32 pointer bytes could be 24"
39+
a struct {
40+
p *int
41+
q [2]uintptr
42+
}
43+
b struct {
44+
p *int
45+
q uintptr
46+
}
47+
}
48+
49+
type gvfaZeroGood struct {
50+
a [0]byte
51+
b uint32
52+
}
53+
54+
type gvfaZeroBad struct { // ERROR "struct of size 8 could be 4"
55+
a uint32
56+
b [0]byte
57+
}

Diff for: test/testdata/maligned.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//args: -Emaligned
1+
//args: -Emaligned --internal-cmd-test
22
package testdata
33

44
type BadAlignedStruct struct { // ERROR "struct of size 24 bytes could be of size 16 bytes"

0 commit comments

Comments
 (0)