Skip to content

Commit

Permalink
fix: lint errors globally (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmartingr authored May 30, 2024
1 parent e170598 commit 15a31cd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
14 changes: 11 additions & 3 deletions cmd/go-readability/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func rootCmdHandler(cmd *cobra.Command, args []string) {

fmt.Println(content)
} else {
cmd.Help()
_ = cmd.Help()
}
}

Expand All @@ -83,7 +83,11 @@ func httpHandler(w http.ResponseWriter, r *http.Request) {
textOnly, _ := strconv.ParseBool(r.URL.Query().Get("text"))
url := r.URL.Query().Get("url")
if url == "" {
w.Write([]byte(index))
if _, err := w.Write([]byte(index)); err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
} else {
log.Println("process URL", url)
content, err := getContent(url, metadataOnly, textOnly)
Expand All @@ -97,7 +101,11 @@ func httpHandler(w http.ResponseWriter, r *http.Request) {
} else if textOnly {
w.Header().Set("Content-Type", "text/plain")
}
w.Write([]byte(content))
if _, err := w.Write([]byte(content)); err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ func (ps *Parser) grabArticle() *html.Node {
// - parent: 1 (no division)
// - grandparent: 2
// - great grandparent+: ancestor level * 3
scoreDivider := 1
var scoreDivider int
switch level {
case 0:
scoreDivider = 1
Expand Down
3 changes: 1 addition & 2 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package readability
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/url"
"os"
fp "path/filepath"
Expand Down Expand Up @@ -33,7 +32,7 @@ type ExpectedMetadata struct {

func Test_parser(t *testing.T) {
testDir := "test-pages"
testItems, err := ioutil.ReadDir(testDir)
testItems, err := os.ReadDir(testDir)
if err != nil {
t.Errorf("\nfailed to read test directory")
}
Expand Down
7 changes: 4 additions & 3 deletions scripts/generate-test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
nurl "net/url"
Expand Down Expand Up @@ -49,7 +48,7 @@ func main() {

// If test name is 'all', generate test case for all existing test directory
if testName == "all" {
dirItems, err := ioutil.ReadDir("test-pages")
dirItems, err := os.ReadDir("test-pages")
if err != nil {
log.Fatalf("failed to read test dir: %v\n", err)
}
Expand Down Expand Up @@ -149,7 +148,9 @@ func downloadWebPage(srcURL string, dstPath string) error {
defer resp.Body.Close()

// Save to file
os.MkdirAll(fp.Dir(dstPath), os.ModePerm)
if err := os.MkdirAll(fp.Dir(dstPath), os.ModePerm); err != nil {
return fmt.Errorf("failed to create directory: %w", err)
}
dst, err := os.Create(dstPath)
if err != nil {
return fmt.Errorf("failed to save file: %v", err)
Expand Down

0 comments on commit 15a31cd

Please sign in to comment.