golangci-lint run
```console
$ golangci-lint run
internal/ast/ast.go:87:1: unlabelStmt: label Token is redundant (gocritic)
Token:
^
internal/ast/parser.go:26:1: unlabelStmt: label Token is redundant (gocritic)
Token:
^
internal/ast/parser.go:89:1: unlabelStmt: label BeforeToken is redundant (gocritic)
BeforeToken:
^
internal/ast/object.go:9:2: `name` is unused (structcheck)
name string
^
internal/ast/object.go:56:3: shadow: declaration of "objAttr" shadows declaration at line 52 (govet)
objAttr := newObjectAttribute(name, exprTokens, commentTokens)
^
internal/handler/block.go:31:9: ST1005: error strings should not be capitalized (stylecheck)
return fmt.Errorf("This function should not be called")
^
internal/walker/walker.go:43:26: Error return value of `w.Handler.HandleBody` is not checked (errcheck)
w.Handler.HandleBody(body, key, keytrail)
^
internal/walker/walker.go:81:24: Error return value of `w.Handler.HandleBody` is not checked (errcheck)
w.Handler.HandleBody(body, key, keytrail)
^
internal/walker/walker.go:122:25: Error return value of `w.Handler.HandleBody` is not checked (errcheck)
w.Handler.HandleBody(body, "", keytrail)
^
internal/walker/walker.go:141:28: Error return value of `w.Handler.HandleObject` is not checked (errcheck)
w.Handler.HandleObject(obj, key, keytrail)
^
internal/walker/walker.go:176:26: Error return value of `w.Handler.HandleObject` is not checked (errcheck)
w.Handler.HandleObject(obj, key, keytrail)
^
internal/walker/walker.go:94:3: shadow: declaration of "keytrail" shadows declaration at line 86 (govet)
keytrail := append(keytrail, block.Type())
^
hcledit.go:64:16: Error return value of `h.reload` is not checked (errcheck)
defer h.reload()
^
hcledit.go:91:16: Error return value of `h.reload` is not checked (errcheck)
defer h.reload()
^
hcledit.go:116:16: Error return value of `h.reload` is not checked (errcheck)
defer h.reload()
^
hcledit.go:76:2: importShadow: shadow of imported from 'github.com/mercari/hcledit/internal/handler' package 'handler' (gocritic)
handler, err := handler.New(value, opt.comment, opt.afterKey)
^
hcledit.go:104:2: importShadow: shadow of imported from 'github.com/mercari/hcledit/internal/handler' package 'handler' (gocritic)
handler, _ := handler.NewReadHandler(results)
^
hcledit.go:138:2: importShadow: shadow of imported from 'github.com/mercari/hcledit/internal/handler' package 'handler' (gocritic)
handler, err := handler.New(value, opt.comment, opt.afterKey)
^
hcledit.go:103:40: S1019: should use make(map[string]cty.Value) instead (gosimple)
results := make(map[string]cty.Value, 0)
^
hcledit.go:186:42: S1019: should use make(map[string]interface{}) instead (gosimple)
results := make(map[string]interface{}, 0)
^
cmd/hcledit/internal/command/read_test.go:98:21: Using the variable on range scope `tc` in function literal (scopelint)
args := []string{tc.query, fixture}
^
cmd/hcledit/internal/command/read_test.go:99:24: Using the variable on range scope `tc` in function literal (scopelint)
got, err := runRead(tc.opts, args)
^
cmd/hcledit/internal/command/read_test.go:104:14: Using the variable on range scope `tc` in function literal (scopelint)
if got != tc.want {
^
cmd/hcledit/internal/command/create.go:41:10: ST1005: error strings should not end with punctuation or a newline (stylecheck)
return fmt.Errorf("[ERROR] Failed to read file: %s\n", err)
^
cmd/hcledit/internal/command/create.go:46:10: ST1005: error strings should not end with punctuation or a newline (stylecheck)
return fmt.Errorf("[ERROR] Failed to convert input to specific type: %s\n", err)
^
cmd/hcledit/internal/command/create.go:50:10: ST1005: error strings should not end with punctuation or a newline (stylecheck)
return fmt.Errorf("[ERROR] Failed to create: %s\n", err)
^
cmd/hcledit/internal/command/create.go:67:15: ST1005: error strings should not be capitalized (stylecheck)
return nil, fmt.Errorf("Unsupported type: %s", typeStr)
^
internal/converter/converter.go:72:14: ST1005: error strings should not be capitalized (stylecheck)
return nil, fmt.Errorf("Unsupported cty type")
^
example_test.go:43:15: Error return value of `editor.Create` is not checked (errcheck)
editor.Create("resource.google_container_node_pool.*.node_config.disk_size_gb", "200")
^
example_test.go:46:15: Error return value of `editor.Create` is not checked (errcheck)
editor.Create("resource.google_container_node_pool.*.master_auth", hcledit.BlockVal())
^
example_test.go:47:15: Error return value of `editor.Create` is not checked (errcheck)
editor.Create("resource.google_container_node_pool.*.master_auth.username", "")
^
example_test.go:51:15: Error return value of `editor.Update` is not checked (errcheck)
editor.Update("resource.google_container_node_pool.*.node_config.machine_type", "COS")
^
example_test.go:52:15: Error return value of `editor.Update` is not checked (errcheck)
editor.Update("resource.google_container_node_pool.*.node_config.preemptible", true)
^
example_test.go:55:15: Error return value of `editor.Delete` is not checked (errcheck)
editor.Delete("resource.google_container_node_pool.*.timeouts")
^
write_test.go:53:12: G306: Expect WriteFile permissions to be 0600 or less (gosec)
if err := ioutil.WriteFile(tempFile, []byte(`
attribute1 = "str1"
`), 0666); err != nil {
```
WHAT
Fixed most of the lint errors by
golangci-lint
.
```console $ golangci-lint run internal/ast/ast.go:87:1: unlabelStmt: label Token is redundant (gocritic) Token: ^ internal/ast/parser.go:26:1: unlabelStmt: label Token is redundant (gocritic) Token: ^ internal/ast/parser.go:89:1: unlabelStmt: label BeforeToken is redundant (gocritic) BeforeToken: ^ internal/ast/object.go:9:2: `name` is unused (structcheck) name string ^ internal/ast/object.go:56:3: shadow: declaration of "objAttr" shadows declaration at line 52 (govet) objAttr := newObjectAttribute(name, exprTokens, commentTokens) ^ internal/handler/block.go:31:9: ST1005: error strings should not be capitalized (stylecheck) return fmt.Errorf("This function should not be called") ^ internal/walker/walker.go:43:26: Error return value of `w.Handler.HandleBody` is not checked (errcheck) w.Handler.HandleBody(body, key, keytrail) ^ internal/walker/walker.go:81:24: Error return value of `w.Handler.HandleBody` is not checked (errcheck) w.Handler.HandleBody(body, key, keytrail) ^ internal/walker/walker.go:122:25: Error return value of `w.Handler.HandleBody` is not checked (errcheck) w.Handler.HandleBody(body, "", keytrail) ^ internal/walker/walker.go:141:28: Error return value of `w.Handler.HandleObject` is not checked (errcheck) w.Handler.HandleObject(obj, key, keytrail) ^ internal/walker/walker.go:176:26: Error return value of `w.Handler.HandleObject` is not checked (errcheck) w.Handler.HandleObject(obj, key, keytrail) ^ internal/walker/walker.go:94:3: shadow: declaration of "keytrail" shadows declaration at line 86 (govet) keytrail := append(keytrail, block.Type()) ^ hcledit.go:64:16: Error return value of `h.reload` is not checked (errcheck) defer h.reload() ^ hcledit.go:91:16: Error return value of `h.reload` is not checked (errcheck) defer h.reload() ^ hcledit.go:116:16: Error return value of `h.reload` is not checked (errcheck) defer h.reload() ^ hcledit.go:76:2: importShadow: shadow of imported from 'github.com/mercari/hcledit/internal/handler' package 'handler' (gocritic) handler, err := handler.New(value, opt.comment, opt.afterKey) ^ hcledit.go:104:2: importShadow: shadow of imported from 'github.com/mercari/hcledit/internal/handler' package 'handler' (gocritic) handler, _ := handler.NewReadHandler(results) ^ hcledit.go:138:2: importShadow: shadow of imported from 'github.com/mercari/hcledit/internal/handler' package 'handler' (gocritic) handler, err := handler.New(value, opt.comment, opt.afterKey) ^ hcledit.go:103:40: S1019: should use make(map[string]cty.Value) instead (gosimple) results := make(map[string]cty.Value, 0) ^ hcledit.go:186:42: S1019: should use make(map[string]interface{}) instead (gosimple) results := make(map[string]interface{}, 0) ^ cmd/hcledit/internal/command/read_test.go:98:21: Using the variable on range scope `tc` in function literal (scopelint) args := []string{tc.query, fixture} ^ cmd/hcledit/internal/command/read_test.go:99:24: Using the variable on range scope `tc` in function literal (scopelint) got, err := runRead(tc.opts, args) ^ cmd/hcledit/internal/command/read_test.go:104:14: Using the variable on range scope `tc` in function literal (scopelint) if got != tc.want { ^ cmd/hcledit/internal/command/create.go:41:10: ST1005: error strings should not end with punctuation or a newline (stylecheck) return fmt.Errorf("[ERROR] Failed to read file: %s\n", err) ^ cmd/hcledit/internal/command/create.go:46:10: ST1005: error strings should not end with punctuation or a newline (stylecheck) return fmt.Errorf("[ERROR] Failed to convert input to specific type: %s\n", err) ^ cmd/hcledit/internal/command/create.go:50:10: ST1005: error strings should not end with punctuation or a newline (stylecheck) return fmt.Errorf("[ERROR] Failed to create: %s\n", err) ^ cmd/hcledit/internal/command/create.go:67:15: ST1005: error strings should not be capitalized (stylecheck) return nil, fmt.Errorf("Unsupported type: %s", typeStr) ^ internal/converter/converter.go:72:14: ST1005: error strings should not be capitalized (stylecheck) return nil, fmt.Errorf("Unsupported cty type") ^ example_test.go:43:15: Error return value of `editor.Create` is not checked (errcheck) editor.Create("resource.google_container_node_pool.*.node_config.disk_size_gb", "200") ^ example_test.go:46:15: Error return value of `editor.Create` is not checked (errcheck) editor.Create("resource.google_container_node_pool.*.master_auth", hcledit.BlockVal()) ^ example_test.go:47:15: Error return value of `editor.Create` is not checked (errcheck) editor.Create("resource.google_container_node_pool.*.master_auth.username", "") ^ example_test.go:51:15: Error return value of `editor.Update` is not checked (errcheck) editor.Update("resource.google_container_node_pool.*.node_config.machine_type", "COS") ^ example_test.go:52:15: Error return value of `editor.Update` is not checked (errcheck) editor.Update("resource.google_container_node_pool.*.node_config.preemptible", true) ^ example_test.go:55:15: Error return value of `editor.Delete` is not checked (errcheck) editor.Delete("resource.google_container_node_pool.*.timeouts") ^ write_test.go:53:12: G306: Expect WriteFile permissions to be 0600 or less (gosec) if err := ioutil.WriteFile(tempFile, []byte(` attribute1 = "str1" `), 0666); err != nil { ```golangci-lint run
WHY
To keep code quality.