Fix issues from gometalinter and add code badges (#74)

This commit is contained in:
Anton Postov 2018-02-17 02:54:22 +03:00 committed by Sung Won Cho
commit 4d25b84363
9 changed files with 28 additions and 47 deletions

View file

@ -38,3 +38,5 @@ Please refer to [commands](/COMMANDS.md).
MIT
[![Build Status](https://travis-ci.org/dnote-io/cli.svg?branch=master)](https://travis-ci.org/dnote-io/cli)
[![Go Report Card](https://goreportcard.com/badge/github.com/dnote-io/cli)](https://goreportcard.com/report/github.com/dnote-io/cli)
[![GolangCI](https://golangci.com/badges/github.com/dnote-io/cli.svg)](https://golangci.com)

View file

@ -71,8 +71,8 @@ func newRun(ctx infra.DnoteCtx) core.RunEFunc {
fpath := core.GetDnoteTmpContentPath(ctx)
e := ioutil.WriteFile(fpath, []byte(targetNote.Content), 0644)
if err != nil {
return errors.Wrap(err, "Failed to prepare editor content")
if e != nil {
return errors.Wrap(e, "Failed to prepare editor content")
}
e = core.GetEditorInput(ctx, fpath, &newContent)

View file

@ -36,7 +36,9 @@ func newRun(ctx infra.DnoteCtx) core.RunEFunc {
log.Printf("API key: ")
var apiKey string
fmt.Scanln(&apiKey)
if _, err := fmt.Scanln(&apiKey); err != nil {
return err
}
if apiKey == "" {
return errors.New("Empty API key")

View file

@ -5,6 +5,7 @@ import (
"compress/gzip"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
@ -100,6 +101,9 @@ func newRun(ctx infra.DnoteCtx) core.RunEFunc {
// Update bookmark
ts, err := core.ReadTimestamp(ctx)
if err != nil {
return errors.Wrap(err, "Failed to read the timestamp")
}
ts.Bookmark = respData.Bookmark
err = core.WriteTimestamp(ctx, ts)
@ -157,7 +161,7 @@ func compressActions(actions []core.Action) ([]byte, error) {
return buf.Bytes(), nil
}
func postActions(ctx infra.DnoteCtx, APIKey string, payload *bytes.Buffer) (*http.Response, error) {
func postActions(ctx infra.DnoteCtx, APIKey string, payload io.Reader) (*http.Response, error) {
endpoint := fmt.Sprintf("%s/v1/sync", ctx.APIEndpoint)
req, err := http.NewRequest("POST", endpoint, payload)
if err != nil {

View file

@ -242,12 +242,7 @@ func WriteDnote(ctx infra.DnoteCtx, dnote infra.Dnote) error {
notePath := GetDnotePath(ctx)
err = ioutil.WriteFile(notePath, d, 0644)
if err != nil {
return err
}
return nil
return ioutil.WriteFile(notePath, d, 0644)
}
func WriteConfig(ctx infra.DnoteCtx, config infra.Config) error {
@ -258,12 +253,7 @@ func WriteConfig(ctx infra.DnoteCtx, config infra.Config) error {
configPath := GetConfigPath(ctx)
err = ioutil.WriteFile(configPath, d, 0644)
if err != nil {
return err
}
return nil
return ioutil.WriteFile(configPath, d, 0644)
}
// LogAction appends the action to the action log and updates the last_action
@ -297,12 +287,7 @@ func WriteActionLog(ctx infra.DnoteCtx, actions []Action) error {
return errors.Wrap(err, "Failed to marshal newly generated actions to JSON")
}
err = ioutil.WriteFile(path, d, 0644)
if err != nil {
return err
}
return nil
return ioutil.WriteFile(path, d, 0644)
}
func ClearActionLog(ctx infra.DnoteCtx) error {
@ -336,11 +321,7 @@ func ReadActionLog(ctx infra.DnoteCtx) ([]Action, error) {
}
err = json.Unmarshal(b, &ret)
if err != nil {
return ret, err
}
return ret, nil
return ret, err
}
func ReadConfig(ctx infra.DnoteCtx) (infra.Config, error) {
@ -353,11 +334,7 @@ func ReadConfig(ctx infra.DnoteCtx) (infra.Config, error) {
}
err = yaml.Unmarshal(b, &ret)
if err != nil {
return ret, err
}
return ret, nil
return ret, err
}
func UpdateLastActionTimestamp(ctx infra.DnoteCtx, val int64) error {

View file

@ -27,7 +27,7 @@ func TestReduceAddNote(t *testing.T) {
Data: b,
Timestamp: 1517629805,
}
if err := Reduce(ctx, action); err != nil {
if err = Reduce(ctx, action); err != nil {
t.Fatal(errors.Wrap(err, "Failed to process action"))
}
@ -70,7 +70,7 @@ func TestReduceAddNote_SortByAddedOn(t *testing.T) {
Data: b,
Timestamp: 1515199944,
}
if err := Reduce(ctx, action); err != nil {
if err = Reduce(ctx, action); err != nil {
t.Fatal(errors.Wrap(err, "Failed to process action"))
}
@ -115,7 +115,7 @@ func TestReduceRemoveNote(t *testing.T) {
Data: b,
Timestamp: 1517629805,
}
if err := Reduce(ctx, action); err != nil {
if err = Reduce(ctx, action); err != nil {
t.Fatal(errors.Wrap(err, "Failed to process action"))
}
@ -197,7 +197,7 @@ func TestReduceAddBook(t *testing.T) {
Data: b,
Timestamp: 1517629805,
}
if err := Reduce(ctx, action); err != nil {
if err = Reduce(ctx, action); err != nil {
t.Fatal(errors.Wrap(err, "Failed to process action"))
}
@ -229,7 +229,7 @@ func TestReduceRemoveBook(t *testing.T) {
Data: b,
Timestamp: 1517629805,
}
if err := Reduce(ctx, action); err != nil {
if err = Reduce(ctx, action); err != nil {
t.Fatal(errors.Wrap(err, "Failed to process action"))
}

View file

@ -23,7 +23,7 @@ var binaryName = "test-dnote"
func TestMain(m *testing.M) {
if err := exec.Command("go", "build", "-o", binaryName).Run(); err != nil {
log.Printf(errors.Wrap(err, "Failed to build a binary").Error())
log.Print(errors.Wrap(err, "Failed to build a binary").Error())
os.Exit(1)
}
@ -66,7 +66,7 @@ func TestInit(t *testing.T) {
runDnoteCmd(ctx)
// Test
if !utils.FileExists(fmt.Sprintf("%s", ctx.DnoteDir)) {
if !utils.FileExists(ctx.DnoteDir) {
t.Errorf("dnote directory was not initialized")
}
if !utils.FileExists(fmt.Sprintf("%s/%s", ctx.DnoteDir, core.DnoteFilename)) {

View file

@ -186,11 +186,7 @@ func readSchema(ctx infra.DnoteCtx) (schema, error) {
}
err = yaml.Unmarshal(b, &ret)
if err != nil {
return ret, err
}
return ret, nil
return ret, err
}
func writeSchema(ctx infra.DnoteCtx, s schema) error {

View file

@ -82,7 +82,7 @@ func CopyFile(src, dest string) error {
return errors.Wrap(err, "Failed to copy the file content")
}
if err := out.Sync(); err != nil {
if err = out.Sync(); err != nil {
return errors.Wrap(err, "Failed to flush the output file to disk")
}
@ -91,12 +91,12 @@ func CopyFile(src, dest string) error {
return errors.Wrap(err, "Failed to get file info for the input file")
}
if err := os.Chmod(dest, fi.Mode()); err != nil {
if err = os.Chmod(dest, fi.Mode()); err != nil {
return errors.Wrap(err, "Failed to copy permission to the output file")
}
// Close the output file
if err := out.Close(); err != nil {
if err = out.Close(); err != nil {
return errors.Wrap(err, "Failed to close the output file")
}