Skip to content

Commit b5a100b

Browse files
authored
Merge pull request #3560 from karalabe/ci-misspell
travis, appveyor, build: add source spell checking
2 parents 01f6f2d + 54fcab2 commit b5a100b

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ install:
9090
- go get golang.org/x/tools/cmd/cover
9191
script:
9292
- go run build/ci.go install
93-
- go run build/ci.go test -coverage -vet
93+
- go run build/ci.go test -coverage -vet -misspell
9494

9595
notifications:
9696
webhooks:

accounts/abi/type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func NewType(t string) (typ Type, err error) {
9191
}
9292
typ.Elem = &sliceType
9393
typ.stringKind = sliceType.stringKind + t[len(res[1]):]
94-
// Altough we know that this is an array, we cannot return
94+
// Although we know that this is an array, we cannot return
9595
// as we don't know the type of the element, however, if it
9696
// is still an array, then don't determine the type.
9797
if typ.Elem.IsArray || typ.Elem.IsSlice {

build/ci.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Usage: go run ci.go <command> <command flags/arguments>
2424
Available commands are:
2525
2626
install [-arch architecture] [ packages... ] -- builds packages and executables
27-
test [ -coverage ] [ -vet ] [ packages... ] -- runs the tests
27+
test [ -coverage ] [ -vet ] [ -misspell ] [ packages... ] -- runs the tests
2828
archive [-arch architecture] [ -type zip|tar ] [ -signer key-envvar ] [ -upload dest ] -- archives build artefacts
2929
importkeys -- imports signing keys from env
3030
debsrc [ -signer key-id ] [ -upload dest ] -- creates a debian source package
@@ -262,6 +262,7 @@ func goToolArch(arch string, subcmd string, args ...string) *exec.Cmd {
262262
func doTest(cmdline []string) {
263263
var (
264264
vet = flag.Bool("vet", false, "Whether to run go vet")
265+
misspell = flag.Bool("misspell", false, "Whether to run the spell checker")
265266
coverage = flag.Bool("coverage", false, "Whether to record code coverage")
266267
)
267268
flag.CommandLine.Parse(cmdline)
@@ -287,7 +288,9 @@ func doTest(cmdline []string) {
287288
if *vet {
288289
build.MustRun(goTool("vet", packages...))
289290
}
290-
291+
if *misspell {
292+
spellcheck(packages)
293+
}
291294
// Run the actual tests.
292295
gotest := goTool("test")
293296
// Test a single package at a time. CI builders are slow
@@ -300,6 +303,34 @@ func doTest(cmdline []string) {
300303
build.MustRun(gotest)
301304
}
302305

306+
// spellcheck runs the client9/misspell spellchecker package on all Go, Cgo and
307+
// test files in the requested packages.
308+
func spellcheck(packages []string) {
309+
// Ensure the spellchecker is available
310+
build.MustRun(goTool("get", "github.com/client9/misspell/cmd/misspell"))
311+
312+
// Windows chokes on long argument lists, check packages individualy
313+
for _, pkg := range packages {
314+
// The spell checker doesn't work on packages, gather all .go files for it
315+
out, err := goTool("list", "-f", "{{.Dir}}{{range .GoFiles}}\n{{.}}{{end}}{{range .CgoFiles}}\n{{.}}{{end}}{{range .TestGoFiles}}\n{{.}}{{end}}", pkg).CombinedOutput()
316+
if err != nil {
317+
log.Fatalf("source file listing failed: %v\n%s", err, string(out))
318+
}
319+
// Retrieve the folder and assemble the source list
320+
lines := strings.Split(string(out), "\n")
321+
root := lines[0]
322+
323+
sources := make([]string, 0, len(lines)-1)
324+
for _, line := range lines[1:] {
325+
if line = strings.TrimSpace(line); line != "" {
326+
sources = append(sources, filepath.Join(root, line))
327+
}
328+
}
329+
// Run the spell checker for this particular package
330+
build.MustRunCommand(filepath.Join(GOBIN, "misspell"), append([]string{"-error"}, sources...)...)
331+
}
332+
}
333+
303334
// Release Packaging
304335

305336
func doArchive(cmdline []string) {

0 commit comments

Comments
 (0)