ManageIQ/optimist

View on GitHub

Showing 56 of 56 total issues

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

require 'date'

module Optimist
VERSION = "3.1.0"

Severity: Major
Found in lib/optimist.rb - About 1 day to fix

    Method parse has a Cognitive Complexity of 61 (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/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

    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/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

    Cyclomatic complexity for parse is too high. [50/11]
    Open

      def parse(cmdline = ARGV)
        vals = {}
        required = {}
    
        opt :version, "Print version and exit" if @version && ! (@specs[:version] || @long["version"])
    Severity: Minor
    Found in lib/optimist.rb by rubocop

    Checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

    An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one. Blocks that are calls to builtin iteration methods (e.g. `ary.map{...}) also add one, others are ignored.

    def each_child_node(*types)               # count begins: 1
      unless block_given?                     # unless: +1
        return to_enum(__method__, *types)
    
      children.each do |child|                # each{}: +1
        next unless child.is_a?(Node)         # unless: +1
    
        yield child if types.empty? ||        # if: +1, ||: +1
                       types.include?(child.type)
      end
    
      self
    end                                       # total: 6

    Method parse has 89 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/optimist.rb - About 3 hrs to fix

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

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

        Class Parser has 26 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/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/optimist.rb - About 2 hrs to fix

            Cyclomatic complexity for each_arg is too high. [19/11]
            Open

              def each_arg(args)
                remains = []
                i = 0
            
                until i >= args.length
            Severity: Minor
            Found in lib/optimist.rb by rubocop

            Checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

            An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one. Blocks that are calls to builtin iteration methods (e.g. `ary.map{...}) also add one, others are ignored.

            def each_child_node(*types)               # count begins: 1
              unless block_given?                     # unless: +1
                return to_enum(__method__, *types)
            
              children.each do |child|                # each{}: +1
                next unless child.is_a?(Node)         # unless: +1
            
                yield child if types.empty? ||        # if: +1, ||: +1
                               types.include?(child.type)
              end
            
              self
            end                                       # total: 6

            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/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

            Cyclomatic complexity for educate is too high. [13/11]
            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/optimist.rb by rubocop

            Checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

            An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one. Blocks that are calls to builtin iteration methods (e.g. `ary.map{...}) also add one, others are ignored.

            def each_child_node(*types)               # count begins: 1
              unless block_given?                     # unless: +1
                return to_enum(__method__, *types)
            
              children.each do |child|                # each{}: +1
                next unless child.is_a?(Node)         # unless: +1
            
                yield child if types.empty? ||        # if: +1, ||: +1
                               types.include?(child.type)
              end
            
              self
            end                                       # total: 6

            Cyclomatic complexity for create is too high. [13/11]
            Open

              def self.create(name, desc="", opts={}, settings={})
            
                opttype = Optimist::Parser.registry_getopttype(opts[:type])
                opttype_from_default = get_klass_from_default(opts, opttype)
            
            
            Severity: Minor
            Found in lib/optimist.rb by rubocop

            Checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

            An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one. Blocks that are calls to builtin iteration methods (e.g. `ary.map{...}) also add one, others are ignored.

            def each_child_node(*types)               # count begins: 1
              unless block_given?                     # unless: +1
                return to_enum(__method__, *types)
            
              children.each do |child|                # each{}: +1
                next unless child.is_a?(Node)         # unless: +1
            
                yield child if types.empty? ||        # if: +1, ||: +1
                               types.include?(child.type)
              end
            
              self
            end                                       # total: 6

            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/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/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 handle_unknown_argument has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

              def handle_unknown_argument(arg, candidates, suggestions)
                errstring = "unknown argument '#{arg}'"
                if (suggestions &&
                  Module::const_defined?("DidYouMean") &&
                  Module::const_defined?("DidYouMean::JaroWinkler") &&
            Severity: Minor
            Found in lib/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 opt has a Cognitive Complexity of 10 (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/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/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 handle_unknown_argument has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def handle_unknown_argument(arg, candidates, suggestions)
                errstring = "unknown argument '#{arg}'"
                if (suggestions &&
                  Module::const_defined?("DidYouMean") &&
                  Module::const_defined?("DidYouMean::JaroWinkler") &&
            Severity: Minor
            Found in lib/optimist.rb - About 1 hr to fix

              Method add has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                def add(values)
                  values = [values] unless values.is_a?(Array) # box the value
                  values = values.compact
                  if values.include?(:none)
                    if values.size == 1
              Severity: Minor
              Found in lib/optimist.rb - About 55 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 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/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

              Severity
              Category
              Status
              Source
              Language