pstuifzand/ekster

View on GitHub

Showing 86 of 159 total issues

Function parseAtom has 74 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func parseAtom(data []byte) (*Feed, error) {
    warnings := false
    feed := atomFeed{}
    p := xml.NewDecoder(bytes.NewReader(data))
    p.CharsetReader = charsetReader
Severity: Minor
Found in pkg/rss/atom.go - About 1 hr to fix

Function main has 72 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func main() {
    flag.Parse()

    flag.Usage = func() {
        fmt.Print(`Ek is a tool for managing Microsub servers.
Severity: Minor
Found in cmd/ek/main.go - About 1 hr to fix

Method microsubHandler.ServeHTTP has 20 return statements (exceeds 4 allowed).
Open

func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    r.ParseForm()

    // log.Printf("Incoming request: %s %s\n", r.Method, r.URL)
    // log.Println(r.URL.Query())
Severity: Major
Found in pkg/server/microsub.go - About 1 hr to fix

Method postgresStream.Items has 70 lines of code (exceeds 50 allowed). Consider refactoring.
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: Minor
Found in pkg/timeline/postgres.go - About 1 hr to fix

Function simplifyToItem has 69 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func simplifyToItem(itemType string, item map[string][]interface{}, author microsub.Card) microsub.Item {
    var feedItem microsub.Item

    if itemType == "cite" {
        itemType = "entry"
Severity: Minor
Found in pkg/jf2/simplify.go - About 1 hr to fix

Function CleanHTML has a Cognitive Complexity of 29 (exceeds 20 allowed). Consider refactoring.
Open

func CleanHTML(s string) (string, error) {
    doc, err := html.Parse(strings.NewReader(s))

    if err != nil {
        return "", err
Severity: Minor
Found in pkg/jf2/simplify.go - About 1 hr 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

Method memoryBackend.Search has a Cognitive Complexity of 29 (exceeds 20 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

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 67 lines of code (exceeds 50 allowed). Consider refactoring.
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: Minor
Found in pkg/fetch/fetch.go - About 1 hr to fix

Method redisSortedSetTimeline.Items has 66 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (timeline *redisSortedSetTimeline) Items(before, after string) (microsub.Timeline, error) {
    conn := timeline.pool.Get()
    defer conn.Close()

    items := []microsub.Item{}
Severity: Minor
Found in pkg/timeline/redisset.go - About 1 hr to fix

Function importOPMLIntoMicrosub has 62 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func importOPMLIntoMicrosub(sub microsub.Microsub, filename string) {
    channelMap := make(map[string]microsub.Channel)
    channels, err := sub.ChannelsGetList()
    if err != nil {
        log.Fatalf("an error occurred: %s\n", err)
Severity: Minor
Found in cmd/ek/main.go - About 1 hr to fix

Method hubIncomingBackend.Feeds has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring.
Open

func (h *hubIncomingBackend) Feeds() ([]Feed, error) {
    conn := h.pool.Get()
    defer conn.Close()
    feeds := []Feed{}

Severity: Minor
Found in cmd/eksterd/hubbackend.go - About 1 hr 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 main has 58 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func main() {
    log.Println("eksterd - microsub server")

    var options AppOptions

Severity: Minor
Found in cmd/eksterd/main.go - About 1 hr to fix

Method incomingHandler.ServeHTTP has 58 lines of code (exceeds 50 allowed). Consider refactoring.
Open

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

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

Method micropubHandler.ServeHTTP has 57 lines of code (exceeds 50 allowed). Consider refactoring.
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: Minor
Found in cmd/eksterd/micropub.go - About 1 hr to fix

Function FeedHeader has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring.
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: Minor
Found in pkg/fetch/fetch.go - About 1 hr 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 Authorize has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring.
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: Minor
Found in pkg/indieauth/auth.go - About 1 hr 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 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
Severity
Category
Status
Source
Language