meifamily/ptt-alertor

View on GitHub

Showing 61 of 61 total issues

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

func findSpanByClassName(node *html.Node, className string) *html.Node {
    if node.Type == html.ElementNode && node.Data == "span" {
        for _, tagAttr := range node.Attr {
            if tagAttr.Key == "class" && tagAttr.Val == className {
                return node
Severity: Major
Found in ptt/web/node.go and 2 other locations - About 45 mins to fix
ptt/web/node.go on lines 32..41
ptt/web/node.go on lines 74..83

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 115.

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 RemoveSubscriber(board, account string) error {
    conn := connections.Redis()
    defer conn.Close()
    _, err := conn.Do("SREM", prefix+board+":subs", account)
    if err != nil {
Severity: Minor
Found in models/pushsum/pushsum.go and 1 other location - About 40 mins to fix
models/pushsum/pushsum.go on lines 82..90

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 112.

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 AddSubscriber(board, account string) error {
    conn := connections.Redis()
    defer conn.Close()
    _, err := conn.Do("SADD", prefix+board+":subs", account)
    if err != nil {
Severity: Minor
Found in models/pushsum/pushsum.go and 1 other location - About 40 mins to fix
models/pushsum/pushsum.go on lines 92..100

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 112.

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 addArticles(u *user.User, sub subscription.Subscription, inputs ...string) error {
    sub.Articles = inputs
    a := models.Article()
    a.Code = inputs[0]
    a.AddSubscriber(u.Profile.Account)
Severity: Minor
Found in command/actions.go and 1 other location - About 40 mins to fix
command/actions.go on lines 142..148

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 111.

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 removeArticles(u *user.User, sub subscription.Subscription, inputs ...string) error {
    sub.Articles = inputs
    a := models.Article()
    a.Code = inputs[0]
    a.RemoveSubscriber(u.Profile.Account)
Severity: Minor
Found in command/actions.go and 1 other location - About 40 mins to fix
command/actions.go on lines 134..140

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 111.

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 fetchHTML has 6 return statements (exceeds 4 allowed).
Open

func fetchHTML(reqURL string) (doc *html.Node, err error) {
    req, err := pttHttp.HttpRequest(reqURL)
    if err != nil {
        return nil, err
    }
Severity: Major
Found in ptt/web/crawler.go - About 40 mins to fix

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

    func checkKeywordSubscriber(bd *board.Board, cker Checker) {
        u := models.User()
        accounts := keyword.Subscribers(bd.Name)
        for _, account := range accounts {
            user := u.Find(account)
    Severity: Minor
    Found in jobs/checker.go and 1 other location - About 40 mins to fix
    jobs/checker.go on lines 234..244

    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 110.

    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 checkAuthorSubscriber(bd *board.Board, cker Checker) {
        u := models.User()
        accounts := author.Subscribers(bd.Name)
        for _, account := range accounts {
            user := u.Find(account)
    Severity: Minor
    Found in jobs/checker.go and 1 other location - About 40 mins to fix
    jobs/checker.go on lines 194..204

    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 110.

    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 addKeywords(u *user.User, sub subscription.Subscription, inputs ...string) error {
        sub.Keywords = inputs
        err := u.Subscribes.Add(sub)
        if err == nil {
            err = keyword.AddSubscriber(sub.Board, u.Profile.Account)
    Severity: Minor
    Found in command/actions.go and 1 other location - About 40 mins to fix
    command/actions.go on lines 49..56

    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 109.

    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 addAuthors(u *user.User, sub subscription.Subscription, inputs ...string) error {
        sub.Authors = inputs
        err := u.Subscribes.Add(sub)
        if err == nil {
            err = author.AddSubscriber(sub.Board, u.Profile.Account)
    Severity: Minor
    Found in command/actions.go and 1 other location - About 40 mins to fix
    command/actions.go on lines 18..25

    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 109.

    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 Add(board string) error {
        conn := connections.Redis()
        defer conn.Close()
        _, err := conn.Do("SADD", prefix+"boards", board)
        if err != nil {
    Severity: Minor
    Found in models/pushsum/pushsum.go and 1 other location - About 35 mins to fix
    models/pushsum/pushsum.go on lines 72..80

    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 107.

    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 Remove(board string) error {
        conn := connections.Redis()
        defer conn.Close()
        _, err := conn.Do("SREM", prefix+"boards", board)
        if err != nil {
    Severity: Minor
    Found in models/pushsum/pushsum.go and 1 other location - About 35 mins to fix
    models/pushsum/pushsum.go on lines 62..70

    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 107.

    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 Messenger.Received has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
    Open

    func (m *Messenger) Received(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
        data := Webhook{}
        json.NewDecoder(r.Body).Decode(&data)
        if data.Object == "page" {
            for _, entry := range data.Entry {
    Severity: Minor
    Found in channels/messenger/messenger.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 callAPI has 5 return statements (exceeds 4 allowed).
    Open

    func callAPI(url string, body interface{}) error {
        data, err := json.Marshal(body)
        if err != nil {
            return err
        }
    Severity: Major
    Found in channels/messenger/http.go - About 35 mins to fix

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

      func handleCommandLine(userID, command, text string) string {
          var keywordStr, authorStr, push, boo string
          cl := flag.NewFlagSet("Ptt Alertor: <add|del> <-flag <argument>> <board> [board...]\nexample: add -k ptt -a chodino -p 10 ezsoft", flag.ContinueOnError)
          bf := new(bytes.Buffer)
          cl.SetOutput(bf)
      Severity: Minor
      Found in command/command.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 handlePushSum has 5 return statements (exceeds 4 allowed).
      Open

      func handlePushSum(command, account, board, sumStr string) (string, error) {
          if sum, err := strconv.Atoi(sumStr); err != nil || sum < 0 || sum > 100 {
              return "", errors.New("推噓文數需為介於 0-100 的數字")
          }
          boardNames := splitParamString(board)
      Severity: Major
      Found in command/command.go - About 35 mins to fix

        Function CurrentPage has 5 return statements (exceeds 4 allowed).
        Open

        func CurrentPage(board string) (int, error) {
            url := makeBoardURL(board, -1)
            htmlNodes, err := fetchHTML(url)
            if err != nil {
                return 0, err
        Severity: Major
        Found in ptt/web/crawler.go - About 35 mins to fix

          Function handleCommandLine has 5 return statements (exceeds 4 allowed).
          Open

          func handleCommandLine(userID, command, text string) string {
              var keywordStr, authorStr, push, boo string
              cl := flag.NewFlagSet("Ptt Alertor: <add|del> <-flag <argument>> <board> [board...]\nexample: add -k ptt -a chodino -p 10 ezsoft", flag.ContinueOnError)
              bf := new(bytes.Buffer)
              cl.SetOutput(bf)
          Severity: Major
          Found in command/command.go - About 35 mins to fix

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

            func checkKeywordSubscription(user user.User, bd *board.Board, cker Checker) {
                for _, sub := range user.Subscribes {
                    if bd.Name == sub.Board {
                        cker.board = sub.Board
                        for _, keyword := range sub.Keywords {
            Severity: Minor
            Found in jobs/checker.go and 1 other location - About 35 mins to fix
            jobs/checker.go on lines 246..255

            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 104.

            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 checkAuthorSubscription(user user.User, bd *board.Board, cker Checker) {
                for _, sub := range user.Subscribes {
                    if bd.Name == sub.Board {
                        cker.board = sub.Board
                        for _, author := range sub.Authors {
            Severity: Minor
            Found in jobs/checker.go and 1 other location - About 35 mins to fix
            jobs/checker.go on lines 206..215

            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 104.

            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

            Severity
            Category
            Status
            Source
            Language