refactor: remove if/else statements

This commit is contained in:
Jan De Dobbeleer 2024-08-06 13:56:56 +02:00 committed by Jan De Dobbeleer
parent 3bc476488a
commit 701cd499df
3 changed files with 14 additions and 10 deletions

View file

@ -153,11 +153,10 @@ func (u *Umbraco) TryFindLegacyUmbraco(configPath string) bool {
for _, appSetting := range webConfigAppSettings.AppSettings { for _, appSetting := range webConfigAppSettings.AppSettings {
if strings.EqualFold(appSetting.Key, "umbraco.core.configurationstatus") || strings.EqualFold(appSetting.Key, "umbracoConfigurationStatus") { if strings.EqualFold(appSetting.Key, "umbraco.core.configurationstatus") || strings.EqualFold(appSetting.Key, "umbracoConfigurationStatus") {
u.Modern = false u.Modern = false
u.Version = appSetting.Value
if len(appSetting.Value) == 0 { if len(u.Version) == 0 {
u.Version = UNKNOWN u.Version = UNKNOWN
} else {
u.Version = appSetting.Value
} }
return true return true

View file

@ -222,16 +222,18 @@ func (t *Text) cleanTemplate() {
result += string(char) result += string(char)
continue continue
} }
// end of a variable, needs to be appended
if !isKnownVariable(property) { //nolint: gocritic switch {
case !isKnownVariable(property):
// end of a variable, needs to be appended
result += ".Data" + property result += ".Data" + property
} else if strings.HasPrefix(property, ".Segments") && !strings.HasSuffix(property, ".Contains") { case strings.HasPrefix(property, ".Segments") && !strings.HasSuffix(property, ".Contains"):
// as we can't provide a clean way to access the list // as we can't provide a clean way to access the list
// of segments, we need to replace the property with // of segments, we need to replace the property with
// the list of segments so they can be accessed directly // the list of segments so they can be accessed directly
property = strings.Replace(property, ".Segments", ".Segments.ToSimple", 1) property = strings.Replace(property, ".Segments", ".Segments.ToSimple", 1)
result += property result += property
} else { default:
// check if we have the same property in Data // check if we have the same property in Data
// and replace it with the Data property so it // and replace it with the Data property so it
// can take precedence // can take precedence
@ -242,6 +244,7 @@ func (t *Text) cleanTemplate() {
property = strings.TrimPrefix(property, globalRef) property = strings.TrimPrefix(property, globalRef)
result += property result += property
} }
property = "" property = ""
result += string(char) result += string(char)
inProperty = false inProperty = false

View file

@ -428,17 +428,19 @@ func writeSegmentColors() {
return return
} }
if fg.IsTransparent() && len(BackgroundColor) != 0 { //nolint: gocritic switch {
case fg.IsTransparent() && len(BackgroundColor) != 0:
background := getAnsiFromColorString(BackgroundColor, false) background := getAnsiFromColorString(BackgroundColor, false)
writeEscapedAnsiString(fmt.Sprintf(colorise, background)) writeEscapedAnsiString(fmt.Sprintf(colorise, background))
writeEscapedAnsiString(fmt.Sprintf(colorise, bg.ToForeground())) writeEscapedAnsiString(fmt.Sprintf(colorise, bg.ToForeground()))
} else if fg.IsTransparent() && !bg.IsEmpty() { case fg.IsTransparent() && !bg.IsEmpty():
isTransparent = true isTransparent = true
writeEscapedAnsiString(fmt.Sprintf(transparentStart, bg)) writeEscapedAnsiString(fmt.Sprintf(transparentStart, bg))
} else { default:
if !bg.IsEmpty() && !bg.IsTransparent() { if !bg.IsEmpty() && !bg.IsTransparent() {
writeEscapedAnsiString(fmt.Sprintf(colorise, bg)) writeEscapedAnsiString(fmt.Sprintf(colorise, bg))
} }
if !fg.IsEmpty() { if !fg.IsEmpty() {
writeEscapedAnsiString(fmt.Sprintf(colorise, fg)) writeEscapedAnsiString(fmt.Sprintf(colorise, fg))
} }