Showing 86 of 159 total issues
Function importJSONIntoMicrosub
has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring. Open
Open
func importJSONIntoMicrosub(sub microsub.Microsub, filename string) {
var export Export
f, err := os.Open(filename)
if err != nil {
log.Fatalf("can't open file %s: %s", filename, err)
- 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"
Further reading
Function Create
has 9 return statements (exceeds 4 allowed). Open
Open
func Create(channel, timelineType string, pool *redis.Pool, db *sql.DB) Backend {
if timelineType == "sorted-set" {
timeline := &redisSortedSetTimeline{channel: channel, pool: pool}
err := timeline.Init()
if err != nil {
- Create a ticketCreate a ticket
Function verifyAuthCode
has 9 return statements (exceeds 4 allowed). Open
Open
func verifyAuthCode(code, redirectURI, authEndpoint, clientID string) (bool, *authResponse, error) {
reqData := url.Values{}
reqData.Set("code", code)
reqData.Set("client_id", clientID)
reqData.Set("redirect_uri", redirectURI)
- Create a ticketCreate a ticket
Method incomingHandler.ServeHTTP
has 9 return statements (exceeds 4 allowed). Open
Open
func (h *incomingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
err := r.ParseForm()
if err != nil {
- Create a ticketCreate a ticket
Method postgresStream.Init
has 8 return statements (exceeds 4 allowed). Open
Open
func (p *postgresStream) Init() error {
ctx := context.Background()
conn, err := p.database.Conn(ctx)
if err != nil {
return err
- 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
if err != nil {
fmt.Fprintf(w, "ERROR: %s\n", err)
}
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
Open
} else if action == "follow" {
channel := values.Get("channel")
following, err := h.backend.FollowGetList(channel)
if err != nil {
http.Error(w, err.Error(), 500)
- Create a ticketCreate a ticket
Function parseIncomingItem
has 7 return statements (exceeds 4 allowed). Open
Open
func parseIncomingItem(r *http.Request) (*microsub.Item, error) {
contentType := r.Header.Get("content-type")
if contentType == "application/jf2+json" {
var item microsub.Item
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
Open
if err == http.ErrNoCookie {
http.Redirect(w, r, "/", 302)
return
}
- Create a ticketCreate a ticket
Function getEndpoints
has 7 return statements (exceeds 4 allowed). Open
Open
func getEndpoints(me string) (parsedEndpoints, error) {
endpoints := parsedEndpoints{}
meURL, err := url.Parse(me)
if err != nil {
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
Open
if !isLoggedIn(h.Backend, &sess) {
w.WriteHeader(401)
fmt.Fprintf(w, "Unauthorized")
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
if str, ok := s[0].(string); ft.Type.Kind() == reflect.String && ok {
fv.SetString(str)
} else if ft.Type.Kind() == reflect.Slice {
for _, v := range s {
fv.Set(reflect.Append(fv, reflect.ValueOf(v)))
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
Open
} else if link.Rel == "microsub" {
endpoints.MicrosubEndpoint = link.URL
} else {
log.Printf("Skipping unsupported rels in Link header: %s %s\n", link.Rel, link.URL)
}
- Create a ticketCreate a ticket
Function loadEndpoints
has 7 return statements (exceeds 4 allowed). Open
Open
func loadEndpoints(c *client.Client, me *url.URL, filename string) error {
var endpoints indieauth.Endpoints
f, err := os.Open(filename)
if err != nil {
- Create a ticketCreate a ticket
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