mirror of
https://github.com/neovim/neovim.git
synced 2025-09-20 18:28:19 +00:00
refactor: allow not having a default
case for enum
Problem: The style guide states that all switch statements that are not conditional on an enum must have a `default` case, but does not give any explicit guideline for switch statements that are conditional on enums. As a result, a `default` case is added in many enum switch statements, even when the switch statement is exhaustive. This is not ideal because it removes the ability to have compiler errors to easily detect unchanged switch statements when a new possible value for an enum is added. Solution: Add explicit guidelines for switch statements that are conditional on an enum, clarifying that a `default` case is not necessary if the switch statement is exhaustive. Also refactor pre-existing code with unnecessary `default` cases.
This commit is contained in:

committed by
Lewis Russell

parent
a2f17e97ec
commit
9ff6f73f83
@@ -294,7 +294,7 @@ Array nvim_get_autocmds(Dict(get_autocmds) *opts, Error *err)
|
||||
case kCallbackPartial:
|
||||
PUT(autocmd_info, "callback", CSTR_AS_OBJ(callback_to_string(cb)));
|
||||
break;
|
||||
default:
|
||||
case kCallbackNone:
|
||||
abort();
|
||||
}
|
||||
} else {
|
||||
|
@@ -146,16 +146,14 @@ static Object optval_as_object(OptVal o)
|
||||
return BOOLEAN_OBJ(o.data.boolean);
|
||||
case kNone:
|
||||
return NIL;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
UNREACHABLE;
|
||||
case kOptValTypeNumber:
|
||||
return INTEGER_OBJ(o.data.number);
|
||||
case kOptValTypeString:
|
||||
return STRING_OBJ(o.data.string);
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
|
||||
/// Consume an API Object and convert it to an OptVal.
|
||||
|
@@ -363,9 +363,6 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err)
|
||||
tv->vval.v_string = xstrdup(name);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@@ -610,9 +610,6 @@ void api_free_object(Object value)
|
||||
case kObjectTypeLuaRef:
|
||||
api_free_luaref(value.data.luaref);
|
||||
break;
|
||||
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -800,10 +797,8 @@ Object copy_object(Object obj, Arena *arena)
|
||||
|
||||
case kObjectTypeLuaRef:
|
||||
return LUAREF_OBJ(api_new_luaref(obj.data.luaref));
|
||||
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
|
||||
void api_set_error(Error *err, ErrorType errType, const char *format, ...)
|
||||
@@ -884,9 +879,8 @@ char *api_typename(ObjectType t)
|
||||
return "Window";
|
||||
case kObjectTypeTabpage:
|
||||
return "Tabpage";
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
|
||||
HlMessage parse_hl_msg(Array chunks, Error *err)
|
||||
|
@@ -279,8 +279,6 @@ Dictionary config_put_bordertext(Dictionary config, FloatConfig *fconfig,
|
||||
field_name = "footer";
|
||||
field_pos_name = "footer_pos";
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
|
||||
Array bordertext = virt_text_to_array(vt, true);
|
||||
|
Reference in New Issue
Block a user