Skip to content

Commit ccde652

Browse files
committed
linting
1 parent 8f4257e commit ccde652

File tree

5 files changed

+35
-28
lines changed

5 files changed

+35
-28
lines changed

.travis.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ go:
33
- 1.8
44

55
before_install:
6-
- go get golang.org/x/tools/cmd/cover
7-
- go get github.com/mattn/goveralls
6+
- go get -u golang.org/x/tools/cmd/cover
7+
- go get -u github.com/mattn/goveralls
8+
- go get -u github.com/alecthomas/gometalinter
89

910
script:
1011
- go build
12+
- gometalinter
1113
- go test -v ./...
1214
- go test -v -covermode=count -coverprofile=coverage.out ./diff
1315
- $GOPATH/bin/goveralls -coverprofile=coverage.out -service=travis-ci -repotoken $COVERALLS_TOKEN

config.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import (
99
)
1010

1111
type config struct {
12-
Output
13-
Ignore Patterns `long:"ignore" short:"i" description:"paths to ignore (glob)"`
14-
OutputReport bool `long:"report" short:"r" description:"output report format"`
15-
Files struct {
12+
Files struct {
1613
LHS string `positional-arg-name:"FILE_1"`
1714
RHS string `positional-arg-name:"FILE_2"`
1815
} `positional-args:"yes" required:"yes"`
16+
Ignore ignorePatterns `long:"ignore" short:"i" description:"paths to ignore (glob)"`
17+
output
18+
OutputReport bool `long:"report" short:"r" description:"output report format"`
1919
}
2020

21-
type Output struct {
21+
type output struct {
2222
Indent string `long:"indent" description:"indent string" default:"\t"`
2323
ShowTypes bool `long:"show-types" short:"t" description:"show types"`
2424
Colorized bool
@@ -33,10 +33,10 @@ func readConfig() config {
3333
os.Exit(0)
3434
}
3535
fmt.Fprintf(os.Stderr, "Failed to parse arguments. See %s --help\n", os.Args[0])
36-
os.Exit(2)
36+
os.Exit(statusUsage)
3737
}
3838

39-
c.Output.Colorized = terminal.IsTerminal(int(os.Stdout.Fd()))
39+
c.output.Colorized = terminal.IsTerminal(int(os.Stdout.Fd()))
4040

4141
return c
4242
}

diff/diff_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ func TestReport(t *testing.T) {
428428
}
429429
ss, err := Report(d, testOutput)
430430
if err != nil {
431-
t.Errorf("Report(Diff(...), %+v): unexpected error: %s", err, testOutput)
431+
t.Errorf("Report(Diff(...), %+v): unexpected error: %s", testOutput, err)
432432
return
433433
}
434434

main.go

+17-12
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import (
1010
)
1111

1212
const (
13-
StatusDiffMismatch = 1
14-
StatusReadError = 3
15-
StatusUnmarshalError = 4
16-
StatusDiffError = 5
13+
statusDiffMismatch = 1
14+
statusUsage = 2
15+
statusReadError = 3
16+
statusUnmarshalError = 4
17+
statusDiffError = 5
1718
)
1819

1920
func main() {
@@ -26,29 +27,33 @@ func main() {
2627
d, err := diff.Diff(lhs, rhs)
2728
if err != nil {
2829
fmt.Fprintf(os.Stderr, "Error: diff failed: %s", err)
29-
os.Exit(StatusDiffError)
30+
os.Exit(statusDiffError)
3031
}
3132

3233
d, err = pruneIgnore(d, conf.Ignore)
34+
if err != nil {
35+
fmt.Fprintf(os.Stderr, "Error: ignoring failed: %s", err)
36+
os.Exit(statusDiffError)
37+
}
3338

3439
if conf.OutputReport {
35-
ss, err := diff.Report(d, diff.Output(conf.Output))
40+
ss, err := diff.Report(d, diff.Output(conf.output))
3641
if err != nil {
3742
fmt.Fprintf(os.Stderr, "Error: Failed to generate report: %s", err)
38-
os.Exit(StatusDiffError)
43+
os.Exit(statusDiffError)
3944
}
4045
for _, s := range ss {
4146
fmt.Println(s)
4247
}
4348
} else {
44-
fmt.Println(d.StringIndent("", "", diff.Output(conf.Output)))
49+
fmt.Println(d.StringIndent("", "", diff.Output(conf.output)))
4550
}
4651
if d.Diff() != diff.Identical {
47-
os.Exit(StatusDiffMismatch)
52+
os.Exit(statusDiffMismatch)
4853
}
4954
}
5055

51-
func pruneIgnore(d diff.Differ, ignore Patterns) (diff.Differ, error) {
56+
func pruneIgnore(d diff.Differ, ignore ignorePatterns) (diff.Differ, error) {
5257
return diff.Walk(d, func(parent diff.Differ, d diff.Differ, path string) (diff.Differ, error) {
5358
if ignore.Match(path) {
5459
return diff.Ignore()
@@ -64,12 +69,12 @@ func parseFile(fname string) interface{} {
6469
b, err := ioutil.ReadFile(fname)
6570
if err != nil {
6671
fmt.Fprintf(os.Stderr, "Error: cannot read %s\n", fname)
67-
os.Exit(StatusReadError)
72+
os.Exit(statusReadError)
6873
}
6974
err = json.Unmarshal(b, &val)
7075
if err != nil {
7176
fmt.Fprintf(os.Stderr, "Error: cannot parse %s: %s\n", fname, err)
72-
os.Exit(StatusUnmarshalError)
77+
os.Exit(statusUnmarshalError)
7378
}
7479

7580
return val

patterns.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import (
66
"github.com/gobwas/glob"
77
)
88

9-
type Pattern struct {
9+
type ignorePattern struct {
1010
glob.Glob
1111
s string
1212
}
1313

14-
type Patterns []Pattern
14+
type ignorePatterns []ignorePattern
1515

16-
func (p Patterns) String() string {
16+
func (p ignorePatterns) String() string {
1717
var ss []string
1818

1919
for _, pattern := range p {
@@ -23,20 +23,20 @@ func (p Patterns) String() string {
2323
return strings.Join(ss, ",")
2424
}
2525

26-
func (p *Patterns) Set(s string) error {
26+
func (p *ignorePatterns) Set(s string) error {
2727
pattern, err := glob.Compile(s)
2828
if err != nil {
2929
return err
3030
}
31-
*p = append(*p, Pattern{
31+
*p = append(*p, ignorePattern{
3232
s: s,
3333
Glob: pattern,
3434
})
3535

3636
return nil
3737
}
3838

39-
func (p Patterns) Match(s string) bool {
39+
func (p ignorePatterns) Match(s string) bool {
4040
for _, pattern := range p {
4141
if pattern.Match(s) {
4242
return true

0 commit comments

Comments
 (0)