Closed wtnb75 closed 1 year ago
revive
main.go:1:1: should have a package comment
exec_os.go:13:6: exported type OsRunner should have comment or be unexported
exec_os.go:32:1: exported method OsRunner.Run should have comment or be unexported
exec_if.go:19:6: exported type SrvConfig should have comment or be unexported
exec_if.go:30:6: exported type Runner should have comment or be unexported
exec_if.go:34:1: exported function OutputFilter should have comment or be unexported
exec_if.go:94:1: exported function RunBy should have comment or be unexported
exec_if.go:162:1: exported function DoPipe should have comment or be unexported
exec_wasmer.go:13:6: exported type WasmerRunner should have comment or be unexported
exec_wasmer.go:46:1: exported method WasmerRunner.Run should have comment or be unexported
exec_os.go:37:2: don't use underscores in Go names; var cmd_stdin should be cmdStdin
exec_os.go:37:13: don't use underscores in Go names; var cmd_stdout should be cmdStdout
exec_os.go:37:25: don't use underscores in Go names; var cmd_stderr should be cmdStderr
exec_if.go:26:2: struct field JsonLog should be JSONLog
exec_if.go:96:2: don't use underscores in Go names; var http_status should be httpStatus
staticcheck
exec_wasmer.go:5:2: "io/ioutil" has been deprecated since Go 1.16: As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code. See the specific function documentation for details. (SA1019)
golangci-lint
exec_if.go:149:17: Error return value is not checked (errcheck)
go OutputFilter(pr, w, &wg)
^
exec_os.go:52:11: Error return value is not checked (errcheck)
go DoPipe(stdin, cmd_stdin, &wg)
^
exec_os.go:54:11: Error return value is not checked (errcheck)
go DoPipe(cmd_stderr, stderr, &wg)
^
exec_wasmer.go:92:22: Error return value of `runner.pipeStdout` is not checked (errcheck)
go runner.pipeStdout(wasiEnv, stdout, &wg)
^
exec_wasmer.go:94:22: Error return value of `runner.pipeStderr` is not checked (errcheck)
go runner.pipeStderr(wasiEnv, stderr, &wg)
^
exec_wasmer.go:5:2: SA1019: "io/ioutil" has been deprecated since Go 1.16: As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code. See the specific function documentation for details. (staticcheck)
"io/ioutil"
^
golangci-lint run --enable-all
WARN [runner] The linter 'nosnakecase' is deprecated (since v1.48.1) due to: The repository of the linter has been deprecated by the owner. Replaced by revive(var-naming).
WARN [runner] The linter 'deadcode' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused.
WARN [runner] The linter 'structcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused.
WARN [runner] The linter 'exhaustivestruct' is deprecated (since v1.46.0) due to: The owner seems to have abandoned the linter. Replaced by exhaustruct.
WARN [runner] The linter 'interfacer' is deprecated (since v1.38.0) due to: The repository of the linter has been archived by the owner.
WARN [runner] The linter 'varcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused.
WARN [runner] The linter 'ifshort' is deprecated (since v1.48.0) due to: The repository of the linter has been deprecated by the owner.
WARN [runner] The linter 'scopelint' is deprecated (since v1.39.0) due to: The repository of the linter has been deprecated by the owner. Replaced by exportloopref.
WARN [runner] The linter 'maligned' is deprecated (since v1.38.0) due to: The repository of the linter has been archived by the owner. Replaced by govet 'fieldalignment'.
WARN [runner] The linter 'golint' is deprecated (since v1.41.0) due to: The repository of the linter has been archived by the owner. Replaced by revive.
WARN [linters_context] rowserrcheck is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649.
WARN [linters_context] sqlclosecheck is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649.
WARN [linters_context] structcheck is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649.
WARN [linters_context] wastedassign is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649.
exec_if.go:149:17: Error return value is not checked (errcheck)
go OutputFilter(pr, w, &wg)
^
exec_os.go:52:11: Error return value is not checked (errcheck)
go DoPipe(stdin, cmd_stdin, &wg)
^
exec_os.go:54:11: Error return value is not checked (errcheck)
go DoPipe(cmd_stderr, stderr, &wg)
^
exec_wasmer.go:92:22: Error return value of `runner.pipeStdout` is not checked (errcheck)
go runner.pipeStdout(wasiEnv, stdout, &wg)
^
exec_wasmer.go:94:22: Error return value of `runner.pipeStderr` is not checked (errcheck)
go runner.pipeStderr(wasiEnv, stderr, &wg)
^
exec_if.go:94: Function 'RunBy' is too long (65 > 60) (funlen)
func RunBy(opts SrvConfig, runner Runner, w http.ResponseWriter, r *http.Request) error {
exec_wasmer.go:46: Function 'Run' has too many statements (44 > 40) (funlen)
func (runner *WasmerRunner) Run(conf SrvConfig, cmdname string, envvar map[string]string, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer) error {
exec_os.go:13: File is not `gofumpt`-ed (gofumpt)
type OsRunner struct {
}
exec_wasmer.go:13: File is not `gofumpt`-ed (gofumpt)
type WasmerRunner struct {
}
main.go:13: File is not `gofumpt`-ed (gofumpt)
var opts SrvConfig
var runner Runner
exec_if.go:26:2: struct field `JsonLog` should be `JSONLog` (golint)
JsonLog bool `long:"json-log"`
^
exec_if.go:96:2: don't use underscores in Go names; var `http_status` should be `httpStatus` (golint)
http_status := http.StatusOK
^
exec_os.go:37:2: don't use underscores in Go names; var `cmd_stdin` should be `cmdStdin` (golint)
cmd_stdin, cmd_stdout, cmd_stderr, err := runner.getPipe(cmd)
^
main.go:53:12: G112: Potential Slowloris Attack because ReadHeaderTimeout is not configured in the http.Server (gosec)
server := http.Server{
Addr: opts.Addr,
Handler: nil,
}
exec_if.go:31: line is 125 characters (lll)
Run(conf SrvConfig, cmdname string, envvar map[string]string, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer) error
exec_os.go:16: line is 126 characters (lll)
func (runner *OsRunner) getPipe(cmd *exec.Cmd) (stdin io.WriteCloser, stdout io.ReadCloser, stderr io.ReadCloser, err error) {
exec_os.go:32: line is 150 characters (lll)
func (runner *OsRunner) Run(conf SrvConfig, cmdname string, envvar map[string]string, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer) error {
exec_if_test.go:63: line is 148 characters (lll)
func (runner runner1) Run(conf SrvConfig, cmdname string, envvar map[string]string, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer) error {
exec_if_test.go:71: line is 148 characters (lll)
func (runner runner2) Run(conf SrvConfig, cmdname string, envvar map[string]string, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer) error {
exec_if.go:19:16: struct of size 96 bytes could be of size 88 bytes (maligned)
type SrvConfig struct {
^
exec_if.go:38:2: assignments should only be cuddled with other assignments (wsl)
rd := bufio.NewReader(stdout)
^
exec_if.go:46:3: if statements should only be cuddled with assignments (wsl)
if len(line) == 0 {
^
exec_if.go:50:3: assignments should only be cuddled with other assignments (wsl)
linestr := string(line)
^
exec_if.go:52:3: only one cuddle assignment allowed before if statement (wsl)
if idx == -1 {
^
exec_if.go:56:3: assignments should only be cuddled with other assignments (wsl)
k := strings.TrimSpace(linestr[:idx])
^
exec_if.go:58:3: only one cuddle assignment allowed before if statement (wsl)
if strings.ToLower(k) == "status" {
^
exec_if.go:40:2: for statement without condition should never be cuddled (wsl)
for {
^
exec_if.go:71:2: only one cuddle assignment allowed before if statement (wsl)
if err != nil {
^
exec_if.go:75:2: expressions should not be cuddled with blocks (wsl)
slog.Debug("write body", "length", olen)
^
exec_if.go:76:2: return statements should not be cuddled if block has more than two lines (wsl)
return nil
^
exec_if.go:83:3: if statements should only be cuddled with assignments (wsl)
if fi, err := os.Stat(filepath.Join(basedir, ret)); err == nil {
^
exec_if.go:91:2: return statements should not be cuddled if block has more than two lines (wsl)
return "", "", fmt.Errorf("not found %s", path)
^
exec_if.go:97:2: only one cuddle assignment allowed before defer statement (wsl)
defer func() {
^
exec_if.go:113:2: expressions should not be cuddled with blocks (wsl)
slog.Debug("memo", "host", host, "port", port)
^
exec_if.go:118:3: return statements should not be cuddled if block has more than two lines (wsl)
return err
^
exec_if.go:120:2: expressions should not be cuddled with blocks (wsl)
slog.Debug("memo(path)", "bn", bn, "bn2", bn2, "rest", rest)
^
exec_if.go:142:2: only one cuddle assignment allowed before range statement (wsl)
for k, v := range r.Header {
^
exec_if.go:147:2: declarations should never be cuddled (wsl)
var wg sync.WaitGroup
^
exec_if.go:148:2: expressions should not be cuddled with declarations or returns (wsl)
wg.Add(1)
^
exec_os.go:21:2: if statements should only be cuddled with assignments (wsl)
if stdout, err = cmd.StdoutPipe(); err != nil {
^
exec_os.go:42:2: only one cuddle assignment allowed before range statement (wsl)
for k, v := range envvar {
^
exec_os.go:50:2: declarations should never be cuddled (wsl)
var wg sync.WaitGroup
^
exec_os.go:51:2: expressions should not be cuddled with declarations or returns (wsl)
wg.Add(1)
^
exec_wasmer.go:55:2: only one cuddle assignment allowed before range statement (wsl)
for k, v := range envvar {
^
exec_wasmer.go:90:2: declarations should never be cuddled (wsl)
var wg sync.WaitGroup
^
exec_wasmer.go:91:2: expressions should not be cuddled with declarations or returns (wsl)
wg.Add(1)
^
main.go:20:12: ReplaceAttr is missing in HandlerOptions (exhaustivestruct)
logopt = slog.HandlerOptions{Level: slog.LevelDebug, AddSource: true}
^
main.go:22:12: AddSource, Level, ReplaceAttr are missing in HandlerOptions (exhaustivestruct)
logopt = slog.HandlerOptions{}
^
exec_if_test.go:92:10: Verbose, Proto, Prefix, Suffix, JsonLog, Wasm are missing in SrvConfig (exhaustivestruct)
opts := SrvConfig{Addr: ":9999", BaseDir: "."}
^
exec_if_test.go:99:7: ProtoMajor, ProtoMinor, Header, Body, GetBody, ContentLength, TransferEncoding, Close, Host, Form, PostForm, MultipartForm, Trailer, TLS, Cancel, Response are missing in Request (exhaustivestruct)
r := http.Request{
^
exec_if_test.go:118:10: Verbose, Proto, Prefix, Suffix, JsonLog, Wasm are missing in SrvConfig (exhaustivestruct)
opts := SrvConfig{Addr: ":9999", BaseDir: "."}
^
exec_if_test.go:125:7: ProtoMajor, ProtoMinor, Header, Body, GetBody, ContentLength, TransferEncoding, Close, Host, Form, PostForm, MultipartForm, Trailer, TLS, Cancel, Response are missing in Request (exhaustivestruct)
r := http.Request{
^
main.go:14:5: runner is a global variable (gochecknoglobals)
var runner Runner
^
exec_if.go:54:11: err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"invalid header format\")" (goerr113)
return fmt.Errorf("invalid header format")
^
exec_if_test.go:38:2: variable 'err' is only used in the if-statement (exec_if_test.go:40:2); consider using short syntax (ifshort)
err := DoPipe(rd, wr, &wg)
^
exec_if_test.go:50:2: variable 'err' is only used in the if-statement (exec_if_test.go:52:2); consider using short syntax (ifshort)
err := DoPipe(rd, wr, &wg)
^
exec_if.go:44:4: return with no blank line before (nlreturn)
return err
^
exec_if.go:48:4: break with no blank line before (nlreturn)
break
^
exec_if.go:73:3: return with no blank line before (nlreturn)
return err
^
exec_if.go:111:3: return with no blank line before (nlreturn)
return err
^
exec_if.go:103:14: http_status contains underscore. You should use mixedCap or MixedCap. (nosnakecase)
"status", http_status,
^
exec_if.go:152:3: http_status contains underscore. You should use mixedCap or MixedCap. (nosnakecase)
http_status = http.StatusInternalServerError
^
exec_if.go:153:17: http_status contains underscore. You should use mixedCap or MixedCap. (nosnakecase)
w.WriteHeader(http_status)
^
exec_os.go:58:2: cmd_stdin contains underscore. You should use mixedCap or MixedCap. (nosnakecase)
cmd_stdin.Close()
^
exec_os.go:59:2: cmd_stderr contains underscore. You should use mixedCap or MixedCap. (nosnakecase)
cmd_stderr.Close()
^
exec_if_test.go:13:1: Function TestSplit missing the call to method parallel (paralleltest)
func TestSplit(t *testing.T) {
^
exec_if_test.go:26:1: Function TestSplitNotFound missing the call to method parallel (paralleltest)
func TestSplitNotFound(t *testing.T) {
^
exec_if_test.go:33:1: Function TestDoPipeWriteClose missing the call to method parallel (paralleltest)
func TestDoPipeWriteClose(t *testing.T) {
^
exec_if_test.go:45:1: Function TestDoPipeReadClose missing the call to method parallel (paralleltest)
func TestDoPipeReadClose(t *testing.T) {
^
exec_if_test.go:91:1: Function TestRunBy missing the call to method parallel (paralleltest)
func TestRunBy(t *testing.T) {
^
exec_if_test.go:117:1: Function TestRunByStatusCode missing the call to method parallel (paralleltest)
func TestRunByStatusCode(t *testing.T) {
^
exec_if_test.go:100:15: "GET" can be replaced by http.MethodGet (usestdlibvars)
Method: "GET",
^
exec_if_test.go:126:15: "GET" can be replaced by http.MethodGet (usestdlibvars)
Method: "GET",
^
main.go:57:2: variable name 'l' is too short for the scope of its usage (varnamelen)
l, err := net.Listen(opts.Proto, opts.Addr)
^
exec_wasmer.go:47:2: variable name 'fn' is too short for the scope of its usage (varnamelen)
fn := filepath.Join(conf.BaseDir, cmdname)
^
exec_if_test.go:121:2: variable name 'w' is too short for the scope of its usage (varnamelen)
w := writer{
^
exec_if_test.go:95:2: variable name 'w' is too short for the scope of its usage (varnamelen)
w := writer{
^
exec_if.go:57:3: variable name 'v' is too short for the scope of its usage (varnamelen)
v := strings.TrimSpace(linestr[idx+1:])
^
exec_if.go:34:37: parameter name 'w' is too short for the scope of its usage (varnamelen)
func OutputFilter(stdout io.Reader, w http.ResponseWriter, wg *sync.WaitGroup) error {
^
exec_os.go:47:10: error returned from external package is unwrapped: sig: func (*os/exec.Cmd).Start() error (wrapcheck)
return err
^
exec_if_test.go:84:9: error returned from external package is unwrapped: sig: func (*bytes.Buffer).Write(p []byte) (n int, err error) (wrapcheck)
return w.out.Write(data)
^
だいぶ減った。
golangci-lintのデフォルトで入っているやつではerrcheckはまだ引っかかる。goroutineからエラーを返すのが、sync.WaitGroupではエラーを渡せない。そのためだけにchannelを使うのもなあ…ならsync.WaitGroupも使う必要ないじゃん、という。
golang.org/x/sync/errgroup
ならエラーも渡せるらしい。
errcheckも通した。--enable-all
を通すまでやる必要はないかな。
CIにも組み込んだし、このへんでクローズしておく。
現状