amazing-print/amazing_print

View on GitHub

Showing 36 of 36 total issues

Method format has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

      def format
        vars = variables.map do |var|
          property = var.to_s[1..-1].to_sym # to_s because of some monkey patching done by Puppet.
          accessor = if object.respond_to?(:"#{property}=")
                       object.respond_to?(property) ? :accessor : :writer
Severity: Minor
Found in lib/amazing_print/formatters/object_formatter.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 format has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

      def format
        vars = variables.map do |var|
          property = var.to_s[1..-1].to_sym # to_s because of some monkey patching done by Puppet.
          accessor = if struct.respond_to?(:"#{property}=")
                       struct.respond_to?(property) ? :accessor : :writer
Severity: Minor
Found in lib/amazing_print/formatters/struct_formatter.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 awesome_active_record_instance has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    def awesome_active_record_instance(object)
      return object.inspect unless defined?(::ActiveSupport::OrderedHash)
      return awesome_object(object) if @options[:raw]

      data = if object.class.column_names == object.attributes.keys
Severity: Minor
Found in lib/amazing_print/ext/active_record.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 initialize has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def initialize(options = {})
      @options = {
        indent: 4, # Number of spaces for indenting.
        index: true, # Display array indices.
        html: false, # Use ANSI color codes rather than HTML.
Severity: Minor
Found in lib/amazing_print/inspector.rb - About 1 hr to fix

    Method format has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def format
            vars = variables.map do |var|
              property = var.to_s[1..-1].to_sym # to_s because of some monkey patching done by Puppet.
              accessor = if object.respond_to?(:"#{property}=")
                           object.respond_to?(property) ? :accessor : :writer
    Severity: Minor
    Found in lib/amazing_print/formatters/object_formatter.rb - About 1 hr to fix

      Method format has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def format
              vars = variables.map do |var|
                property = var.to_s[1..-1].to_sym # to_s because of some monkey patching done by Puppet.
                accessor = if struct.respond_to?(:"#{property}=")
                             struct.respond_to?(property) ? :accessor : :writer
      Severity: Minor
      Found in lib/amazing_print/formatters/struct_formatter.rb - About 1 hr to fix

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

            def awesome_mongoid_document(object)
              return object.inspect unless defined?(::ActiveSupport::OrderedHash)
        
              aliases = object.aliased_fields.invert
              data = (object.attributes || {}).sort.each_with_object(::ActiveSupport::OrderedHash.new) do |c, hash|
        Severity: Minor
        Found in lib/amazing_print/ext/mongoid.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

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

                  key = left_aligned do
                    align(declaration, declaration.size)
                  end
        
                  unless options[:plain]
        Severity: Major
        Found in lib/amazing_print/formatters/object_formatter.rb and 1 other location - About 1 hr to fix
        lib/amazing_print/formatters/struct_formatter.rb on lines 34..47

        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 53.

        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

                  key = left_aligned do
                    align(declaration, declaration.size)
                  end
        
                  unless options[:plain]
        Severity: Major
        Found in lib/amazing_print/formatters/struct_formatter.rb and 1 other location - About 1 hr to fix
        lib/amazing_print/formatters/object_formatter.rb on lines 34..47

        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 53.

        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

        Method mode has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

              def mode
                r = ['-'] * 6
                r[0] = 'd' if @stat.directory?
                r[1] = 'a' unless (@attrs & FILE_ATTRIBUTE_ARCHIVE).zero?
                r[2] = 'r' unless (@attrs & FILE_ATTRIBUTE_READONLY).zero?
        Severity: Minor
        Found in lib/amazing_print/formatters/mswin_helper.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 awesome_mongo_mapper_instance has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def awesome_mongo_mapper_instance(object)
              return object.inspect unless defined?(::ActiveSupport::OrderedHash)
              return awesome_object(object) if @options[:raw]
        
              data = object.keys.keys.sort.each_with_object(::ActiveSupport::OrderedHash.new) do |name, hash|
        Severity: Minor
        Found in lib/amazing_print/ext/mongo_mapper.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

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

                vars = variables.map do |var|
                  property = var.to_s[1..-1].to_sym # to_s because of some monkey patching done by Puppet.
                  accessor = if object.respond_to?(:"#{property}=")
                               object.respond_to?(property) ? :accessor : :writer
                             else
        Severity: Minor
        Found in lib/amazing_print/formatters/object_formatter.rb and 1 other location - About 55 mins to fix
        lib/amazing_print/formatters/struct_formatter.rb on lines 19..29

        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 46.

        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

                vars = variables.map do |var|
                  property = var.to_s[1..-1].to_sym # to_s because of some monkey patching done by Puppet.
                  accessor = if struct.respond_to?(:"#{property}=")
                               struct.respond_to?(property) ? :accessor : :writer
                             else
        Severity: Minor
        Found in lib/amazing_print/formatters/struct_formatter.rb and 1 other location - About 55 mins to fix
        lib/amazing_print/formatters/object_formatter.rb on lines 19..29

        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 46.

        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

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

            def cast_with_mongoid(object, type)
              cast = cast_without_mongoid(object, type)
              if defined?(::Mongoid::Document)
                if object.is_a?(Class) && object.ancestors.include?(::Mongoid::Document)
                  cast = :mongoid_class
        Severity: Minor
        Found in lib/amazing_print/ext/mongoid.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 awesome_mongoid_class has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def awesome_mongoid_class(object)
              return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:fields)
        
              aliases = object.aliased_fields.invert
              data = object.fields.sort.each_with_object(::ActiveSupport::OrderedHash.new) do |c, hash|
        Severity: Minor
        Found in lib/amazing_print/ext/mongoid.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

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

            def cast_with_active_record(object, type)
              cast = cast_without_active_record(object, type)
              return cast unless defined?(::ActiveRecord::Base)
        
              if object.is_a?(::ActiveRecord::Base)
        Severity: Minor
        Found in lib/amazing_print/ext/active_record.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

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

            def cast_with_mongo_mapper(object, type)
              apply_default_mongo_mapper_options
              cast = cast_without_mongo_mapper(object, type)
        
              if defined?(::MongoMapper::Document)
        Severity: Minor
        Found in lib/amazing_print/ext/mongo_mapper.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

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

            def self.call
              return if @load_attemps >= EXT_LOAD_ATTEMPT_LIMIT
        
              require_relative 'ext/mongo_mapper'   if defined?(MongoMapper)
              require_relative 'ext/mongoid'        if defined?(Mongoid)
        Severity: Minor
        Found in lib/amazing_print/ext_loader.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

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

              def printable_hash
                data = printable_keys
                width = left_width(data)
        
                data.map! do |key, value|
        Severity: Minor
        Found in lib/amazing_print/formatters/hash_formatter.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 convert_to_hash has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def convert_to_hash(object)
              return nil unless object.respond_to?(:to_hash)
        
              return nil if object.method(:to_hash).arity != 0
        
        
        Severity: Minor
        Found in lib/amazing_print/formatter.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

        Severity
        Category
        Status
        Source
        Language