Skip to content

Commit 34fe08c

Browse files
authored
Enable misspell and gofmtmd; fix formatting issues (#706)
1 parent 9f265e1 commit 34fe08c

14 files changed

+223
-209
lines changed

build.sh

+8-9
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
set -e
44

55
go get github.com/gorilla/websocket #todo vendor this or learn about the module stuff!
6-
#go get -u golang.org/x/lint/golint
7-
#go get -u github.com/client9/misspell/cmd/misspell
8-
#go get github.com/po3rin/gofmtmd/cmd/gofmtmd
6+
go install github.com/client9/misspell/cmd/misspell@latest
7+
go install github.com/po3rin/gofmtmd/cmd/gofmtmd@latest
98

10-
#ls *.md | xargs misspell -error
11-
#for md_file in ./*.md; do
12-
# echo "formatting file: $md_file"
13-
# gofmtmd "$md_file" -r
14-
#done
9+
ls *.md | xargs misspell -error
10+
11+
for md_file in ./*.md; do
12+
echo "formatting file: $md_file"
13+
gofmtmd "$md_file" -r
14+
done
1515

1616
go test ./...
1717
go vet ./...
1818
go fmt ./...
19-
#golint ./...

command-line.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Finally, we need to import this package into `main.go` so we can use it to creat
6868
The paths will be different on your computer, but it should be similar to this:
6969

7070
```go
71-
//cmd/webserver/main.go
71+
// cmd/webserver/main.go
7272
package main
7373

7474
import (
@@ -116,7 +116,7 @@ In addition, users can view [the documentation at pkg.go.dev](https://pkg.go.dev
116116
Before we get stuck into writing tests, let's add a new application that our project will build. Create another directory inside `cmd` called `cli` (command line interface) and add a `main.go` with the following
117117

118118
```go
119-
//cmd/cli/main.go
119+
// cmd/cli/main.go
120120
package main
121121

122122
import "fmt"
@@ -137,7 +137,7 @@ Before we jump too far ahead though, let's just write a test to check it integra
137137
Inside `CLI_test.go` (in the root of the project, not inside `cmd`)
138138

139139
```go
140-
//CLI_test.go
140+
// CLI_test.go
141141
package poker
142142

143143
import "testing"
@@ -172,7 +172,7 @@ At this point, you should be comfortable enough to create our new `CLI` struct w
172172
You should end up with code like this
173173

174174
```go
175-
//CLI.go
175+
// CLI.go
176176
package poker
177177

178178
type CLI struct {
@@ -464,7 +464,7 @@ Anecdotally I have used this technique in other shared packages and it has prove
464464
So let's create a file called `testing.go` and add our stub and our helpers.
465465

466466
```go
467-
//testing.go
467+
// testing.go
468468
package poker
469469

470470
import "testing"
@@ -622,7 +622,7 @@ Now refactor both of our applications to use this function to create the store.
622622
#### CLI application code
623623

624624
```go
625-
//cmd/cli/main.go
625+
// cmd/cli/main.go
626626
package main
627627

628628
import (
@@ -651,7 +651,7 @@ func main() {
651651
#### Web server application code
652652

653653
```go
654-
//cmd/webserver/main.go
654+
// cmd/webserver/main.go
655655
package main
656656

657657
import (

generics.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ func (s *Stack[T]) Push(value T) {
437437
}
438438

439439
func (s *Stack[T]) IsEmpty() bool {
440-
return len(s.values)==0
440+
return len(s.values) == 0
441441
}
442442

443443
func (s *Stack[T]) Pop() (T, bool) {
@@ -446,7 +446,7 @@ func (s *Stack[T]) Pop() (T, bool) {
446446
return zero, false
447447
}
448448

449-
index := len(s.values) -1
449+
index := len(s.values) - 1
450450
el := s.values[index]
451451
s.values = s.values[:index]
452452
return el, true

hello-world.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -409,20 +409,20 @@ The tests should now pass.
409409
Now it is time to _refactor_. You should see some problems in the code, "magic" strings, some of which are repeated. Try and refactor it yourself, with every change make sure you re-run the tests to make sure your refactoring isn't breaking anything.
410410

411411
```go
412-
const spanish = "Spanish"
413-
const englishHelloPrefix = "Hello, "
414-
const spanishHelloPrefix = "Hola, "
412+
const spanish = "Spanish"
413+
const englishHelloPrefix = "Hello, "
414+
const spanishHelloPrefix = "Hola, "
415415

416-
func Hello(name string, language string) string {
417-
if name == "" {
418-
name = "World"
419-
}
416+
func Hello(name string, language string) string {
417+
if name == "" {
418+
name = "World"
419+
}
420420

421-
if language == spanish {
422-
return spanishHelloPrefix + name
421+
if language == spanish {
422+
return spanishHelloPrefix + name
423+
}
424+
return englishHelloPrefix + name
423425
}
424-
return englishHelloPrefix + name
425-
}
426426
```
427427

428428
### French
@@ -483,10 +483,10 @@ You could argue that maybe our function is getting a little big. The simplest re
483483
const (
484484
french = "French"
485485
spanish = "Spanish"
486-
487-
englishHelloPrefix = "Hello, "
488-
spanishHelloPrefix = "Hola, "
489-
frenchHelloPrefix = "Bonjour, "
486+
487+
englishHelloPrefix = "Hello, "
488+
spanishHelloPrefix = "Hola, "
489+
frenchHelloPrefix = "Bonjour, "
490490
)
491491

492492
func Hello(name string, language string) string {

html-templates.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ func Render(w io.Writer, p Post) error {
531531
return err
532532
}
533533

534-
if err := templ.ExecuteTemplate(w, "blog.gohtml", p); err != nil {
534+
if err := templ.ExecuteTemplate(w, "blog.gohtml", p); err != nil {
535535
return err
536536
}
537537

@@ -588,7 +588,7 @@ func NewPostRenderer() (*PostRenderer, error) {
588588

589589
func (r *PostRenderer) Render(w io.Writer, p Post) error {
590590

591-
if err := r.templ.ExecuteTemplate(w, "blog.gohtml", p); err != nil {
591+
if err := r.templ.ExecuteTemplate(w, "blog.gohtml", p); err != nil {
592592
return err
593593
}
594594

http-server.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ For that reason, it is recommended that you research _The Test Pyramid_.
959959
In the interest of brevity, I am going to show you the final refactored integration test.
960960

961961
```go
962-
//server_integration_test.go
962+
// server_integration_test.go
963963
package main
964964

965965
import (
@@ -1035,7 +1035,7 @@ func (i *InMemoryPlayerStore) GetPlayerScore(name string) int {
10351035
The integration test passes, now we just need to change `main` to use `NewInMemoryPlayerStore()`
10361036

10371037
```go
1038-
//main.go
1038+
// main.go
10391039
package main
10401040
10411041
import (

intro-to-acceptance-tests.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,13 @@ func waitForServerListening(port string) error {
254254
}
255255

256256
func randomString(n int) string {
257-
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
257+
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
258258

259-
s := make([]rune, n)
260-
for i := range s {
261-
s[i] = letters[rand.Intn(len(letters))]
262-
}
263-
return string(s)
259+
s := make([]rune, n)
260+
for i := range s {
261+
s[i] = letters[rand.Intn(len(letters))]
262+
}
263+
return string(s)
264264
}
265265
```
266266

@@ -294,7 +294,7 @@ import (
294294

295295
const (
296296
port = "8080"
297-
url = "<http://localhost:"> + port
297+
url = "<http://localhost:" > +port
298298
)
299299

300300
func TestGracefulShutdown(t *testing.T) {

io.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ store := &FileSystemPlayerStore{database}
718718
If you run the test it should pass and now we can delete `InMemoryPlayerStore`. `main.go` will now have compilation problems which will motivate us to now use our new store in the "real" code.
719719

720720
```go
721-
//main.go
721+
// main.go
722722
package main
723723

724724
import (
@@ -822,7 +822,7 @@ How will we test for this though? What we need to do is first refactor our code
822822
We'll create a new type to encapsulate our "when we write we go from the beginning" functionality. I'm going to call it `Tape`. Create a new file with the following:
823823

824824
```go
825-
//tape.go
825+
// tape.go
826826
package main
827827

828828
import "io"

math.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ So my first test looks like this:
131131
package clockface_test
132132

133133
import (
134-
"projectpath/clockface"
134+
"projectpath/clockface"
135135
"testing"
136136
"time"
137137
)
@@ -1068,7 +1068,7 @@ const (
10681068
clockCentreY = 150
10691069
)
10701070

1071-
//SVGWriter writes an SVG representation of an analogue clock, showing the time t, to the writer w
1071+
// SVGWriter writes an SVG representation of an analogue clock, showing the time t, to the writer w
10721072
func SVGWriter(w io.Writer, t time.Time) {
10731073
io.WriteString(w, svgStart)
10741074
io.WriteString(w, bezel)
@@ -2073,7 +2073,7 @@ const (
20732073
clockCentreY = 150
20742074
)
20752075

2076-
//SVGWriter writes an SVG representation of an analogue clock, showing the time t, to the writer w
2076+
// SVGWriter writes an SVG representation of an analogue clock, showing the time t, to the writer w
20772077
func SVGWriter(w io.Writer, t time.Time) {
20782078
io.WriteString(w, svgStart)
20792079
io.WriteString(w, bezel)

reflection.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ To fix this, we'll need to move our assertion with the maps to a new test where
744744
```go
745745
t.Run("with maps", func(t *testing.T) {
746746
aMap := map[string]string{
747-
"Cow": "Moo",
747+
"Cow": "Moo",
748748
"Sheep": "Baa",
749749
}
750750

roman-numerals.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1176,13 +1176,13 @@ chapter so, in the interests of full disclosure, here's what he said.
11761176
> sometimes `arabic` will be written as a decimal integer literal
11771177
>
11781178
> ```go
1179-
> ConvertToRoman(255)
1179+
> ConvertToRoman(255)
11801180
> ```
11811181
>
11821182
> But it could just as well be written
11831183
>
11841184
> ```go
1185-
> ConvertToRoman(0xFF)
1185+
> ConvertToRoman(0xFF)
11861186
> ```
11871187
>
11881188
> Really, we're not 'converting' from an Arabic numeral at all, we're 'printing' -

0 commit comments

Comments
 (0)