Skip to content

Commit

Permalink
Fix style
Browse files Browse the repository at this point in the history
  • Loading branch information
bmuschko committed Aug 17, 2024
1 parent 78cec87 commit 581a43c
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 36 deletions.
1 change: 1 addition & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

Expand Down
2 changes: 0 additions & 2 deletions file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func FindTextBasedFiles(sourceDir string, includePatterns []string) []string {

return err
})

if err != nil {
panic(err)
}
Expand All @@ -48,7 +47,6 @@ func appendMatches(extension string, filename string, path string, matches []str
// ReadFile reads the contents of a given file.
func ReadFile(path string) string {
read, err := ioutil.ReadFile(path)

if err != nil {
panic(err)
}
Expand Down
36 changes: 16 additions & 20 deletions file/file_test.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package file_test

import (
"fmt"
. "github.com/bmuschko/link-verifier/file"
. "github.com/stretchr/testify/assert"
"os"
"path/filepath"
"testing"

. "github.com/bmuschko/link-verifier/file"
. "github.com/stretchr/testify/assert"
)

func TestFindAsciiDocFilesInRootDir(t *testing.T) {
tempDirPath := filepath.Join(os.TempDir(), "a")
createDir(tempDirPath)
path1 := filepath.Join(tempDirPath, fmt.Sprintf("1.adoc"))
path2 := filepath.Join(tempDirPath, fmt.Sprintf("abc.adoc"))
path1 := filepath.Join(tempDirPath, "1.adoc")
path2 := filepath.Join(tempDirPath, "abc.adoc")
jpgPath := filepath.Join(tempDirPath, "my.jpg")
binPath := filepath.Join(tempDirPath, "other.bin")
docPath := filepath.Join(tempDirPath, "some.doc")
Expand Down Expand Up @@ -42,8 +42,8 @@ func TestFindAsciiDocFilesInSubDirs(t *testing.T) {
createDir(subDirPath)
subSubDirPath := filepath.Join(subDirPath, "subsub")
createDir(subSubDirPath)
path1 := filepath.Join(subDirPath, fmt.Sprintf("1.adoc"))
path2 := filepath.Join(subSubDirPath, fmt.Sprintf("2.adoc"))
path1 := filepath.Join(subDirPath, "1.adoc")
path2 := filepath.Join(subSubDirPath, "2.adoc")
createFile(path1)
createFile(path2)

Expand All @@ -59,9 +59,9 @@ func TestFindAsciiDocFilesInSubDirs(t *testing.T) {
func TestFindAsciiDocFilesDifferentExtensions(t *testing.T) {
tempDirPath := filepath.Join(os.TempDir(), "c")
createDir(tempDirPath)
path1 := filepath.Join(tempDirPath, fmt.Sprintf("1.adoc"))
path2 := filepath.Join(tempDirPath, fmt.Sprintf("2.asciidoc"))
path3 := filepath.Join(tempDirPath, fmt.Sprintf("3.asc"))
path1 := filepath.Join(tempDirPath, "1.adoc")
path2 := filepath.Join(tempDirPath, "2.asciidoc")
path3 := filepath.Join(tempDirPath, "3.asc")
createFile(path1)
createFile(path2)
createFile(path3)
Expand All @@ -80,8 +80,8 @@ func TestFindAsciiDocFilesDifferentExtensions(t *testing.T) {
func TestFilesForCustomIncludePatterns(t *testing.T) {
tempDirPath := filepath.Join(os.TempDir(), "e")
createDir(tempDirPath)
path1 := filepath.Join(tempDirPath, fmt.Sprintf("1.html"))
path2 := filepath.Join(tempDirPath, fmt.Sprintf("2.yml"))
path1 := filepath.Join(tempDirPath, "1.html")
path2 := filepath.Join(tempDirPath, "2.yml")
createFile(path1)
createFile(path2)

Expand All @@ -98,7 +98,7 @@ func TestReadFile(t *testing.T) {
expectedContent := "some text"
tempDirPath := filepath.Join(os.TempDir(), "content")
createDir(tempDirPath)
path1 := filepath.Join(tempDirPath, fmt.Sprintf("1.adoc"))
path1 := filepath.Join(tempDirPath, "1.adoc")
createFile(path1)
writeFile(path1, expectedContent)

Expand All @@ -116,16 +116,14 @@ func TestPanicWhenReadingNonExistentFile(t *testing.T) {
}

func createDir(path string) {
err := os.MkdirAll(path, 0755)

err := os.MkdirAll(path, 0o755)
if err != nil {
panic(err)
}
}

func createFile(path string) {
w, err := os.Create(path)

if err != nil {
panic(err)
}
Expand All @@ -134,7 +132,7 @@ func createFile(path string) {
}

func writeFile(path string, content string) {
var file, err = os.OpenFile(path, os.O_RDWR, 0644)
file, err := os.OpenFile(path, os.O_RDWR, 0o644)

if err != nil {
panic(err)
Expand All @@ -143,20 +141,18 @@ func writeFile(path string, content string) {
defer file.Close()

_, err = file.WriteString(content)

if err != nil {
panic(err)
}

err = file.Sync()

if err != nil {
panic(err)
}
}

func deleteFile(path string) {
var err = os.Remove(path)
err := os.Remove(path)

if err != nil {
panic(err)
Expand Down
2 changes: 0 additions & 2 deletions http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,12 @@ func (h *HTTP) Get(link string) HttpResponse {
func sendRequest(link string, req func(*url.URL) (resp *http.Response, err error)) HttpResponse {
result := HttpResponse{Url: link}
url, err := url.ParseRequestURI(link)

if err != nil {
result.Error = err
return result
}

resp, err := req(url)

if err != nil {
result.Error = err
return result
Expand Down
5 changes: 3 additions & 2 deletions http/http_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package http_test

import (
. "github.com/bmuschko/link-verifier/http"
. "github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"testing"
"time"

. "github.com/bmuschko/link-verifier/http"
. "github.com/stretchr/testify/assert"
)

const (
Expand Down
4 changes: 1 addition & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import (
"github.com/bmuschko/link-verifier/cmd"
)

var (
version = "undefined"
)
var version = "undefined"

func main() {
cmd.SetVersion(version)
Expand Down
3 changes: 2 additions & 1 deletion stat/stat_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package stat_test

import (
"testing"

. "github.com/bmuschko/link-verifier/stat"
. "github.com/stretchr/testify/assert"
"testing"
)

func TestSumSuccessesForEmptySlice(t *testing.T) {
Expand Down
5 changes: 4 additions & 1 deletion text/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
package text

import (
"mvdan.cc/xurls/v2"
"regexp"
"strings"

"mvdan.cc/xurls/v2"
)

// ParseLinks parses a given text and extracts all links. None of the links is further modified except for the rules listed below.
// Sanitizes founds like based on the following logic:
// - Removes link description e.g. [...] if extraction logic couldn't remove it.
// - Remove fragments in URLs e.g. #sec:news - they are a browser-only concept.
//
// Does not included links based on the following logic:
// - URLs that contains String interpolation with ${...}.
//
// Returns a slice of links.
func ParseLinks(content string) []string {
uniqueLinks := make(map[string]bool)
Expand Down
3 changes: 2 additions & 1 deletion text/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package text_test

import (
"fmt"
"testing"

. "github.com/bmuschko/link-verifier/text"
. "github.com/stretchr/testify/assert"
"testing"
)

const expectedLink = "http://www.oracle.com/technetwork/articles/java/index-jsp-135444.html"
Expand Down
9 changes: 5 additions & 4 deletions verify/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package verify

import (
"fmt"
"os"
"strconv"
"strings"

"github.com/bmuschko/link-verifier/file"
"github.com/bmuschko/link-verifier/http"
"github.com/bmuschko/link-verifier/stat"
"github.com/bmuschko/link-verifier/text"
"os"
"strconv"
"strings"
)

// Resolve resolves text-based files for a given directories.
Expand Down Expand Up @@ -111,7 +112,7 @@ func validateLink(link string, timeout int, ignoreStatusCodes []int, summary *st
}

func calculateSeparator(stats string) string {
var separator = ""
separator := ""

for i := 0; i < len(stats); i++ {
separator += "-"
Expand Down

0 comments on commit 581a43c

Please sign in to comment.