pstuifzand/ekster

View on GitHub

Showing 145 of 159 total issues

Function Authorize has 11 return statements (exceeds 4 allowed).
Open

func Authorize(me *url.URL, endpoints Endpoints, clientID, scope string) (TokenResponse, error) {
    var tokenResponse TokenResponse

    authURL, err := url.Parse(endpoints.AuthorizationEndpoint)
    if err != nil {
Severity: Major
Found in pkg/indieauth/auth.go - About 1 hr to fix

Function parseBodyLinks has 11 return statements (exceeds 4 allowed).
Open

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

    if err != nil {
        return "", err
Severity: Major
Found in pkg/websub/subscribe.go - About 1 hr to fix

Method memoryBackend.Search has 51 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (b *memoryBackend) Search(query string) ([]microsub.Feed, error) {
    urls := getPossibleURLs(query)

    // needs to be like this, because we get a null result otherwise in the json output
    feeds := []microsub.Feed{}
Severity: Minor
Found in cmd/eksterd/memory.go - About 1 hr to fix

Method memoryBackend.channelAddItemWithMatcher has 10 return statements (exceeds 4 allowed).
Open

func (b *memoryBackend) channelAddItemWithMatcher(channel string, item microsub.Item) error {
    // an item is posted
    // check for all channels as channel
    // if regex matches item
    //  - add item to channel
Severity: Major
Found in cmd/eksterd/memory.go - About 1 hr to fix

Function importJSONIntoMicrosub has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
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)
Severity: Minor
Found in cmd/ek/main.go - About 55 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 Create has 9 return statements (exceeds 4 allowed).
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 {
Severity: Major
Found in pkg/timeline/timeline.go - About 55 mins to fix

Function verifyAuthCode has 9 return statements (exceeds 4 allowed).
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)
Severity: Major
Found in cmd/eksterd/http.go - About 55 mins to fix

Method incomingHandler.ServeHTTP has 9 return statements (exceeds 4 allowed).
Open

func (h *incomingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    defer r.Body.Close()

    err := r.ParseForm()
    if err != nil {
Severity: Major
Found in cmd/eksterd/incoming.go - About 55 mins to fix

Method postgresStream.Init has 8 return statements (exceeds 4 allowed).
Open

func (p *postgresStream) Init() error {
    ctx := context.Background()
    conn, err := p.database.Conn(ctx)
    if err != nil {
        return err
Severity: Major
Found in pkg/timeline/postgres.go - About 50 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

            if err != nil {
                fmt.Fprintf(w, "ERROR: %s\n", err)
            }
Severity: Major
Found in cmd/eksterd/http.go - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

        } else if action == "follow" {
            channel := values.Get("channel")
            following, err := h.backend.FollowGetList(channel)
            if err != nil {
                http.Error(w, err.Error(), 500)
Severity: Major
Found in pkg/server/microsub.go - About 45 mins to fix

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

func parseIncomingItem(r *http.Request) (*microsub.Item, error) {
    contentType := r.Header.Get("content-type")

    if contentType == "application/jf2+json" {
        var item microsub.Item
Severity: Major
Found in cmd/eksterd/micropub.go - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

            if err == http.ErrNoCookie {
                http.Redirect(w, r, "/", 302)
                return
            }
Severity: Major
Found in cmd/eksterd/http.go - About 45 mins to fix

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

func getEndpoints(me string) (parsedEndpoints, error) {
    endpoints := parsedEndpoints{}

    meURL, err := url.Parse(me)
    if err != nil {
Severity: Major
Found in cmd/eksterd/http.go - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

            if !isLoggedIn(h.Backend, &sess) {
                w.WriteHeader(401)
                fmt.Fprintf(w, "Unauthorized")
                return
            }
Severity: Major
Found in cmd/eksterd/http.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

                    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)))
Severity: Major
Found in pkg/jf2/reflect.go - About 45 mins to fix

Avoid deeply nested control flow statements.
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)
            }
Severity: Major
Found in pkg/indieauth/auth.go - About 45 mins to fix

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

func loadEndpoints(c *client.Client, me *url.URL, filename string) error {
    var endpoints indieauth.Endpoints

    f, err := os.Open(filename)
    if err != nil {
Severity: Major
Found in cmd/ek/main.go - About 45 mins to fix
Severity
Category
Status
Source
Language