kenjij/kajiki

View on GitHub
lib/kajiki/optimist.rb

Summary

Maintainability
F
6 days
Test Coverage

Method parse has a Cognitive Complexity of 73 (exceeds 5 allowed). Consider refactoring.
Open

  def parse(cmdline = ARGV)
    vals = {}
    required = {}

    opt :version, "Print version and exit" if @version && ! (@specs[:version] || @long["version"])
Severity: Minor
Found in lib/kajiki/optimist.rb - About 1 day 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

File optimist.rb has 629 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'date'

module Optimist
  # note: this is duplicated in gemspec
  # please change over there too
Severity: Major
Found in lib/kajiki/optimist.rb - About 1 day to fix

    Method each_arg has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring.
    Open

      def each_arg(args)
        remains = []
        i = 0
    
        until i >= args.length
    Severity: Minor
    Found in lib/kajiki/optimist.rb - About 7 hrs 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 parse has 87 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def parse(cmdline = ARGV)
        vals = {}
        required = {}
    
        opt :version, "Print version and exit" if @version && ! (@specs[:version] || @long["version"])
    Severity: Major
    Found in lib/kajiki/optimist.rb - About 3 hrs to fix

      Method each_arg has 69 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def each_arg(args)
          remains = []
          i = 0
      
          until i >= args.length
      Severity: Major
      Found in lib/kajiki/optimist.rb - About 2 hrs to fix

        Class Parser has 24 methods (exceeds 20 allowed). Consider refactoring.
        Open

        class Parser
        
          ## The registry is a class-instance-variable map of option aliases to their subclassed Option class.
          @registry = {}
        
        
        Severity: Minor
        Found in lib/kajiki/optimist.rb - About 2 hrs to fix

          Class Option has 22 methods (exceeds 20 allowed). Consider refactoring.
          Open

          class Option
          
            attr_accessor :name, :short, :long, :default
            attr_writer :multi_given
          
          
          Severity: Minor
          Found in lib/kajiki/optimist.rb - About 2 hrs to fix

            Method educate has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
            Open

              def educate(stream = $stdout)
                width # hack: calculate it now; otherwise we have to be careful not to
                      # call this unless the cursor's at the beginning of a line.
            
                left = {}
            Severity: Minor
            Found in lib/kajiki/optimist.rb - 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 wrap_line has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

              def wrap_line(str, opts = {})
                prefix = opts[:prefix] || 0
                width = opts[:width] || (self.width - 1)
                start = 0
                ret = []
            Severity: Minor
            Found in lib/kajiki/optimist.rb - 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 parse has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

              def parse(paramlist, _neg_given)
                paramlist.map do |pg|
                  pg.map do |param|
                    next param if param.is_a?(Date)
                    begin
            Severity: Minor
            Found in lib/kajiki/optimist.rb - 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 get_type_from_disdef has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

              def self.get_type_from_disdef(optdef, opttype, disambiguated_default)
                if disambiguated_default.is_a? Array
                  return(optdef.first.class.name.downcase + "s") if !optdef.empty?
                  if opttype
                    raise ArgumentError, "multiple argument type must be plural" unless opttype.multi_arg?
            Severity: Minor
            Found in lib/kajiki/optimist.rb - 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 parse has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def parse(paramlist, _neg_given)
                paramlist.map do |pg|
                  pg.map do |param|
                    if param =~ /^(stdin|-)$/i
                      $stdin
            Severity: Minor
            Found in lib/kajiki/optimist.rb - About 45 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 deeply nested control flow statements.
            Open

                          if @stop_on_unknown
                            remains << "-#{short_remaining}"
                            return remains += args[i + 1..-1]
                          end
            Severity: Major
            Found in lib/kajiki/optimist.rb - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                            if @stop_on_unknown
                              short_remaining += shortargs[j + 1..-1].join
                              remains << "-#{short_remaining}"
                              return remains += args[i + 1..-1]
                            end
              Severity: Major
              Found in lib/kajiki/optimist.rb - About 45 mins to fix

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

                  def opt(name, desc = "", opts = {}, &b)
                    opts[:callback] ||= b if block_given?
                    opts[:desc] ||= desc
                
                    o = Option.create(name, desc, opts)
                Severity: Minor
                Found in lib/kajiki/optimist.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

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

                  def resolve_default_short_options!
                    @order.each do |type, name|
                      opts = @specs[name]
                      next if type != :opt || opts.short
                
                
                Severity: Minor
                Found in lib/kajiki/optimist.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 remains += args[i + 1..-1]
                Severity: Major
                Found in lib/kajiki/optimist.rb - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                            return remains += args[i..-1]
                  Severity: Major
                  Found in lib/kajiki/optimist.rb - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                    return remains += args[i + 1..-1]
                    Severity: Major
                    Found in lib/kajiki/optimist.rb - About 30 mins to fix

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

                        def self.registry_getopttype(type)
                          return nil unless type
                          if type.respond_to?(:name)
                            type = type.name
                            lookup = type.downcase.to_sym
                      Severity: Minor
                      Found in lib/kajiki/optimist.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 die has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def die(arg, msg = nil, error_code = nil)
                          msg, error_code = nil, msg if msg.kind_of?(Integer)
                          if msg
                            $stderr.puts "Error: argument --#{@specs[arg].long} #{msg}."
                          else
                      Severity: Minor
                      Found in lib/kajiki/optimist.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 handle_short_opt has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def self.handle_short_opt(sopt)
                          sopt = sopt.to_s if sopt && sopt != :none
                          sopt = case sopt
                                 when /^-(.)$/          then $1
                                 when nil, :none, /^.$/ then sopt
                      Severity: Minor
                      Found in lib/kajiki/optimist.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

                      There are no issues that match your filters.

                      Category
                      Status