rubygems/rubygems

View on GitHub
lib/rubygems/vendor/optparse/lib/optparse.rb

Summary

Maintainability
F
1 wk
Test Coverage

File optparse.rb has 1142 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class Gem::OptionParser
  Gem::OptionParser::Version = "0.4.0"

  # :stopdoc:
  NoArgument = [NO_ARGUMENT = :NONE, nil].freeze
Severity: Major
Found in lib/rubygems/vendor/optparse/lib/optparse.rb - About 2 days to fix

    Method parse_in_order has a Cognitive Complexity of 129 (exceeds 5 allowed). Consider refactoring.
    Open

      def parse_in_order(argv = default_argv, setter = nil, &nonopt)  # :nodoc:
        opt, arg, val, rest = nil
        nonopt ||= proc {|a| throw :terminate, a}
        argv.unshift(arg) if arg = catch(:terminate) {
          while arg = argv.shift
    Severity: Minor
    Found in lib/rubygems/vendor/optparse/lib/optparse.rb - About 2 days 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 make_switch has a Cognitive Complexity of 105 (exceeds 5 allowed). Consider refactoring.
    Open

      def make_switch(opts, block = nil)
        short, long, nolong, style, pattern, conv, not_pattern, not_conv, not_style = [], [], []
        ldesc, sdesc, desc, arg = [], [], []
        default_style = Switch::NoArgument
        default_pattern = nil
    Severity: Minor
    Found in lib/rubygems/vendor/optparse/lib/optparse.rb - About 2 days 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

    Class OptionParser has 67 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class Gem::OptionParser
      Gem::OptionParser::Version = "0.4.0"
    
      # :stopdoc:
      NoArgument = [NO_ARGUMENT = :NONE, nil].freeze
    Severity: Major
    Found in lib/rubygems/vendor/optparse/lib/optparse.rb - About 1 day to fix

      Method make_switch has 123 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def make_switch(opts, block = nil)
          short, long, nolong, style, pattern, conv, not_pattern, not_conv, not_style = [], [], []
          ldesc, sdesc, desc, arg = [], [], []
          default_style = Switch::NoArgument
          default_pattern = nil
      Severity: Major
      Found in lib/rubygems/vendor/optparse/lib/optparse.rb - About 4 hrs to fix

        Method summarize has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
        Open

            def summarize(sdone = {}, ldone = {}, width = 1, max = width - 1, indent = "")
              sopts, lopts = [], [], nil
              @short.each {|s| sdone.fetch(s) {sopts << s}; sdone[s] = true} if @short
              @long.each {|s| ldone.fetch(s) {lopts << s}; ldone[s] = true} if @long
              return if sopts.empty? and lopts.empty? # completely hidden
        Severity: Minor
        Found in lib/rubygems/vendor/optparse/lib/optparse.rb - About 3 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 candidate has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
        Open

          def candidate(word)
            list = []
            case word
            when '-'
              long = short = true
        Severity: Minor
        Found in lib/rubygems/vendor/optparse/lib/optparse.rb - About 3 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_in_order has 73 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def parse_in_order(argv = default_argv, setter = nil, &nonopt)  # :nodoc:
            opt, arg, val, rest = nil
            nonopt ||= proc {|a| throw :terminate, a}
            argv.unshift(arg) if arg = catch(:terminate) {
              while arg = argv.shift
        Severity: Major
        Found in lib/rubygems/vendor/optparse/lib/optparse.rb - About 2 hrs to fix

          Method complete has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
          Open

              def complete(key, icase = false, pat = nil)
                candidates = candidate(key, icase, pat, &method(:each)).sort_by {|k, v, kn| kn.size}
                if candidates.size == 1
                  canon, sw, * = candidates[0]
                elsif candidates.size > 1
          Severity: Minor
          Found in lib/rubygems/vendor/optparse/lib/optparse.rb - About 2 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 load has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
          Open

            def load(filename = nil, into: nil)
              unless filename
                basename = File.basename($0, '.*')
                return true if load(File.expand_path(basename, '~/.options'), into: into) rescue nil
                basename << ".options"
          Severity: Minor
          Found in lib/rubygems/vendor/optparse/lib/optparse.rb - About 2 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 getopts has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

            def getopts(*args, symbolize_names: false)
              argv = Array === args.first ? args.shift : default_argv
              single_options, *long_options = *args
          
              result = {}
          Severity: Minor
          Found in lib/rubygems/vendor/optparse/lib/optparse.rb - About 2 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 pretty_print has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

            def pretty_print(q)           # :nodoc:
              q.object_group(self) do
                first = true
                if @stack.size > 2
                  @stack.each_with_index do |s, i|
          Severity: Minor
          Found in lib/rubygems/vendor/optparse/lib/optparse.rb - About 2 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 candidate has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              def self.candidate(key, icase = false, pat = nil, &block)
                pat ||= Completion.regexp(key, icase)
                candidates = []
                block.call do |k, *v|
                  (if Regexp === k
          Severity: Minor
          Found in lib/rubygems/vendor/optparse/lib/optparse.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_arg has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              def parse_arg(arg) # :nodoc:
                pattern or return nil, [arg]
                unless m = pattern.match(arg)
                  yield(InvalidArgument, arg)
                  return arg, []
          Severity: Minor
          Found in lib/rubygems/vendor/optparse/lib/optparse.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 summarize has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def summarize(sdone = {}, ldone = {}, width = 1, max = width - 1, indent = "")
                sopts, lopts = [], [], nil
                @short.each {|s| sdone.fetch(s) {sopts << s}; sdone[s] = true} if @short
                @long.each {|s| ldone.fetch(s) {lopts << s}; ldone[s] = true} if @long
                return if sopts.empty? and lopts.empty? # completely hidden
          Severity: Minor
          Found in lib/rubygems/vendor/optparse/lib/optparse.rb - About 1 hr to fix

            Method candidate has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def candidate(word)
                list = []
                case word
                when '-'
                  long = short = true
            Severity: Minor
            Found in lib/rubygems/vendor/optparse/lib/optparse.rb - About 1 hr to fix

              Method initialize has 8 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def initialize(pattern = nil, conv = nil,
                                 short = nil, long = nil, arg = nil,
                                 desc = ([] if short or long), block = nil, &_block)
              Severity: Major
              Found in lib/rubygems/vendor/optparse/lib/optparse.rb - About 1 hr to fix

                Avoid deeply nested control flow statements.
                Open

                              rescue InvalidOption
                                raise if require_exact
                                # if no short options match, try completion with long
                                # options.
                                sw, = complete(:long, opt)
                Severity: Major
                Found in lib/rubygems/vendor/optparse/lib/optparse.rb - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                throw :terminate, arg unless raise_unknown
                  Severity: Major
                  Found in lib/rubygems/vendor/optparse/lib/optparse.rb - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                throw :terminate, arg unless raise_unknown
                    Severity: Major
                    Found in lib/rubygems/vendor/optparse/lib/optparse.rb - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                  throw :terminate, arg unless raise_unknown
                      Severity: Major
                      Found in lib/rubygems/vendor/optparse/lib/optparse.rb - About 45 mins to fix

                        Method complete has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                            def complete(id, opt, icase = false, *pat, &block)
                        Severity: Minor
                        Found in lib/rubygems/vendor/optparse/lib/optparse.rb - About 35 mins to fix

                          Method update has 5 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                              def update(sw, sopts, lopts, nsw = nil, nlopts = nil) # :nodoc:
                          Severity: Minor
                          Found in lib/rubygems/vendor/optparse/lib/optparse.rb - About 35 mins to fix

                            Method summarize has 5 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                                def summarize(sdone = {}, ldone = {}, width = 1, max = width - 1, indent = "")
                            Severity: Minor
                            Found in lib/rubygems/vendor/optparse/lib/optparse.rb - About 35 mins to fix

                              Method summarize has 5 arguments (exceeds 4 allowed). Consider refactoring.
                              Open

                                def summarize(to = [], width = @summary_width, max = width - 1, indent = @summary_indent, &blk)
                              Severity: Minor
                              Found in lib/rubygems/vendor/optparse/lib/optparse.rb - About 35 mins to fix

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

                                    def compsys(sdone, ldone)   # :nodoc:
                                      sopts, lopts = [], []
                                      @short.each {|s| sdone.fetch(s) {sopts << s}; sdone[s] = true} if @short
                                      @long.each {|s| ldone.fetch(s) {lopts << s}; ldone[s] = true} if @long
                                      return if sopts.empty? and lopts.empty? # completely hidden
                                Severity: Minor
                                Found in lib/rubygems/vendor/optparse/lib/optparse.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 arg[s.length..-1], m
                                Severity: Major
                                Found in lib/rubygems/vendor/optparse/lib/optparse.rb - About 30 mins to fix

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

                                      def add_banner(to)  # :nodoc:
                                        unless @short or @long
                                          s = desc.join
                                          to << " [" + s + "]..." unless s.empty?
                                        end
                                  Severity: Minor
                                  Found in lib/rubygems/vendor/optparse/lib/optparse.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 parse has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                        def parse(arg, argv, &error)
                                          if !(val = arg) and (argv.empty? or /\A-./ =~ (val = argv[0]))
                                            return nil, block, nil
                                          end
                                          opt = (val = parse_arg(val, &error))[1]
                                  Severity: Minor
                                  Found in lib/rubygems/vendor/optparse/lib/optparse.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 summarize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      def summarize(*args, &block)
                                        sum = []
                                        list.reverse_each do |opt|
                                          if opt.respond_to?(:summarize) # perhaps Gem::OptionParser::Switch
                                            s = []
                                  Severity: Minor
                                  Found in lib/rubygems/vendor/optparse/lib/optparse.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

                                  XXX found
                                  Open

                                  XXX

                                  XXX found
                                  Open

                                    COMPSYS_HEADER = <<'XXX'      # :nodoc:

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

                                    def parse(*argv, into: nil)
                                      argv = argv[0].dup if argv.size == 1 and Array === argv[0]
                                      parse!(argv, into: into)
                                  Severity: Minor
                                  Found in lib/rubygems/vendor/optparse/lib/optparse.rb and 1 other location - About 15 mins to fix
                                  lib/rubygems/vendor/optparse/lib/optparse.rb on lines 1728..1730

                                  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

                                    def permute(*argv, into: nil)
                                      argv = argv[0].dup if argv.size == 1 and Array === argv[0]
                                      permute!(argv, into: into)
                                  Severity: Minor
                                  Found in lib/rubygems/vendor/optparse/lib/optparse.rb and 1 other location - About 15 mins to fix
                                  lib/rubygems/vendor/optparse/lib/optparse.rb on lines 1751..1753

                                  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

                                  There are no issues that match your filters.

                                  Category
                                  Status