reactrb/reactrb

View on GitHub
lib/react/api.rb

Summary

Maintainability
B
6 hrs
Test Coverage

Method has too many lines. [54/30]
Open

    def self.create_native_react_class(type)
      raise "Provided class should define `render` method"  if !(type.method_defined? :render)
      render_fn = (type.method_defined? :_render_wrapper) ? :_render_wrapper : :render
      # this was hashing type.to_s, not sure why but .to_s does not work as it Foo::Bar::View.to_s just returns "View"
      @@component_classes[type] ||= %x{
Severity: Minor
Found in lib/react/api.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Cyclomatic complexity for create_native_react_class is too high. [14/6]
Open

    def self.create_native_react_class(type)
      raise "Provided class should define `render` method"  if !(type.method_defined? :render)
      render_fn = (type.method_defined? :_render_wrapper) ? :_render_wrapper : :render
      # this was hashing type.to_s, not sure why but .to_s does not work as it Foo::Bar::View.to_s just returns "View"
      @@component_classes[type] ||= %x{
Severity: Minor
Found in lib/react/api.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 convert_props has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

    def self.convert_props(properties)
      raise "Component parameters must be a hash. Instead you sent #{properties}" unless properties.is_a? Hash
      props = {}
      properties.map do |key, value|
        if key == "class_name" && value.is_a?(Hash)
Severity: Minor
Found in lib/react/api.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

Cyclomatic complexity for convert_props is too high. [12/6]
Open

    def self.convert_props(properties)
      raise "Component parameters must be a hash. Instead you sent #{properties}" unless properties.is_a? Hash
      props = {}
      properties.map do |key, value|
        if key == "class_name" && value.is_a?(Hash)
Severity: Minor
Found in lib/react/api.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 create_native_react_class has 54 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def self.create_native_react_class(type)
      raise "Provided class should define `render` method"  if !(type.method_defined? :render)
      render_fn = (type.method_defined? :_render_wrapper) ? :_render_wrapper : :render
      # this was hashing type.to_s, not sure why but .to_s does not work as it Foo::Bar::View.to_s just returns "View"
      @@component_classes[type] ||= %x{
Severity: Major
Found in lib/react/api.rb - About 2 hrs to fix

    Cyclomatic complexity for eval_native_react_component is too high. [7/6]
    Open

        def self.eval_native_react_component(name)
          component = `eval(name)`
          raise "#{name} is not defined" if `#{component} === undefined`
          is_component_class = `#{component}.prototype !== undefined` &&
                                (`!!#{component}.prototype.isReactComponent` ||
    Severity: Minor
    Found in lib/react/api.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 convert_props has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def self.convert_props(properties)
          raise "Component parameters must be a hash. Instead you sent #{properties}" unless properties.is_a? Hash
          props = {}
          properties.map do |key, value|
            if key == "class_name" && value.is_a?(Hash)
    Severity: Minor
    Found in lib/react/api.rb - About 1 hr to fix

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

          def self.eval_native_react_component(name)
            component = `eval(name)`
            raise "#{name} is not defined" if `#{component} === undefined`
            is_component_class = `#{component}.prototype !== undefined` &&
                                  (`!!#{component}.prototype.isReactComponent` ||
      Severity: Minor
      Found in lib/react/api.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 create_element has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def self.create_element(type, properties = {}, &block)
            params = []
      
            # Component Spec, Normal DOM, String or Native Component
            if @@component_classes[type]
      Severity: Minor
      Found in lib/react/api.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

      Literal #{component} === undefined appeared as a condition.
      Open

            raise "#{name} is not defined" if `#{component} === undefined`
      Severity: Minor
      Found in lib/react/api.rb by rubocop

      This cop checks for literals used as the conditions or as operands in and/or expressions serving as the conditions of if/while/until.

      Example:

      # bad
      
      if 20
        do_something
      end

      Example:

      # bad
      
      if some_var && true
        do_something
      end

      Example:

      # good
      
      if some_var && some_condition
        do_something
      end

      Useless private access modifier.
      Open

          private
      Severity: Minor
      Found in lib/react/api.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.

      Example:

      class Foo
        public # this is redundant (default access is public)
      
        def method
        end
      
        private # this is not redundant (a method is defined)
        def method2
        end
      
        private # this is redundant (no following methods are defined)
      end

      Example:

      class Foo
        # The following is not redundant (conditionally defined methods are
        # considered as always defining a method)
        private
      
        if condition?
          def method
          end
        end
      
        protected # this is not redundant (method is defined)
      
        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
      
        # The following is redundant (methods defined on the class'
        # singleton class are not affected by the public modifier)
        public
      
        def self.method3
        end
      end

      Example:

      # Lint/UselessAccessModifier:
      #   ContextCreatingMethods:
      #     - concerning
      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:

      # Lint/UselessAccessModifier:
      #   MethodCreatingMethods:
      #     - delegate
      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

      There are no issues that match your filters.

      Category
      Status