Skip to content

Commit

Permalink
Remove unnecessary install tools (#130)
Browse files Browse the repository at this point in the history
* Install golint first

* Setup reviewdog/action-staticcheck

- Use staticcheck instead of golint,govet
- Use reviewdog for gofmt

* Deprecation of io/ioutil package

ref. https://go.dev/doc/go1.16#ioutil

* Return err if `io.ReadAll` gets an error

* Use pull_request_target for reviewdog
  • Loading branch information
toshimaru authored Dec 11, 2021
1 parent cb8576a commit 9f9dabd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
17 changes: 7 additions & 10 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
name: reviewdog
on: [pull_request]
on: [pull_request_target]
jobs:
reviewdog:
name: reviewdog
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-go@v2
with:
go-version: '1.17'
- name: install tools
run: |
go get -u golang.org/x/lint/golint
go get github.com/mattn/go-isatty
- uses: reviewdog/action-staticcheck@v1
with:
fail_on_error: true
- uses: reviewdog/action-setup@v1
- name: Run reviewdog
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
reviewdog -reporter=github-pr-review \
-runners=golint,govet,gofmt \
-fail-on-error
# reviewdog doesn't work with go vet, so run again
- run: go vet ./...
reviewdog -reporter=github-pr-review -runners=gofmt
10 changes: 5 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"

"github.com/alecthomas/chroma"
Expand Down Expand Up @@ -70,10 +69,12 @@ func cmdMain(cmd *cobra.Command, args []string) (err error) {
lexer = lexers.Get(language)
}

cmd.SilenceUsage = true

if len(args) < 1 || args[0] == "-" {
if data, err = ioutil.ReadAll(cmd.InOrStdin()); err != nil {
if data, err = io.ReadAll(cmd.InOrStdin()); err != nil {
cmd.PrintErrln("Error:", err)
return
return err
}
if lexer == nil {
lexer = lexers.Analyse(string(data))
Expand All @@ -82,7 +83,7 @@ func cmdMain(cmd *cobra.Command, args []string) (err error) {
} else {
var lastErr error
for _, filename := range args {
if data, err = ioutil.ReadFile(filename); err != nil {
if data, err = os.ReadFile(filename); err != nil {
cmd.PrintErrln("Error:", err)
lastErr = err
continue
Expand All @@ -93,7 +94,6 @@ func cmdMain(cmd *cobra.Command, args []string) (err error) {
printData(&data, cmd, lexer)
}
if lastErr != nil {
cmd.SilenceUsage = true
return lastErr
}
}
Expand Down
4 changes: 2 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"bytes"
"io/ioutil"
"os"
"os/exec"
"testing"

Expand Down Expand Up @@ -59,7 +59,7 @@ func TestShell(t *testing.T) {
outfile := "testdata/output"
cmd := exec.Command("bash", "-c", "echo 'package main' | ./nyan > "+outfile)
err := cmd.Run()
data, err := ioutil.ReadFile(outfile)
data, err := os.ReadFile(outfile)
assert.Nil(t, err)
assert.Equal(t, "package main\n", string(data))
})
Expand Down

0 comments on commit 9f9dabd

Please sign in to comment.