Showing 145 of 159 total issues
Avoid deeply nested control flow statements. Open
Open
} else if err != nil {
http.Error(w, "could not read cookie", 500)
return
}
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
Open
if sess.NextURI != "" {
http.Redirect(w, r, sess.NextURI, 302)
} else {
http.Redirect(w, r, "/", 302)
}
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
Open
} else if r.URL.Path == "/logs" {
c, err := r.Cookie("session")
if err == http.ErrNoCookie {
http.Redirect(w, r, "/", 302)
return
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
Open
if err != nil {
http.Error(w, err.Error(), 500)
return
}
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
Open
} else if key == "photo" {
return &item.Photo
} else if key == "category" {
return &item.Category
}
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
Open
if len(item.Content.HTML) == 0 {
item.Content.HTML = feedItem.Summary
}
- Create a ticketCreate a ticket
Method redisSortedSetTimeline.AddItem
has 7 return statements (exceeds 4 allowed). Open
Open
func (timeline *redisSortedSetTimeline) AddItem(item microsub.Item) (bool, error) {
conn := timeline.pool.Get()
defer conn.Close()
channel := timeline.channel
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
Open
} else if action == "unfollow" {
uid := values.Get("channel")
url := values.Get("url")
err := h.backend.UnfollowURL(uid, url)
if err != nil {
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
Open
if err != nil {
http.Error(w, err.Error(), 500)
return
}
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
Open
} else if name != "" {
channel, err := h.backend.ChannelsUpdate(uid, name)
if err != nil {
http.Error(w, err.Error(), 500)
return
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
Open
if v.UID == currentChannel {
page.CurrentChannel = v
if setting, e := h.Backend.Settings[v.UID]; e {
page.CurrentSetting = setting
} else {
- Create a ticketCreate a ticket
Function itemPtr
has 7 return statements (exceeds 4 allowed). Open
Open
func itemPtr(item *microsub.Item, key string) *[]string {
if key == "bookmark-of" {
return &item.BookmarkOf
} else if key == "repost-of" {
return &item.RepostOf
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
Open
} else if r.URL.Path == "/auth/approve" {
// create a code
code := util.RandStringBytes(32)
state := r.FormValue("state")
channel := r.FormValue("channel")
- Create a ticketCreate a ticket
Method micropubHandler.ServeHTTP
has 6 return statements (exceeds 4 allowed). Open
Open
func (h *micropubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer func() {
err := r.Body.Close()
if err != nil {
log.Printf("could not close request body: %v", err)
- Create a ticketCreate a ticket
Method postgresStream.Items
has 6 return statements (exceeds 4 allowed). Open
Open
func (p *postgresStream) Items(before, after string) (microsub.Timeline, error) {
ctx := context.Background()
conn, err := p.database.Conn(ctx)
if err != nil {
return microsub.Timeline{}, err
- Create a ticketCreate a ticket
Method hubIncomingBackend.CreateFeed
has 6 return statements (exceeds 4 allowed). Open
Open
func (h *hubIncomingBackend) CreateFeed(topic string, channel string) (int64, error) {
conn := h.pool.Get()
defer conn.Close()
// TODO(peter): check if topic already is registered
- Create a ticketCreate a ticket
Function checkAuthToken
has 6 return statements (exceeds 4 allowed). Open
Open
func checkAuthToken(header string, tokenEndpoint string, token *auth.TokenResponse) (bool, error) {
req, err := buildValidateAuthTokenRequest(tokenEndpoint, header)
if err != nil {
return false, err
}
- Create a ticketCreate a ticket
Function WriteMessages
has 6 return statements (exceeds 4 allowed). Open
Open
func WriteMessages(w http.ResponseWriter, messageChan chan Message) error {
// Make sure that the writer supports flushing.
flusher, ok := w.(http.Flusher)
if !ok {
return fmt.Errorf("streaming unsupported")
- Create a ticketCreate a ticket
Function getChannelFromAuthorization
has 5 return statements (exceeds 4 allowed). Open
Open
func getChannelFromAuthorization(r *http.Request, conn redis.Conn) (string, error) {
// backward compatible
sourceID := r.URL.Query().Get("source_id")
if sourceID != "" {
channel, err := redis.String(conn.Do("HGET", "sources", sourceID))
- Create a ticketCreate a ticket
Function GetEndpoints
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
Open
func GetEndpoints(me *url.URL) (Endpoints, error) {
var endpoints Endpoints
endpoints.Me = me.String()
baseURL := me
- Read upRead up
- Create a ticketCreate a ticket
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"