zold-io/zold

View on GitHub

Showing 118 of 118 total issues

Method select has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def select(opts)
      @remotes.all.shuffle.sort_by { |r| r[:errors] }.reverse.each_with_index do |r, idx|
        next if idx < opts['max-nodes']
        next if r[:master] && !opts['masters-too']
        @remotes.remove(r[:host], r[:port])
Severity: Minor
Found in lib/zold/commands/remote.rb - 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

Avoid too many return statements within this method.
Open

      return "#{(days / 30).round}mo" if days < 365
Severity: Major
Found in lib/zold/age.rb - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

          return "#{days}d" if days < 14
    Severity: Major
    Found in lib/zold/age.rb - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

            return "#{(days / 7).round}w" if days < 40
      Severity: Major
      Found in lib/zold/age.rb - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

              return "#{hours}h" if hours < 24
        Severity: Major
        Found in lib/zold/age.rb - About 30 mins to fix

          Method trim has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def trim(opts)
                all = @remotes.all
                all.each do |r|
                  next if r[:errors] <= opts['tolerate']
                  @remotes.remove(r[:host], r[:port]) if !opts['masters-too'] || !r[:master]
          Severity: Minor
          Found in lib/zold/commands/remote.rb - About 25 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

          Method sign has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def sign(pvt, id, txn)
                raise 'pvt must be of type Key' unless pvt.is_a?(Key)
                raise 'id must be of type Id' unless id.is_a?(Id)
                raise 'txn must be of type Txn' unless txn.is_a?(Txn)
                pvt.sign(body(id, txn))
          Severity: Minor
          Found in lib/zold/signature.rb - About 25 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

          Method fetch has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def fetch
                raise "Wallet file '#{@file}' is absent" unless File.exist?(@file)
                lines = []
                File.open(@file) do |f|
                  lines << f.readline.strip while lines.count < 4 && !f.eof?
          Severity: Minor
          Found in lib/zold/head.rb - About 25 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

          Method all has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def all
                DirItems.new(path).fetch.select do |f|
                  next unless f.end_with?(Wallet::EXT)
                  basename = File.basename(f, Wallet::EXT)
                  file = File.join(path, f)
          Severity: Minor
          Found in lib/zold/tree_wallets.rb - About 25 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

          Method exists? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def exists?(id, body)
                DirItems.new(@dir).fetch.each do |f|
                  next unless f.start_with?("#{id}-")
                  return true if safe_read(File.join(@dir, f)) == body
                end
          Severity: Minor
          Found in lib/zold/node/async_entrance.rb - About 25 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

          Method top_scores has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def top_scores(opts)
                best = []
                @remotes.iterate(@log) do |r|
                  @log.debug("Testing #{r}...")
                  uri = '/'
          Severity: Minor
          Found in lib/zold/commands/taxes.rb - About 25 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

          Method all has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def all
                list = Futex.new(@file).open(false) { load }
                max_score = list.empty? ? 0 : list.max_by { |r| r[:score] }[:score]
                max_score = 1 if max_score.zero?
                max_errors = list.empty? ? 0 : list.max_by { |r| r[:errors] }[:errors]
          Severity: Minor
          Found in lib/zold/remotes.rb - About 25 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

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

                pem = File.read(opts['private-key'])
                unless opts['keygap'].empty?
                  pem = pem.sub('*' * opts['keygap'].length, opts['keygap'])
          Severity: Minor
          Found in lib/zold/commands/pay.rb and 1 other location - About 25 mins to fix
          lib/zold/commands/taxes.rb on lines 157..159

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

          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

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

                  pem = File.read(opts['private-key'])
                  unless opts['keygap'].empty?
                    pem = pem.sub('*' * opts['keygap'].length, opts['keygap'])
          Severity: Minor
          Found in lib/zold/commands/taxes.rb and 1 other location - About 25 mins to fix
          lib/zold/commands/pay.rb on lines 166..168

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

          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

                opts = Slop.parse(args, help: true, suppress_errors: true) do |o|
                  o.banner = "Usage: zold next [options] score
          Available options:"
                  o.bool '--low-priority',
                    'Set the lowest priority to this process',
          Severity: Minor
          Found in lib/zold/commands/next.rb and 1 other location - About 15 mins to fix
          lib/zold/commands/remove.rb on lines 44..50

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

          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

                opts = Slop.parse(args, help: true, suppress_errors: true) do |o|
                  o.banner = "Usage: zold remove [ID...] [options]
          Available options:"
                  o.bool '--force',
                    'Don\'t report any errors if the wallet doesn\'t exist',
          Severity: Minor
          Found in lib/zold/commands/remove.rb and 1 other location - About 15 mins to fix
          lib/zold/commands/next.rb on lines 42..48

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

          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

                when 'show'
                  raise 'At least one wallet ID is required' unless mine[1]
                  mine[1..-1].each do |id|
                    @wallets.acq(Id.new(id)) do |w|
                      show(w, opts)
          Severity: Minor
          Found in lib/zold/commands/taxes.rb and 1 other location - About 15 mins to fix
          lib/zold/commands/taxes.rb on lines 105..109

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

          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

                when 'debt'
                  raise 'At least one wallet ID is required' unless mine[1]
                  mine[1..-1].each do |id|
                    @wallets.acq(Id.new(id)) do |w|
                      debt(w, opts)
          Severity: Minor
          Found in lib/zold/commands/taxes.rb and 1 other location - About 15 mins to fix
          lib/zold/commands/taxes.rb on lines 98..102

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

          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