ManageIQ/binary_struct

View on GitHub

Showing 16 of 16 total issues

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

class BinaryStruct
  SIZES = {
    'A'   => 1,   # String with trailing NULs and spaces removed
    'a'   => 1,   # String
    'B'   => 1,   # Extract bits from each character (MSB first)
Severity: Minor
Found in lib/binary_struct.rb - About 2 hrs to fix

    Method encode_hash has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

      def encode_hash(hash)
        data = ""
        @definition.each_slice(2) do |format, name|
          raise "member not found: #{name}" unless name.nil? || hash.has_key?(name)
          value = unless name.nil?
    Severity: Minor
    Found in lib/binary_struct.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_size has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.get_size(definition)
        size = 0
        definition.each_slice(2) do |format, _|
          type, count        = format[0, 1], format[1..-1]
          modifier, modcount = count[0, 1], count[1..-1]
    Severity: Minor
    Found in lib/binary_struct.rb - About 55 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method offset has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def offset(attr)
        offset = 0
        self.definition.each_slice(2) do |format, name|
          return offset if name == attr
    
    
    Severity: Minor
    Found in lib/binary_struct.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

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

      def self.prep_decode(definition)
    Severity: Minor
    Found in lib/binary_struct.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

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

      def self.validate_definition_entry_count(count)
    Severity: Minor
    Found in lib/binary_struct.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

    Remove unnecessary require statement.
    Open

    require "enumerator"
    Severity: Minor
    Found in lib/binary_struct.rb by rubocop

    Checks for unnecessary require statement.

    The following features are unnecessary require statement because they are already loaded. e.g. Ruby 2.2:

    ruby -ve 'p $LOADED_FEATURES.reject { |feature| %r|/| =~ feature }'
    ruby 2.2.8p477 (2017-09-14 revision 59906) [x86_64-darwin13]
    ["enumerator.so", "rational.so", "complex.so", "thread.rb"]

    Below are the features that each TargetRubyVersion targets.

    * 2.0+ ... `enumerator`
    * 2.1+ ... `thread`
    * 2.2+ ... Add `rational` and `complex` above
    * 2.5+ ... Add `pp` above
    * 2.7+ ... Add `ruby2_keywords` above
    * 3.1+ ... Add `fiber` above
    * 3.2+ ... `set`

    This cop target those features.

    Example:

    # bad
    require 'unloaded_feature'
    require 'thread'
    
    # good
    require 'unloaded_feature'

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

      def self.struct_by_definition(definition)
    Severity: Minor
    Found in lib/binary_struct.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

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

      def self.validate_definition_endian_modifier(modifier, type)
    Severity: Minor
    Found in lib/binary_struct.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

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

    Gem::Specification.new do |spec|
      spec.name          = "binary_struct"
      spec.version       = BinaryStruct::VERSION
      spec.authors       = ["Oleg Barenboim", "Jason Frey"]
      spec.email         = ["chessbyte@gmail.com", "fryguy9@gmail.com"]
    Severity: Minor
    Found in binary_struct.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

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

      def self.validate_definition(definition)
    Severity: Minor
    Found in lib/binary_struct.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

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

      def self.valid_definition_entry_modifier?(modifier)
    Severity: Minor
    Found in lib/binary_struct.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

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

      def self.validate_definition_entry_type(type)
    Severity: Minor
    Found in lib/binary_struct.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

    Useless private access modifier.
    Open

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

    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 private modifier)
      private
    
      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

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

      def self.get_size(definition)
    Severity: Minor
    Found in lib/binary_struct.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

    Do not set test_files in gemspec.
    Open

      spec.test_files    = `git ls-files -- spec/*`.split("\n")
    Severity: Minor
    Found in binary_struct.gemspec by rubocop

    Checks that deprecated attributes are not set in a gemspec file. Removing deprecated attributes allows the user to receive smaller packed gems.

    Example:

    # bad
    Gem::Specification.new do |spec|
      spec.name = 'your_cool_gem_name'
      spec.test_files = Dir.glob('test/**/*')
    end
    
    # bad
    Gem::Specification.new do |spec|
      spec.name = 'your_cool_gem_name'
      spec.test_files += Dir.glob('test/**/*')
    end
    
    # good
    Gem::Specification.new do |spec|
      spec.name = 'your_cool_gem_name'
    end
    Severity
    Category
    Status
    Source
    Language