Cleanup: flip conditions for less indentation

This commit is contained in:
Stefan Haller 2025-05-04 12:57:11 +02:00
parent 7fc580fe61
commit e4c1583fb7

View file

@ -225,17 +225,18 @@ func migrateUserConfig(path string, content []byte) ([]byte, error) {
return nil, err return nil, err
} }
// Write config back if changed // Nothing to do if config didn't change
if string(changedContent) != string(content) { if string(changedContent) == string(content) {
fmt.Println("Provided user config is deprecated but auto-fixable. Attempting to write fixed version back to file...") return content, nil
if err := os.WriteFile(path, changedContent, 0o644); err != nil {
return nil, fmt.Errorf("While attempting to write back fixed user config to %s, an error occurred: %s", path, err)
}
fmt.Printf("Success. New config written to %s\n", path)
return changedContent, nil
} }
return content, nil // Write config back
fmt.Println("Provided user config is deprecated but auto-fixable. Attempting to write fixed version back to file...")
if err := os.WriteFile(path, changedContent, 0o644); err != nil {
return nil, fmt.Errorf("While attempting to write back fixed user config to %s, an error occurred: %s", path, err)
}
fmt.Printf("Success. New config written to %s\n", path)
return changedContent, nil
} }
// A pure function helper for testing purposes // A pure function helper for testing purposes
@ -295,15 +296,15 @@ func computeMigratedConfig(path string, content []byte) ([]byte, error) {
// Add more migrations here... // Add more migrations here...
if !reflect.DeepEqual(rootNode, originalCopy) { if reflect.DeepEqual(rootNode, originalCopy) {
newContent, err := yaml_utils.YamlMarshal(&rootNode)
if err != nil {
return nil, fmt.Errorf("Failed to remarsal!\n %w", err)
}
return newContent, nil
} else {
return content, nil return content, nil
} }
newContent, err := yaml_utils.YamlMarshal(&rootNode)
if err != nil {
return nil, fmt.Errorf("Failed to remarsal!\n %w", err)
}
return newContent, nil
} }
func changeNullKeybindingsToDisabled(rootNode *yaml.Node) error { func changeNullKeybindingsToDisabled(rootNode *yaml.Node) error {