ManageIQ/trollop

View on GitHub

Showing 53 of 53 total issues

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

    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

      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

      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

      Wrap expressions with varying precedence with parentheses to avoid ambiguity.
      Open

            ret << ((ret.empty? && !opts[:inner]) ? "" : " " * prefix) + str[start...nextt]
      Severity: Minor
      Found in lib/optimist.rb by rubocop

      Looks for expressions containing multiple binary operators where precedence is ambiguous due to lack of parentheses. For example, in 1 + 2 * 3, the multiplication will happen before the addition, but lexically it appears that the addition will happen first.

      The cop does not consider unary operators (ie. !a or -b) or comparison operators (ie. a =~ b) because those are not ambiguous.

      NOTE: Ranges are handled by Lint/AmbiguousRange.

      Example:

      # bad
      a + b * c
      a || b && c
      a ** b + c
      
      # good (different precedence)
      a + (b * c)
      a || (b && c)
      (a ** b) + c
      
      # good (same precedence)
      a + b + c
      a * b / c % d

      private (on line 702) 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

      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

      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

      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

          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

      Use string as argument instead of regexp.
      Open

            c = opts.long.split(//).find { |d| d !~ INVALID_SHORT_ARG_REGEX && !@short.member?(d) }
      Severity: Minor
      Found in lib/optimist.rb by rubocop

      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

            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 bind_call(self, *a) instead of bind(self).call(*a).
      Open

          cloaker(&b).bind(self).call(*a) if b
      Severity: Minor
      Found in lib/optimist.rb by rubocop

      metadata['rubygems_mfa_required'] must be set to 'true'.
      Open

      Gem::Specification.new do |spec|
        spec.name          = "optimist"
        spec.version       = Optimist::VERSION
        spec.authors       = ["William Morgan", "Keenan Brock", "Jason Frey"]
        spec.email         = "keenan@thebrocks.net"
      Severity: Minor
      Found in optimist.gemspec by rubocop

      Requires a gemspec to have rubygems_mfa_required metadata set.

      This setting tells RubyGems that MFA (Multi-Factor Authentication) is required for accounts to be able perform privileged operations, such as (see RubyGems' documentation for the full list of privileged operations):

      • gem push
      • gem yank
      • gem owner --add/remove
      • adding or removing owners using gem ownership page

      This helps make your gem more secure, as users can be more confident that gem updates were pushed by maintainers.

      Example:

      # bad
      Gem::Specification.new do |spec|
        # no `rubygems_mfa_required` metadata specified
      end
      
      # good
      Gem::Specification.new do |spec|
        spec.metadata = {
          'rubygems_mfa_required' => 'true'
        }
      end
      
      # good
      Gem::Specification.new do |spec|
        spec.metadata['rubygems_mfa_required'] = 'true'
      end
      
      # bad
      Gem::Specification.new do |spec|
        spec.metadata = {
          'rubygems_mfa_required' => 'false'
        }
      end
      
      # good
      Gem::Specification.new do |spec|
        spec.metadata = {
          'rubygems_mfa_required' => 'true'
        }
      end
      
      # bad
      Gem::Specification.new do |spec|
        spec.metadata['rubygems_mfa_required'] = 'false'
      end
      
      # good
      Gem::Specification.new do |spec|
        spec.metadata['rubygems_mfa_required'] = 'true'
      end

      Use string as argument instead of regexp.
      Open

              shortargs = $1.split(//)
      Severity: Minor
      Found in lib/optimist.rb by rubocop

      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

      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

      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

      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

      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.

      private (on line 702) 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

      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

      Check block argument explicitly instead of using block_given?.
      Open

          opts[:callback] ||= b if block_given?
      Severity: Minor
      Found in lib/optimist.rb by rubocop
      Severity
      Category
      Status
      Source
      Language