Showing 95 of 150 total issues
Method LabelSelectorRequirement.Validate
has 5 return statements (exceeds 4 allowed). Open
Open
func (r *LabelSelectorRequirement) Validate() error {
if r.Key == "" {
return fmt.Errorf("%w: %s", validation.ErrMissingRequiredField, "key")
}
if r.Operator == "" {
Method CreateBootstrapTokenRequest.Validate
has 5 return statements (exceeds 4 allowed). Open
Open
func (r *CreateBootstrapTokenRequest) Validate() error {
if err := r.GetTtl().CheckValid(); err != nil {
return fmt.Errorf("%w (ttl): %s", validation.ErrInvalidValue, err.Error())
}
if r.GetTtl().AsDuration() <= 0 {
Method Reconciler.configMap
has 5 return statements (exceeds 4 allowed). Open
Open
func (r *Reconciler) configMap() (resources.Resource, error) {
gatewayConf := &cfgv1beta1.GatewayConfig{
TypeMeta: cfgmeta.TypeMeta{
Kind: "GatewayConfig",
APIVersion: "v1beta1",
Function FetchUserInfo
has 5 return statements (exceeds 4 allowed). Open
Open
func FetchUserInfo(endpoint, token string) (map[string]interface{}, error) {
req, err := http.NewRequest("POST", endpoint, nil)
if err != nil {
return nil, err
}
Method Plugin.QueryRange
has 5 return statements (exceeds 4 allowed). Open
Open
func (p *Plugin) QueryRange(
ctx context.Context,
in *cortexadmin.QueryRangeRequest,
) (*cortexadmin.QueryResponse, error) {
lg := p.logger.With(
Method Agent.streamRulesToGateway
has 5 return statements (exceeds 4 allowed). Open
Open
func (a *Agent) streamRulesToGateway(ctx context.Context) error {
lg := a.logger
updateC, err := a.streamRuleGroupUpdates(ctx)
if err != nil {
a.logger.With(
Function BuildDebugEtcdctlCmd
has 5 return statements (exceeds 4 allowed). Open
Open
func BuildDebugEtcdctlCmd() *cobra.Command {
debugEtcdctlCmd := &cobra.Command{
Use: "etcdctl",
Short: "embedded auto-configured etcdctl",
Long: "To specify a config location, use the OPNIM_CONFIG environment variable.",
Method Plugin.AllUserStats
has 5 return statements (exceeds 4 allowed). Open
Open
func (p *Plugin) AllUserStats(ctx context.Context, _ *emptypb.Empty) (*cortexadmin.UserIDStatsList, error) {
client := p.cortexHttpClient.Get()
req, err := http.NewRequestWithContext(ctx, "GET",
fmt.Sprintf("https://%s/distributor/all_user_stats", p.config.Get().Spec.Cortex.Distributor.HTTPAddress), nil)
if err != nil {
Method BootstrapAuthRequest.Validate
has 5 return statements (exceeds 4 allowed). Open
Open
func (h BootstrapAuthRequest) Validate() error {
if h.ClientID == "" {
return validation.Errorf("%w: %s", validation.ErrMissingRequiredField, "client_id")
}
if err := validation.ValidateID(h.ClientID); err != nil {
Method EtcdStore.GetRoleBinding
has 5 return statements (exceeds 4 allowed). Open
Open
func (e *EtcdStore) GetRoleBinding(ctx context.Context, ref *core.Reference) (*core.RoleBinding, error) {
ctx, ca := context.WithTimeout(ctx, e.CommandTimeout)
defer ca()
resp, err := e.Client.Get(ctx, path.Join(e.Prefix, roleBindingKey, ref.Id))
if err != nil {
Method Server.GetConfig
has 5 return statements (exceeds 4 allowed). Open
Open
func (m *Server) GetConfig(
ctx context.Context,
_ *emptypb.Empty,
) (*GatewayConfig, error) {
lg := m.logger
Method Plugin.Query
has 5 return statements (exceeds 4 allowed). Open
Open
func (p *Plugin) Query(
ctx context.Context,
in *cortexadmin.QueryRequest,
) (*cortexadmin.QueryResponse, error) {
lg := p.logger.With(
Function CheckAvailability
has 5 return statements (exceeds 4 allowed). Open
Open
func CheckAvailability(ctx context.Context, cc *grpc.ClientConn, id string) error {
ref := rpb.NewServerReflectionClient(cc)
stream, err := ref.ServerReflectionInfo(ctx)
if err != nil {
return err
Method requestBuilder.Do
has 5 return statements (exceeds 4 allowed). Open
Open
func (rb *requestBuilder) Do() (code int, body []byte, err error) {
nonce, mac, err := b2mac.New512([]byte(rb.gatewayClient.id),
rb.req.Request().Body(), rb.gatewayClient.sharedKeys.ClientKey)
if err != nil {
return 0, nil, err
Function TLSConfig
has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring. Open
Open
func TLSConfig(pins []*PublicKeyPin) (*tls.Config, error) {
if len(pins) == 0 {
return nil, ErrNoPins
}
copiedPins := make([]*PublicKeyPin, len(pins))
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"