pstuifzand/ekster

View on GitHub

Showing 86 of 159 total issues

Avoid deeply nested control flow statements.
Open

    } else if key == "photo" {
        return &item.Photo
    } else if key == "category" {
        return &item.Category
    }
Severity: Major
Found in pkg/jf2/simplify.go - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

                if len(item.Content.HTML) == 0 {
                    item.Content.HTML = feedItem.Summary
                }
Severity: Major
Found in pkg/fetch/fetch.go - About 45 mins to fix

Method redisSortedSetTimeline.AddItem has 7 return statements (exceeds 4 allowed).
Open

func (timeline *redisSortedSetTimeline) AddItem(item microsub.Item) (bool, error) {
    conn := timeline.pool.Get()
    defer conn.Close()

    channel := timeline.channel
Severity: Major
Found in pkg/timeline/redisset.go - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

        } else if action == "unfollow" {
            uid := values.Get("channel")
            url := values.Get("url")
            err := h.backend.UnfollowURL(uid, url)
            if err != nil {
Severity: Major
Found in pkg/server/microsub.go - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

            if err != nil {
                http.Error(w, err.Error(), 500)
                return
            }
Severity: Major
Found in pkg/server/microsub.go - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

            } else if name != "" {
                channel, err := h.backend.ChannelsUpdate(uid, name)
                if err != nil {
                    http.Error(w, err.Error(), 500)
                    return
Severity: Major
Found in pkg/server/microsub.go - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

                if v.UID == currentChannel {
                    page.CurrentChannel = v
                    if setting, e := h.Backend.Settings[v.UID]; e {
                        page.CurrentSetting = setting
                    } else {
Severity: Major
Found in cmd/eksterd/http.go - About 45 mins to fix

Function itemPtr has 7 return statements (exceeds 4 allowed).
Open

func itemPtr(item *microsub.Item, key string) *[]string {
    if key == "bookmark-of" {
        return &item.BookmarkOf
    } else if key == "repost-of" {
        return &item.RepostOf
Severity: Major
Found in pkg/jf2/simplify.go - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

        } else if r.URL.Path == "/auth/approve" {
            // create a code
            code := util.RandStringBytes(32)
            state := r.FormValue("state")
            channel := r.FormValue("channel")
Severity: Major
Found in cmd/eksterd/http.go - About 45 mins to fix

Method micropubHandler.ServeHTTP has 6 return statements (exceeds 4 allowed).
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)
Severity: Major
Found in cmd/eksterd/micropub.go - About 40 mins to fix

Method postgresStream.Items has 6 return statements (exceeds 4 allowed).
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
Severity: Major
Found in pkg/timeline/postgres.go - About 40 mins to fix

Method hubIncomingBackend.CreateFeed has 6 return statements (exceeds 4 allowed).
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
Severity: Major
Found in cmd/eksterd/hubbackend.go - About 40 mins to fix

Function checkAuthToken has 6 return statements (exceeds 4 allowed).
Open

func checkAuthToken(header string, tokenEndpoint string, token *auth.TokenResponse) (bool, error) {
    req, err := buildValidateAuthTokenRequest(tokenEndpoint, header)
    if err != nil {
        return false, err
    }
Severity: Major
Found in cmd/eksterd/auth.go - About 40 mins to fix

Function WriteMessages has 6 return statements (exceeds 4 allowed).
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")
Severity: Major
Found in pkg/sse/events.go - About 40 mins to fix

Function getChannelFromAuthorization has 5 return statements (exceeds 4 allowed).
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))
Severity: Major
Found in cmd/eksterd/micropub.go - About 35 mins to fix

Function GetEndpoints has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
Open

func GetEndpoints(me *url.URL) (Endpoints, error) {
    var endpoints Endpoints
    endpoints.Me = me.String()

    baseURL := me
Severity: Minor
Found in pkg/indieauth/auth.go - About 35 mins to fix

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

func isFeedContentType(contentType string) bool {
    if strings.HasPrefix(contentType, "application/rss+xml") {
        return true
    }
    if strings.HasPrefix(contentType, "application/atom+xml") {
Severity: Major
Found in pkg/websub/subscribe.go - About 35 mins to fix

Function ValidateHubSignature has 5 return statements (exceeds 4 allowed).
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")
Severity: Major
Found in pkg/websub/signature.go - About 35 mins to fix

Function parseBodyLinks has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
Open

func parseBodyLinks(client *http.Client, topic string) (string, error) {
    resp, err := client.Get(topic)

    if err != nil {
        return "", err
Severity: Minor
Found in pkg/websub/subscribe.go - About 35 mins to fix

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

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{}
Severity: Major
Found in pkg/fetch/fetch.go - About 35 mins to fix
Severity
Category
Status
Source
Language