Fix issues reported by the 'unused', 'staticcheck', 'gosimple' linters. Closes #1360

This commit is contained in:
Puskar Basu
2022-01-31 21:30:54 +05:30
committed by GitHub
parent 758774dd16
commit f2d56ddeb8
6 changed files with 38 additions and 23 deletions

18
.golangci.yml Normal file
View File

@@ -0,0 +1,18 @@
linters:
disable-all: true
enable:
- deadcode
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
run:
timeout: 5m
skip-dirs:
- "tests/acceptance"

View File

@@ -58,9 +58,6 @@ type InteractiveClient struct {
schemaMetadata *schema.Metadata
highlighter *Highlighter
// status update hooks
statusHook statushooks.StatusHooks
}
func getHighlighter(theme string) *Highlighter {

View File

@@ -28,7 +28,6 @@ type PluginManager struct {
pb.UnimplementedPluginManagerServer
Plugins map[string]*runningPlugin
configDir string
mut sync.Mutex
connectionConfig map[string]*pb.ConnectionConfig
logger hclog.Logger

View File

@@ -31,7 +31,7 @@ func Complete(input *CompleterInput) []prompt.Suggest {
func completerFromArgsOf(cmd string) completer {
return func(input *CompleterInput) []prompt.Suggest {
metaQueryDefinition, _ := metaQueryDefinitions[cmd]
metaQueryDefinition := metaQueryDefinitions[cmd]
suggestions := make([]prompt.Suggest, len(metaQueryDefinition.args))
for idx, arg := range metaQueryDefinition.args {
suggestions[idx] = prompt.Suggest{Text: arg.value, Description: arg.description, Output: arg.value}

View File

@@ -438,8 +438,8 @@ func TestGetConnectionsToUpdate(t *testing.T) {
updates, res := NewConnectionUpdates([]string{"a", "b"})
if res.Error != nil && test.expected != "ERROR" {
continue
t.Fatalf("NewConnectionUpdates failed with unexpected error: %v", err)
continue
}
expectedUpdates := test.expected.(*ConnectionUpdates)
@@ -521,7 +521,7 @@ func resetConfig(test getConnectionsToUpdateTest) {
connectionStatePath := filepaths.ConnectionStatePath()
os.Remove(connectionStatePath)
for i := range test.required {
for i := range test.required {
os.Remove(connectionConfigPath(i))
}
}

View File

@@ -291,24 +291,25 @@ func decodeParam(block *hcl.Block, runCtx *RunContext, parentName string) (*modc
content, diags := block.Body.Content(ParamDefBlockSchema)
if attr, exists := content.Attributes["description"]; exists {
valDiags := gohcl.DecodeExpression(attr.Expr, runCtx.EvalCtx, &def.Description)
diags = append(diags, valDiags...)
moreDiags := gohcl.DecodeExpression(attr.Expr, runCtx.EvalCtx, &def.Description)
diags = append(diags, moreDiags...)
}
if attr, exists := content.Attributes["default"]; exists {
v, diags := attr.Expr.Value(runCtx.EvalCtx)
if diags.HasErrors() {
return nil, diags
}
// convert the raw default into a postgres representation
if valStr, err := ctyToPostgresString(v); err == nil {
def.Default = utils.ToStringPointer(valStr)
} else {
diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: fmt.Sprintf("%s has invalid parameter config", parentName),
Detail: err.Error(),
Subject: &attr.Range,
})
v, moreDiags := attr.Expr.Value(runCtx.EvalCtx)
diags = append(diags, moreDiags...)
if !moreDiags.HasErrors() {
// convert the raw default into a postgres representation
if valStr, err := ctyToPostgresString(v); err == nil {
def.Default = utils.ToStringPointer(valStr)
} else {
diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: fmt.Sprintf("%s has invalid parameter config", parentName),
Detail: err.Error(),
Subject: &attr.Range,
})
}
}
}
return def, diags