pstuifzand/ekster

View on GitHub

Showing 145 of 159 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

func (c *Client) FollowURL(channel, url string) (microsub.Feed, error) {
    args := make(map[string]string)
    args["channel"] = channel
    args["url"] = url
    res, err := c.microsubPostRequest("follow", args)
Severity: Major
Found in pkg/client/requests.go and 1 other location - About 2 hrs to fix
pkg/client/requests.go on lines 252..268

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 192.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

func (c *Client) ChannelsUpdate(uid, name string) (microsub.Channel, error) {
    args := make(map[string]string)
    args["name"] = name
    args["channel"] = uid
    res, err := c.microsubPostRequest("channels", args)
Severity: Major
Found in pkg/client/requests.go and 1 other location - About 2 hrs to fix
pkg/client/requests.go on lines 284..300

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 192.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    for ik, vk := range microformat.Properties {
        if p, ok := vk[0].(string); ok {
            switch ik {
            case "name":
                card.Name = p
Severity: Major
Found in pkg/jf2/simplify.go and 1 other location - About 1 hr to fix
pkg/jf2/simplify.go on lines 279..302

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 149.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        if arr, ok := vk.([]interface{}); ok {
            if p, ok := arr[0].(string); ok {
                switch ik {
                case "name":
                    card.Name = p
Severity: Major
Found in pkg/jf2/simplify.go and 1 other location - About 1 hr to fix
pkg/jf2/simplify.go on lines 328..351

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 149.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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

Severity
Category
Status
Source
Language