Showing 145 of 159 total issues
Function Authorize
has 11 return statements (exceeds 4 allowed). Open
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 {
- Create a ticketCreate a ticket
Function parseBodyLinks
has 11 return statements (exceeds 4 allowed). Open
Open
func parseBodyLinks(client *http.Client, topic string) (string, error) {
resp, err := client.Get(topic)
if err != nil {
return "", err
- Create a ticketCreate a ticket
Method memoryBackend.Search
has 51 lines of code (exceeds 50 allowed). Consider refactoring. Open
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{}
- Create a ticketCreate a ticket
Method memoryBackend.channelAddItemWithMatcher
has 10 return statements (exceeds 4 allowed). Open
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
- 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
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 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
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 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
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
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 len(item.Content.HTML) == 0 {
item.Content.HTML = feedItem.Summary
}
- 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 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
} 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
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
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
if err == http.ErrNoCookie {
http.Redirect(w, r, "/", 302)
return
}
- Create a ticketCreate a ticket