ManageIQ/optimist

View on GitHub
lib/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/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/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/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. [41/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

    This cop 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.

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

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

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

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

          This cop 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.

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

            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/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/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/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/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/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/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/optimist.rb - About 30 mins to fix

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

                      Avoid more than 3 levels of block nesting.
                      Open

                                if @stop_on_unknown
                                  return remains += args[i + 1..-1]
                                end
                      Severity: Minor
                      Found in lib/optimist.rb by rubocop

                      This cop checks for excessive nesting of conditional and looping constructs.

                      You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

                      The maximum level of nesting allowed is configurable.

                      Avoid more than 3 levels of block nesting.
                      Open

                                  unless num_params_taken
                                    short_remaining << a
                                    if @stop_on_unknown
                                      remains << "-#{short_remaining}"
                                      return remains += args[i + 1..-1]
                      Severity: Minor
                      Found in lib/optimist.rb by rubocop

                      This cop checks for excessive nesting of conditional and looping constructs.

                      You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

                      The maximum level of nesting allowed is configurable.

                      Avoid more than 3 levels of block nesting.
                      Open

                                if @stop_on_unknown
                                  return remains += args[i + 1..-1]
                                end
                      Severity: Minor
                      Found in lib/optimist.rb by rubocop

                      This cop checks for excessive nesting of conditional and looping constructs.

                      You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

                      The maximum level of nesting allowed is configurable.

                      Avoid more than 3 levels of block nesting.
                      Open

                                  unless yield "-#{a}", []
                                    short_remaining << a
                                    if @stop_on_unknown
                                      short_remaining += shortargs[j + 1..-1].join
                                      remains << "-#{short_remaining}"
                      Severity: Minor
                      Found in lib/optimist.rb by rubocop

                      This cop checks for excessive nesting of conditional and looping constructs.

                      You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

                      The maximum level of nesting allowed is configurable.

                      Use match? instead of =~ when MatchData is not used.
                      Open

                              if param =~ /^(stdin|-)$/i
                      Severity: Minor
                      Found in lib/optimist.rb by rubocop

                      In Ruby 2.4, String#match?, Regexp#match? and Symbol#match? have been added. The methods are faster than match. Because the methods avoid creating a MatchData object or saving backref. So, when MatchData is not used, use match? instead of match.

                      Example:

                      # bad
                      def foo
                        if x =~ /re/
                          do_something
                        end
                      end
                      
                      # bad
                      def foo
                        if x.match(/re/)
                          do_something
                        end
                      end
                      
                      # bad
                      def foo
                        if /re/ === x
                          do_something
                        end
                      end
                      
                      # good
                      def foo
                        if x.match?(/re/)
                          do_something
                        end
                      end
                      
                      # good
                      def foo
                        if x =~ /re/
                          do_something(Regexp.last_match)
                        end
                      end
                      
                      # good
                      def foo
                        if x.match(/re/)
                          do_something($~)
                        end
                      end
                      
                      # good
                      def foo
                        if /re/ === x
                          do_something($~)
                        end
                      end

                      Use match? instead of =~ when MatchData is not used.
                      Open

                            raise ArgumentError, "a short option name can't be a number or a dash" if sopt =~ ::Optimist::Parser::INVALID_SHORT_ARG_REGEX
                      Severity: Minor
                      Found in lib/optimist.rb by rubocop

                      In Ruby 2.4, String#match?, Regexp#match? and Symbol#match? have been added. The methods are faster than match. Because the methods avoid creating a MatchData object or saving backref. So, when MatchData is not used, use match? instead of match.

                      Example:

                      # bad
                      def foo
                        if x =~ /re/
                          do_something
                        end
                      end
                      
                      # bad
                      def foo
                        if x.match(/re/)
                          do_something
                        end
                      end
                      
                      # bad
                      def foo
                        if /re/ === x
                          do_something
                        end
                      end
                      
                      # good
                      def foo
                        if x.match?(/re/)
                          do_something
                        end
                      end
                      
                      # good
                      def foo
                        if x =~ /re/
                          do_something(Regexp.last_match)
                        end
                      end
                      
                      # good
                      def foo
                        if x.match(/re/)
                          do_something($~)
                        end
                      end
                      
                      # good
                      def foo
                        if /re/ === x
                          do_something($~)
                        end
                      end

                      Use tr instead of gsub.
                      Open

                          lopt = lopt ? lopt.to_s : name.to_s.gsub("_", "-")
                      Severity: Minor
                      Found in lib/optimist.rb by rubocop

                      This cop identifies places where gsub can be replaced by tr or delete.

                      Example:

                      # bad
                      'abc'.gsub('b', 'd')
                      'abc'.gsub('a', '')
                      'abc'.gsub(/a/, 'd')
                      'abc'.gsub!('a', 'd')
                      
                      # good
                      'abc'.gsub(/.*/, 'a')
                      'abc'.gsub(/a+/, 'd')
                      'abc'.tr('b', 'd')
                      'a b c'.delete(' ')

                      Use match? instead of =~ when MatchData is not used.
                      Open

                            sym = nil if arg =~ /--no-/ # explicitly invalidate --no-no- arguments
                      Severity: Minor
                      Found in lib/optimist.rb by rubocop

                      In Ruby 2.4, String#match?, Regexp#match? and Symbol#match? have been added. The methods are faster than match. Because the methods avoid creating a MatchData object or saving backref. So, when MatchData is not used, use match? instead of match.

                      Example:

                      # bad
                      def foo
                        if x =~ /re/
                          do_something
                        end
                      end
                      
                      # bad
                      def foo
                        if x.match(/re/)
                          do_something
                        end
                      end
                      
                      # bad
                      def foo
                        if /re/ === x
                          do_something
                        end
                      end
                      
                      # good
                      def foo
                        if x.match?(/re/)
                          do_something
                        end
                      end
                      
                      # good
                      def foo
                        if x =~ /re/
                          do_something(Regexp.last_match)
                        end
                      end
                      
                      # good
                      def foo
                        if x.match(/re/)
                          do_something($~)
                        end
                      end
                      
                      # good
                      def foo
                        if /re/ === x
                          do_something($~)
                        end
                      end

                      Use match? instead of =~ when MatchData is not used.
                      Open

                          return(self.name.to_s =~ /^no_/ ? neg_given : !neg_given)
                      Severity: Minor
                      Found in lib/optimist.rb by rubocop

                      In Ruby 2.4, String#match?, Regexp#match? and Symbol#match? have been added. The methods are faster than match. Because the methods avoid creating a MatchData object or saving backref. So, when MatchData is not used, use match? instead of match.

                      Example:

                      # bad
                      def foo
                        if x =~ /re/
                          do_something
                        end
                      end
                      
                      # bad
                      def foo
                        if x.match(/re/)
                          do_something
                        end
                      end
                      
                      # bad
                      def foo
                        if /re/ === x
                          do_something
                        end
                      end
                      
                      # good
                      def foo
                        if x.match?(/re/)
                          do_something
                        end
                      end
                      
                      # good
                      def foo
                        if x =~ /re/
                          do_something(Regexp.last_match)
                        end
                      end
                      
                      # good
                      def foo
                        if x.match(/re/)
                          do_something($~)
                        end
                      end
                      
                      # good
                      def foo
                        if /re/ === x
                          do_something($~)
                        end
                      end

                      The use of Kernel#open is a serious security risk.
                      Open

                                  open param
                      Severity: Minor
                      Found in lib/optimist.rb by rubocop

                      This cop checks for the use of Kernel#open.

                      Kernel#open enables not only file access but also process invocation by prefixing a pipe symbol (e.g., open("| ls")). So, it may lead to a serious security risk by using variable input to the argument of Kernel#open. It would be better to use File.open, IO.popen or URI#open explicitly.

                      Example:

                      # bad
                      open(something)
                      
                      # good
                      File.open(something)
                      IO.popen(something)
                      URI.parse(something).open

                      Useless assignment to variable - lopt.
                      Open

                          lopt = case lopt
                      Severity: Minor
                      Found in lib/optimist.rb by rubocop

                      This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

                      assigned but unused variable - foo

                      Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

                      Example:

                      # bad
                      
                      def some_method
                        some_var = 1
                        do_something
                      end

                      Example:

                      # good
                      
                      def some_method
                        some_var = 1
                        do_something(some_var)
                      end

                      private (on line 694) does not make singleton methods private. Use private_class_method or private inside a class << self block instead.
                      Open

                        def self.handle_short_opt(sopt)
                      Severity: Minor
                      Found in lib/optimist.rb by rubocop

                      This cop checks for private or protected access modifiers which are applied to a singleton method. These access modifiers do not make singleton methods private/protected. private_class_method can be used for that.

                      Example:

                      # bad
                      
                      class C
                        private
                      
                        def self.method
                          puts 'hi'
                        end
                      end

                      Example:

                      # good
                      
                      class C
                        def self.method
                          puts 'hi'
                        end
                      
                        private_class_method :method
                      end

                      Example:

                      # good
                      
                      class C
                        class << self
                          private
                      
                          def method
                            puts 'hi'
                          end
                        end
                      end

                      Unused method argument - desc. If it's necessary, use _ or _desc as an argument name to indicate that it won't be used.
                      Open

                        def self.create(name, desc="", opts={}, settings={})
                      Severity: Minor
                      Found in lib/optimist.rb by rubocop

                      This cop checks for unused method arguments.

                      Example:

                      # bad
                      def some_method(used, unused, _unused_but_allowed)
                        puts used
                      end
                      
                      # good
                      def some_method(used, _unused, _unused_but_allowed)
                        puts used
                      end

                      Example: AllowUnusedKeywordArguments: false (default)

                      # bad
                      def do_something(used, unused: 42)
                        used
                      end

                      Example: AllowUnusedKeywordArguments: true

                      # good
                      def do_something(used, unused: 42)
                        used
                      end

                      Example: IgnoreEmptyMethods: true (default)

                      # good
                      def do_something(unused)
                      end

                      Example: IgnoreEmptyMethods: false

                      # bad
                      def do_something(unused)
                      end

                      Example: IgnoreNotImplementedMethods: true (default)

                      # good
                      def do_something(unused)
                        raise NotImplementedError
                      end
                      
                      def do_something_else(unused)
                        fail "TODO"
                      end

                      Example: IgnoreNotImplementedMethods: false

                      # bad
                      def do_something(unused)
                        raise NotImplementedError
                      end
                      
                      def do_something_else(unused)
                        fail "TODO"
                      end

                      private (on line 694) does not make singleton methods private. Use private_class_method or private inside a class << self block instead.
                      Open

                        def self.handle_long_opt(lopt, name)
                      Severity: Minor
                      Found in lib/optimist.rb by rubocop

                      This cop checks for private or protected access modifiers which are applied to a singleton method. These access modifiers do not make singleton methods private/protected. private_class_method can be used for that.

                      Example:

                      # bad
                      
                      class C
                        private
                      
                        def self.method
                          puts 'hi'
                        end
                      end

                      Example:

                      # good
                      
                      class C
                        def self.method
                          puts 'hi'
                        end
                      
                        private_class_method :method
                      end

                      Example:

                      # good
                      
                      class C
                        class << self
                          private
                      
                          def method
                            puts 'hi'
                          end
                        end
                      end

                      Unused method argument - settings. If it's necessary, use _ or _settings as an argument name to indicate that it won't be used.
                      Open

                        def self.create(name, desc="", opts={}, settings={})
                      Severity: Minor
                      Found in lib/optimist.rb by rubocop

                      This cop checks for unused method arguments.

                      Example:

                      # bad
                      def some_method(used, unused, _unused_but_allowed)
                        puts used
                      end
                      
                      # good
                      def some_method(used, _unused, _unused_but_allowed)
                        puts used
                      end

                      Example: AllowUnusedKeywordArguments: false (default)

                      # bad
                      def do_something(used, unused: 42)
                        used
                      end

                      Example: AllowUnusedKeywordArguments: true

                      # good
                      def do_something(used, unused: 42)
                        used
                      end

                      Example: IgnoreEmptyMethods: true (default)

                      # good
                      def do_something(unused)
                      end

                      Example: IgnoreEmptyMethods: false

                      # bad
                      def do_something(unused)
                      end

                      Example: IgnoreNotImplementedMethods: true (default)

                      # good
                      def do_something(unused)
                        raise NotImplementedError
                      end
                      
                      def do_something_else(unused)
                        fail "TODO"
                      end

                      Example: IgnoreNotImplementedMethods: false

                      # bad
                      def do_something(unused)
                        raise NotImplementedError
                      end
                      
                      def do_something_else(unused)
                        fail "TODO"
                      end

                      Useless private access modifier.
                      Open

                        private
                      Severity: Minor
                      Found in lib/optimist.rb by rubocop

                      This cop checks for redundant access modifiers, including those with no code, those which are repeated, and leading public modifiers in a class or module body. Conditionally-defined methods are considered as always being defined, and thus access modifiers guarding such methods are not redundant.

                      This cop has ContextCreatingMethods option. The default setting value is an empty array that means no method is specified. This setting is an array of methods which, when called, are known to create its own context in the module's current access context.

                      It also has MethodCreatingMethods option. The default setting value is an empty array that means no method is specified. This setting is an array of methods which, when called, are known to create other methods in the module's current access context.

                      Example:

                      # bad
                      class Foo
                        public # this is redundant (default access is public)
                      
                        def method
                        end
                      end
                      
                      # bad
                      class Foo
                        # The following is redundant (methods defined on the class'
                        # singleton class are not affected by the public modifier)
                        public
                      
                        def self.method3
                        end
                      end
                      
                      # bad
                      class Foo
                        protected
                      
                        define_method(:method2) do
                        end
                      
                        protected # this is redundant (repeated from previous modifier)
                      
                        [1,2,3].each do |i|
                          define_method("foo#{i}") do
                          end
                        end
                      end
                      
                      # bad
                      class Foo
                        private # this is redundant (no following methods are defined)
                      end
                      
                      # good
                      class Foo
                        private # this is not redundant (a method is defined)
                      
                        def method2
                        end
                      end
                      
                      # good
                      class Foo
                        # The following is not redundant (conditionally defined methods are
                        # considered as always defining a method)
                        private
                      
                        if condition?
                          def method
                          end
                        end
                      end
                      
                      # good
                      class Foo
                        protected # this is not redundant (a method is defined)
                      
                        define_method(:method2) do
                        end
                      end

                      Example: ContextCreatingMethods: concerning

                      # Lint/UselessAccessModifier:
                      #   ContextCreatingMethods:
                      #     - concerning
                      
                      # good
                      require 'active_support/concern'
                      class Foo
                        concerning :Bar do
                          def some_public_method
                          end
                      
                          private
                      
                          def some_private_method
                          end
                        end
                      
                        # this is not redundant because `concerning` created its own context
                        private
                      
                        def some_other_private_method
                        end
                      end

                      Example: MethodCreatingMethods: delegate

                      # Lint/UselessAccessModifier:
                      #   MethodCreatingMethods:
                      #     - delegate
                      
                      # good
                      require 'active_support/core_ext/module/delegation'
                      class Foo
                        # this is not redundant because `delegate` creates methods
                        private
                      
                        delegate :method_a, to: :method_b
                      end

                      Unused block argument - val. If it's necessary, use _ or _val as an argument name to indicate that it won't be used.
                      Open

                          required.each do |sym, val|
                      Severity: Minor
                      Found in lib/optimist.rb by rubocop

                      This cop checks for unused block arguments.

                      Example:

                      # bad
                      do_something do |used, unused|
                        puts used
                      end
                      
                      do_something do |bar|
                        puts :foo
                      end
                      
                      define_method(:foo) do |bar|
                        puts :baz
                      end
                      
                      # good
                      do_something do |used, _unused|
                        puts used
                      end
                      
                      do_something do
                        puts :foo
                      end
                      
                      define_method(:foo) do |_bar|
                        puts :baz
                      end

                      Example: IgnoreEmptyBlocks: true (default)

                      # good
                      do_something { |unused| }

                      Example: IgnoreEmptyBlocks: false

                      # bad
                      do_something { |unused| }

                      Example: AllowUnusedKeywordArguments: false (default)

                      # bad
                      do_something do |unused: 42|
                        foo
                      end

                      Example: AllowUnusedKeywordArguments: true

                      # good
                      do_something do |unused: 42|
                        foo
                      end

                      private (on line 694) does not make singleton methods private. Use private_class_method or private inside a class << self block instead.
                      Open

                        def self.get_klass_from_default(opts, opttype)
                      Severity: Minor
                      Found in lib/optimist.rb by rubocop

                      This cop checks for private or protected access modifiers which are applied to a singleton method. These access modifiers do not make singleton methods private/protected. private_class_method can be used for that.

                      Example:

                      # bad
                      
                      class C
                        private
                      
                        def self.method
                          puts 'hi'
                        end
                      end

                      Example:

                      # good
                      
                      class C
                        def self.method
                          puts 'hi'
                        end
                      
                        private_class_method :method
                      end

                      Example:

                      # good
                      
                      class C
                        class << self
                          private
                      
                          def method
                            puts 'hi'
                          end
                        end
                      end

                      private (on line 694) does not make singleton methods private. Use private_class_method or private inside a class << self block instead.
                      Open

                        def self.get_type_from_disdef(optdef, opttype, disambiguated_default)
                      Severity: Minor
                      Found in lib/optimist.rb by rubocop

                      This cop checks for private or protected access modifiers which are applied to a singleton method. These access modifiers do not make singleton methods private/protected. private_class_method can be used for that.

                      Example:

                      # bad
                      
                      class C
                        private
                      
                        def self.method
                          puts 'hi'
                        end
                      end

                      Example:

                      # good
                      
                      class C
                        def self.method
                          puts 'hi'
                        end
                      
                        private_class_method :method
                      end

                      Example:

                      # good
                      
                      class C
                        class << self
                          private
                      
                          def method
                            puts 'hi'
                          end
                        end
                      end

                      There are no issues that match your filters.

                      Category
                      Status