diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2018-07-31 12:42:52 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-07-31 12:42:52 +0200 |
| commit | 50c3709eb0671b6a4d7cfb89775746cff7f6d146 (patch) | |
| tree | ef2a55392576562cd8309a508a3168da21bac48b /pkg | |
| parent | 31549f438fe16b1f0919a86a05960ce65b3df097 (diff) | |
.gometalinter: reduce dupl threshold
Reduce dupl threshold from 63 to 60 and fix violations.
Update #538
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/ast/clone.go | 76 | ||||
| -rw-r--r-- | pkg/report/akaros.go | 34 | ||||
| -rw-r--r-- | pkg/report/gvisor.go | 35 | ||||
| -rw-r--r-- | pkg/report/report.go | 37 |
4 files changed, 80 insertions, 102 deletions
diff --git a/pkg/ast/clone.go b/pkg/ast/clone.go index 072425115..13a603ba8 100644 --- a/pkg/ast/clone.go +++ b/pkg/ast/clone.go @@ -47,15 +47,11 @@ func (n *Define) Clone() Node { } func (n *Resource) Clone() Node { - var values []*Int - for _, v := range n.Values { - values = append(values, v.Clone().(*Int)) - } return &Resource{ Pos: n.Pos, Name: n.Name.Clone().(*Ident), Base: n.Base.Clone().(*Type), - Values: values, + Values: cloneInts(n.Values), } } @@ -82,10 +78,6 @@ func (n *TypeDef) Clone() Node { } func (n *Call) Clone() Node { - var args []*Field - for _, a := range n.Args { - args = append(args, a.Clone().(*Field)) - } var ret *Type if n.Ret != nil { ret = n.Ret.Clone().(*Type) @@ -95,43 +87,27 @@ func (n *Call) Clone() Node { Name: n.Name.Clone().(*Ident), CallName: n.CallName, NR: n.NR, - Args: args, + Args: cloneFields(n.Args), Ret: ret, } } func (n *Struct) Clone() Node { - var fields []*Field - for _, f := range n.Fields { - fields = append(fields, f.Clone().(*Field)) - } - var attrs []*Type - for _, a := range n.Attrs { - attrs = append(attrs, a.Clone().(*Type)) - } - var comments []*Comment - for _, c := range n.Comments { - comments = append(comments, c.Clone().(*Comment)) - } return &Struct{ Pos: n.Pos, Name: n.Name.Clone().(*Ident), - Fields: fields, - Attrs: attrs, - Comments: comments, + Fields: cloneFields(n.Fields), + Attrs: cloneTypes(n.Attrs), + Comments: cloneComments(n.Comments), IsUnion: n.IsUnion, } } func (n *IntFlags) Clone() Node { - var values []*Int - for _, v := range n.Values { - values = append(values, v.Clone().(*Int)) - } return &IntFlags{ Pos: n.Pos, Name: n.Name.Clone().(*Ident), - Values: values, + Values: cloneInts(n.Values), } } @@ -172,10 +148,6 @@ func (n *Int) Clone() Node { } func (n *Type) Clone() Node { - var args []*Type - for _, a := range n.Args { - args = append(args, a.Clone().(*Type)) - } return &Type{ Pos: n.Pos, Value: n.Value, @@ -188,20 +160,44 @@ func (n *Type) Clone() Node { Value2: n.Value2, Value2Fmt: n.Value2Fmt, Ident2: n.Ident2, - Args: args, + Args: cloneTypes(n.Args), } } func (n *Field) Clone() Node { - var comments []*Comment - for _, c := range n.Comments { - comments = append(comments, c.Clone().(*Comment)) - } return &Field{ Pos: n.Pos, Name: n.Name.Clone().(*Ident), Type: n.Type.Clone().(*Type), NewBlock: n.NewBlock, - Comments: comments, + Comments: cloneComments(n.Comments), + } +} + +func cloneFields(list []*Field) (res []*Field) { + for _, n := range list { + res = append(res, n.Clone().(*Field)) + } + return +} + +func cloneInts(list []*Int) (res []*Int) { + for _, n := range list { + res = append(res, n.Clone().(*Int)) + } + return +} + +func cloneTypes(list []*Type) (res []*Type) { + for _, n := range list { + res = append(res, n.Clone().(*Type)) + } + return +} + +func cloneComments(list []*Comment) (res []*Comment) { + for _, n := range list { + res = append(res, n.Clone().(*Comment)) } + return } diff --git a/pkg/report/akaros.go b/pkg/report/akaros.go index cd6fb6a1c..6e6e51bc9 100644 --- a/pkg/report/akaros.go +++ b/pkg/report/akaros.go @@ -33,39 +33,11 @@ func (ctx *akaros) ContainsCrash(output []byte) bool { } func (ctx *akaros) Parse(output []byte) *Report { - rep := &Report{ - Output: output, - } - var oops *oops - for pos := 0; pos < len(output); { - next := bytes.IndexByte(output[pos:], '\n') - if next != -1 { - next += pos - } else { - next = len(output) - } - line := output[pos:next] - for _, oops1 := range akarosOopses { - match := matchOops(line, oops1, ctx.ignores) - if match != -1 { - oops = oops1 - rep.StartPos = pos - break - } - } - if oops != nil { - break - } - pos = next + 1 - } - if oops == nil { + rep := simpleLineParser(output, akarosOopses, akarosStackParams, ctx.ignores) + if rep == nil { return nil } - title, corrupted, _ := extractDescription(output[rep.StartPos:], oops, akarosStackParams) - rep.Title = title - rep.Report = ctx.minimizeReport(output[rep.StartPos:]) - rep.Corrupted = corrupted != "" - rep.CorruptedReason = corrupted + rep.Report = ctx.minimizeReport(rep.Report) return rep } diff --git a/pkg/report/gvisor.go b/pkg/report/gvisor.go index 5f6a273cf..5086f285e 100644 --- a/pkg/report/gvisor.go +++ b/pkg/report/gvisor.go @@ -35,39 +35,12 @@ func (ctx *gvisor) ContainsCrash(output []byte) bool { } func (ctx *gvisor) Parse(output []byte) *Report { - rep := &Report{ - Output: output, - } - var oops *oops - for pos := 0; pos < len(output); { - next := bytes.IndexByte(output[pos:], '\n') - if next != -1 { - next += pos - } else { - next = len(output) - } - line := output[pos:next] - for _, oops1 := range gvisorOopses { - match := matchOops(line, oops1, ctx.ignores) - if match != -1 { - oops = oops1 - rep.StartPos = pos - break - } - } - if oops != nil { - break - } - pos = next + 1 - } - if oops == nil { + rep := simpleLineParser(output, gvisorOopses, nil, ctx.ignores) + if rep == nil { return nil } - title, corrupted, _ := extractDescription(output[rep.StartPos:], oops, nil) - rep.Title = replaceTable(gvisorTitleReplacement, title) - rep.Report = ctx.shortenReport(output[rep.StartPos:]) - rep.Corrupted = corrupted != "" - rep.CorruptedReason = corrupted + rep.Title = replaceTable(gvisorTitleReplacement, rep.Title) + rep.Report = ctx.shortenReport(rep.Report) return rep } diff --git a/pkg/report/report.go b/pkg/report/report.go index 934adc898..1a6e76505 100644 --- a/pkg/report/report.go +++ b/pkg/report/report.go @@ -426,6 +426,43 @@ nextPart: return "", corrupted } +func simpleLineParser(output []byte, oopses []*oops, params *stackParams, ignores []*regexp.Regexp) *Report { + rep := &Report{ + Output: output, + } + var oops *oops + for pos := 0; pos < len(output); { + next := bytes.IndexByte(output[pos:], '\n') + if next != -1 { + next += pos + } else { + next = len(output) + } + line := output[pos:next] + for _, oops1 := range oopses { + match := matchOops(line, oops1, ignores) + if match != -1 { + oops = oops1 + rep.StartPos = pos + break + } + } + if oops != nil { + break + } + pos = next + 1 + } + if oops == nil { + return nil + } + title, corrupted, _ := extractDescription(output[rep.StartPos:], oops, params) + rep.Title = title + rep.Report = output[rep.StartPos:] + rep.Corrupted = corrupted != "" + rep.CorruptedReason = corrupted + return rep +} + func matchesAny(line []byte, res []*regexp.Regexp) bool { for _, re := range res { if re.Match(line) { |
