mirror of
https://github.com/opentofu/opentofu.git
synced 2026-02-18 18:17:54 -05:00
refactor: implement all simple static checks (#2895)
Signed-off-by: Larry Bordowitz <laurence.bordowitz@gmail.com>
This commit is contained in:
parent
6fa79a7de3
commit
9b6a8fae60
12 changed files with 27 additions and 28 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -259,7 +259,7 @@ func (c *httpClient) Put(data []byte) error {
|
|||
}
|
||||
*/
|
||||
|
||||
var method string = "POST"
|
||||
method := "POST"
|
||||
if c.UpdateMethod != "" {
|
||||
method = c.UpdateMethod
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue