-
Notifications
You must be signed in to change notification settings - Fork 7
/
goword.go
71 lines (64 loc) · 1.34 KB
/
goword.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"flag"
"fmt"
"os"
"sort"
"strings"
)
func newSpellCheck(srcpaths []string, ignfile string) (*Spellcheck, error) {
toks, err := GoTokens(srcpaths)
if err != nil {
return nil, err
}
splitToks := make(map[string]struct{})
for k, _ := range toks {
for _, field := range strings.Fields(k) {
splitToks[field] = struct{}{}
}
}
sp, serr := NewSpellcheck(splitToks, ignfile)
if serr != nil {
return nil, serr
}
return sp, nil
}
func main() {
ign := flag.String("ignore-file", "", "additional words to ignore")
useSpell := flag.Bool("use-spell", true, "check spelling")
useGoDoc := flag.Bool("use-godoc", true, "check godocs")
flag.Parse()
var cps []CheckPipe
if *useSpell {
ignfile := ""
if ign != nil {
ignfile = *ign
}
sp, serr := newSpellCheck(flag.Args(), ignfile)
if serr != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", serr)
os.Exit(1)
}
defer sp.Close()
cps = append(cps, sp.Check())
}
if *useGoDoc {
cps = append(cps, CheckGoDocs)
}
// find all errors
ct, cerr := Check(flag.Args(), cps)
if cerr != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", cerr)
os.Exit(1)
}
sort.Sort(CheckedLexemes(ct))
for _, c := range ct {
fmt.Printf("%s.%d: %s (%s: %s -> %s?)\n",
c.ctok.pos.Filename,
c.ctok.pos.Line,
c.ctok.lit,
c.rule,
c.words[0].word,
c.words[0].suggest)
}
}