Showing 86 of 159 total issues
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"
Further reading
Function isFeedContentType
has 5 return statements (exceeds 4 allowed). Open
Open
func isFeedContentType(contentType string) bool {
if strings.HasPrefix(contentType, "application/rss+xml") {
return true
}
if strings.HasPrefix(contentType, "application/atom+xml") {
- Create a ticketCreate a ticket
Function ValidateHubSignature
has 5 return statements (exceeds 4 allowed). Open
Open
func ValidateHubSignature(sig string, feedContent, secret []byte) error {
parts := strings.Split(sig, "=")
if len(parts) != 2 {
return errors.New("signature format is not like sha1=signature")
- Create a ticketCreate a ticket
Function parseBodyLinks
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
Open
func parseBodyLinks(client *http.Client, topic string) (string, error) {
resp, err := client.Get(topic)
if err != nil {
return "", 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 FeedHeader
has 5 return statements (exceeds 4 allowed). Open
Open
func FeedHeader(fetcher FetcherFunc, fetchURL, contentType string, body io.Reader) (microsub.Feed, error) {
log.Printf("ProcessContent %s\n", fetchURL)
log.Println("Found " + contentType)
feed := microsub.Feed{}
- Create a ticketCreate a ticket