refactor: implement all simple static checks (#2895)

Signed-off-by: Larry Bordowitz <laurence.bordowitz@gmail.com>
This commit is contained in:
Larry Bordowitz 2025-06-10 14:48:43 -05:00 committed by GitHub
parent 6fa79a7de3
commit 9b6a8fae60
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 27 additions and 28 deletions

View file

@ -266,8 +266,8 @@ func realMain() int {
}
// Prefix the args with any args from the EnvCLI targeting this command
suffix := strings.Replace(strings.Replace(
cliRunner.Subcommand(), "-", "_", -1), " ", "_", -1)
suffix := strings.ReplaceAll(strings.ReplaceAll(
cliRunner.Subcommand(), "-", "_"), " ", "_")
args, err = mergeEnvArgs(
fmt.Sprintf("%s_%s", EnvCLI, suffix), cliRunner.Subcommand(), args)
if err != nil {

View file

@ -48,7 +48,7 @@ func (b *Backend) Workspaces(context.Context) ([]string, error) {
result := make([]string, 1, len(envs)+1)
result[0] = backend.DefaultStateName
for k, _ := range envs {
for k := range envs {
result = append(result, k)
}

View file

@ -93,14 +93,12 @@ func (me *LogRoundTripper) log(in []byte, out []byte, err error, start time.Time
buf.WriteString("; response:")
err := json.Compact(&buf, out)
if err != nil {
out := bytes.Replace(out,
out := bytes.ReplaceAll(out,
[]byte("\n"),
[]byte(""),
-1)
out = bytes.Replace(out,
[]byte(""))
out = bytes.ReplaceAll(out,
[]byte(" "),
[]byte(""),
-1)
[]byte(""))
buf.Write(out)
}
}

View file

@ -259,7 +259,7 @@ func (c *httpClient) Put(data []byte) error {
}
*/
var method string = "POST"
method := "POST"
if c.UpdateMethod != "" {
method = c.UpdateMethod
}

View file

@ -385,7 +385,7 @@ func tryLoadingConfigFile(d *schema.ResourceData) (*restclient.Config, error) {
}
func expandStringSlice(s []interface{}) []string {
result := make([]string, len(s), len(s))
result := make([]string, len(s))
for k, v := range s {
// Handle the OpenTofu parser bug which turns empty strings in lists to nil.
if v == nil {

View file

@ -1126,10 +1126,10 @@ func pathString(path cty.Path) string {
val := x.Key
typ := val.Type()
var s string
switch {
case typ == cty.String:
switch typ {
case cty.String:
s = val.AsString()
case typ == cty.Number:
case cty.Number:
num := val.AsBigFloat()
if num.IsInt() {
s = num.Text('f', -1)

View file

@ -81,7 +81,7 @@ func dataSourceRemoteStateValidate(cfg cty.Value) tfdiags.Diagnostics {
} else {
// Otherwise we'll just type-check the config object itself.
configTy := cfg.GetAttr("config").Type()
if configTy != cty.DynamicPseudoType && !(configTy.IsObjectType() || configTy.IsMapType()) {
if configTy != cty.DynamicPseudoType && !configTy.IsObjectType() && !configTy.IsMapType() {
diags = diags.Append(tfdiags.AttributeValue(
tfdiags.Error,
"Invalid backend configuration",
@ -93,7 +93,7 @@ func dataSourceRemoteStateValidate(cfg cty.Value) tfdiags.Diagnostics {
{
defaultsTy := cfg.GetAttr("defaults").Type()
if defaultsTy != cty.DynamicPseudoType && !(defaultsTy.IsObjectType() || defaultsTy.IsMapType()) {
if defaultsTy != cty.DynamicPseudoType && !defaultsTy.IsObjectType() && !defaultsTy.IsMapType() {
diags = diags.Append(tfdiags.AttributeValue(
tfdiags.Error,
"Invalid default values",

View file

@ -161,8 +161,8 @@ func (b *Cloud) LocalRun(ctx context.Context, op *backend.Operation) (*backend.L
}
func (b *Cloud) getRemoteWorkspaceName(localWorkspaceName string) string {
switch {
case localWorkspaceName == backend.DefaultStateName:
switch localWorkspaceName {
case backend.DefaultStateName:
// The default workspace name is a special case
return b.WorkspaceMapping.Name
default:

View file

@ -620,8 +620,8 @@ func (b *Cloud) shouldRenderStructuredRunOutput(run *tfe.Run) (bool, error) {
}
func shouldRenderPlan(run *tfe.Run) bool {
return !(run.Status == tfe.RunErrored || run.Status == tfe.RunCanceled ||
run.Status == tfe.RunDiscarded)
return run.Status != tfe.RunErrored && run.Status != tfe.RunCanceled &&
run.Status != tfe.RunDiscarded
}
func shouldGenerateConfig(out string, run *tfe.Run) bool {

View file

@ -67,15 +67,16 @@ func (trs *taskResultSummarizer) Summarize(context *IntegrationContext, output I
func summarizeTaskResults(taskResults []*tfe.TaskResult) *taskResultSummary {
var pendingCount, errCount, errMandatoryCount, passedCount int
for _, task := range taskResults {
if task.Status == tfe.TaskUnreachable {
switch task.Status {
case tfe.TaskUnreachable:
return &taskResultSummary{
unreachable: true,
}
} else if task.Status == tfe.TaskRunning || task.Status == tfe.TaskPending {
case tfe.TaskPending, tfe.TaskRunning:
pendingCount++
} else if task.Status == tfe.TaskPassed {
case tfe.TaskPassed:
passedCount++
} else {
case tfe.TaskErrored, tfe.TaskFailed:
// Everything else is a failure
errCount++
if task.WorkspaceTaskEnforcementLevel == tfe.Mandatory {
@ -133,7 +134,7 @@ func (trs *taskResultSummarizer) runTasksWithTaskResults(output IntegrationOutpu
}
// If a mandatory enforcement level is breached, return an error.
var overall string = "[green]Passed"
overall := "[green]Passed"
if firstMandatoryTaskFailed != nil {
overall = "[red]Failed"
if count.failedMandatory > 1 {

View file

@ -222,7 +222,7 @@ func NewProviderLock(addr addrs.Provider, version getproviders.Version, constrai
// Currently, all providers except builtin and legacy providers are eligible
// for locking.
func ProviderIsLockable(addr addrs.Provider) bool {
return !(addr.IsBuiltIn() || addr.IsLegacy())
return !addr.IsBuiltIn() && !addr.IsLegacy()
}
// Sources returns the source code of the file the receiver was generated from,

View file

@ -250,8 +250,8 @@ func statementDependsOn(a, b *MoveStatement) bool {
// Since we are only interested in checking if A depends on B, we only need
// to check the 4 possibilities above which result in B being executed
// first. If we're there's no dependency at all we can return immediately.
if !(a.From.NestedWithin(b.To) || a.To.NestedWithin(b.To) ||
b.From.NestedWithin(a.From) || b.To.NestedWithin(a.From)) {
if !a.From.NestedWithin(b.To) && !a.To.NestedWithin(b.To) &&
!b.From.NestedWithin(a.From) && !b.To.NestedWithin(a.From) {
return false
}