Skip to content

Commit

Permalink
Enable misspell and gofmtmd; fix formatting issues (quii#706)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear authored Oct 6, 2023
1 parent 9f265e1 commit 34fe08c
Show file tree
Hide file tree
Showing 14 changed files with 223 additions and 209 deletions.
17 changes: 8 additions & 9 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
set -e

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

#ls *.md | xargs misspell -error
#for md_file in ./*.md; do
# echo "formatting file: $md_file"
# gofmtmd "$md_file" -r
#done
ls *.md | xargs misspell -error

for md_file in ./*.md; do
echo "formatting file: $md_file"
gofmtmd "$md_file" -r
done

go test ./...
go vet ./...
go fmt ./...
#golint ./...
14 changes: 7 additions & 7 deletions command-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Finally, we need to import this package into `main.go` so we can use it to creat
The paths will be different on your computer, but it should be similar to this:

```go
//cmd/webserver/main.go
// cmd/webserver/main.go
package main

import (
Expand Down Expand Up @@ -116,7 +116,7 @@ In addition, users can view [the documentation at pkg.go.dev](https://pkg.go.dev
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

```go
//cmd/cli/main.go
// cmd/cli/main.go
package main

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

```go
//CLI_test.go
// CLI_test.go
package poker

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

```go
//CLI.go
// CLI.go
package poker

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

```go
//testing.go
// testing.go
package poker

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

```go
//cmd/cli/main.go
// cmd/cli/main.go
package main

import (
Expand Down Expand Up @@ -651,7 +651,7 @@ func main() {
#### Web server application code

```go
//cmd/webserver/main.go
// cmd/webserver/main.go
package main

import (
Expand Down
4 changes: 2 additions & 2 deletions generics.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ func (s *Stack[T]) Push(value T) {
}

func (s *Stack[T]) IsEmpty() bool {
return len(s.values)==0
return len(s.values) == 0
}

func (s *Stack[T]) Pop() (T, bool) {
Expand All @@ -446,7 +446,7 @@ func (s *Stack[T]) Pop() (T, bool) {
return zero, false
}

index := len(s.values) -1
index := len(s.values) - 1
el := s.values[index]
s.values = s.values[:index]
return el, true
Expand Down
30 changes: 15 additions & 15 deletions hello-world.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,20 +409,20 @@ The tests should now pass.
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.

```go
const spanish = "Spanish"
const englishHelloPrefix = "Hello, "
const spanishHelloPrefix = "Hola, "
const spanish = "Spanish"
const englishHelloPrefix = "Hello, "
const spanishHelloPrefix = "Hola, "

func Hello(name string, language string) string {
if name == "" {
name = "World"
}
func Hello(name string, language string) string {
if name == "" {
name = "World"
}

if language == spanish {
return spanishHelloPrefix + name
if language == spanish {
return spanishHelloPrefix + name
}
return englishHelloPrefix + name
}
return englishHelloPrefix + name
}
```

### French
Expand Down Expand Up @@ -483,10 +483,10 @@ You could argue that maybe our function is getting a little big. The simplest re
const (
french = "French"
spanish = "Spanish"
englishHelloPrefix = "Hello, "
spanishHelloPrefix = "Hola, "
frenchHelloPrefix = "Bonjour, "

englishHelloPrefix = "Hello, "
spanishHelloPrefix = "Hola, "
frenchHelloPrefix = "Bonjour, "
)

func Hello(name string, language string) string {
Expand Down
4 changes: 2 additions & 2 deletions html-templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ func Render(w io.Writer, p Post) error {
return err
}

if err := templ.ExecuteTemplate(w, "blog.gohtml", p); err != nil {
if err := templ.ExecuteTemplate(w, "blog.gohtml", p); err != nil {
return err
}

Expand Down Expand Up @@ -588,7 +588,7 @@ func NewPostRenderer() (*PostRenderer, error) {

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

if err := r.templ.ExecuteTemplate(w, "blog.gohtml", p); err != nil {
if err := r.templ.ExecuteTemplate(w, "blog.gohtml", p); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions http-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ For that reason, it is recommended that you research _The Test Pyramid_.
In the interest of brevity, I am going to show you the final refactored integration test.

```go
//server_integration_test.go
// server_integration_test.go
package main

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

```go
//main.go
// main.go
package main
import (
Expand Down
14 changes: 7 additions & 7 deletions intro-to-acceptance-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,13 @@ func waitForServerListening(port string) error {
}

func randomString(n int) string {
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")

s := make([]rune, n)
for i := range s {
s[i] = letters[rand.Intn(len(letters))]
}
return string(s)
s := make([]rune, n)
for i := range s {
s[i] = letters[rand.Intn(len(letters))]
}
return string(s)
}
```

Expand Down Expand Up @@ -294,7 +294,7 @@ import (

const (
port = "8080"
url = "<http://localhost:"> + port
url = "<http://localhost:" > +port
)

func TestGracefulShutdown(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions io.md
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ store := &FileSystemPlayerStore{database}
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.

```go
//main.go
// main.go
package main

import (
Expand Down Expand Up @@ -822,7 +822,7 @@ How will we test for this though? What we need to do is first refactor our code
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:

```go
//tape.go
// tape.go
package main

import "io"
Expand Down
6 changes: 3 additions & 3 deletions math.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ So my first test looks like this:
package clockface_test

import (
"projectpath/clockface"
"projectpath/clockface"
"testing"
"time"
)
Expand Down Expand Up @@ -1068,7 +1068,7 @@ const (
clockCentreY = 150
)

//SVGWriter writes an SVG representation of an analogue clock, showing the time t, to the writer w
// SVGWriter writes an SVG representation of an analogue clock, showing the time t, to the writer w
func SVGWriter(w io.Writer, t time.Time) {
io.WriteString(w, svgStart)
io.WriteString(w, bezel)
Expand Down Expand Up @@ -2073,7 +2073,7 @@ const (
clockCentreY = 150
)

//SVGWriter writes an SVG representation of an analogue clock, showing the time t, to the writer w
// SVGWriter writes an SVG representation of an analogue clock, showing the time t, to the writer w
func SVGWriter(w io.Writer, t time.Time) {
io.WriteString(w, svgStart)
io.WriteString(w, bezel)
Expand Down
2 changes: 1 addition & 1 deletion reflection.md
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ To fix this, we'll need to move our assertion with the maps to a new test where
```go
t.Run("with maps", func(t *testing.T) {
aMap := map[string]string{
"Cow": "Moo",
"Cow": "Moo",
"Sheep": "Baa",
}

Expand Down
4 changes: 2 additions & 2 deletions roman-numerals.md
Original file line number Diff line number Diff line change
Expand Up @@ -1176,13 +1176,13 @@ chapter so, in the interests of full disclosure, here's what he said.
> sometimes `arabic` will be written as a decimal integer literal
>
> ```go
> ConvertToRoman(255)
> ConvertToRoman(255)
> ```
>
> But it could just as well be written
>
> ```go
> ConvertToRoman(0xFF)
> ConvertToRoman(0xFF)
> ```
>
> Really, we're not 'converting' from an Arabic numeral at all, we're 'printing' -
Expand Down
Loading

0 comments on commit 34fe08c

Please sign in to comment.