zetachang/react.rb

View on GitHub

Showing 44 of 44 total issues

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

  describe '.html_attr?' do
    it 'is truthy for valid html attributes' do
      expect(React.html_attr?('id')).to be_truthy
      expect(React.html_attr?('data')).to be_truthy
    end
Severity: Minor
Found in spec/react/top_level_component_spec.rb and 1 other location - About 55 mins to fix
spec/react/top_level_component_spec.rb on lines 64..76

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

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 update_react_js_state has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def update_react_js_state(object, name, value)
      if object
        set_state({"***_state_updated_at-***" => Time.now.to_f,
                   "#{object.class.to_s+'.' unless object == self}#{name}" => value})
      else
Severity: Minor
Found in lib/react/component.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 expect_component_to_eventually has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def expect_component_to_eventually(component_class, opts = {}, &block)
      # Calls block after each update of a component until it returns true.
      # When it does set the expectation to true.  Uses the after_update
      # callback of the component_class, then instantiates an element of that
      # class The call back is only called on updates, so the call back is
Severity: Minor
Found in spec/support/react/spec_helpers.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 should_component_update? has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def should_component_update?(next_props, next_state)
      State.set_state_context_to(self) do
        if self.respond_to?(:needs_update?)
          !!self.needs_update?(next_props, next_state)
        elsif false # switch to true to force updates per standard react
Severity: Minor
Found in lib/react/component.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 log has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def self.log(message, message_type = :info)
      message = [message] unless message.is_a? Array
      if message_type == :info
        if on_opal_server?
          style = 'background: #00FFFF; color: red'
Severity: Minor
Found in lib/reactive-ruby/isomorphic_helpers.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 method_missing has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

          def method_missing(n, *args, &block)
            name = n
            if name =~ /_as_node$/
              node_only = true
              name = name.gsub(/_as_node$/, "")
Severity: Minor
Found in lib/react/component.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

Consider simplifying this complex logical expression.
Open

          if args.count > 0
            yield name, State.get_state(from || self, name), args[0] if block && block.arity > 0
            current_value = State.get_state(from || self, name)
            State.set_state(from || self, name, args[0])
            current_value
Severity: Major
Found in lib/react/component/class_methods.rb - About 40 mins to fix

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

              def self._react_param_conversion(json, validate_only)
                new(json[:bazwoggle]) if json[:bazwoggle]
              end
    Severity: Minor
    Found in spec/react/param_declaration_spec.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 method_missing has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def method_missing(n, *args, &block)
          # TODO deprecate and remove - done so that params shadow tags, no longer
          # needed
          return props[n] if props.key?(n)
          name = n
    Severity: Minor
    Found in lib/react/component.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 _react_param_conversion has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

              def self._react_param_conversion(json, validate_only)
                new(JSON.from_object(json[0])[:bazwoggle]) if JSON.from_object(json[0])[:bazwoggle]
              end
    Severity: Minor
    Found in spec/react/param_declaration_spec.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 _render_wrapper has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def _render_wrapper
          State.set_state_context_to(self) do
            React::RenderingContext.render(nil) {render || ""}.tap do |element|
              if element.respond_to?(:waiting_on_resources)
                @waiting_on_resources = element.waiting_on_resources
    Severity: Minor
    Found in lib/react/component.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 should_immediately_generate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

                  def self.should_immediately_generate(opts={}, &block)
                    sself = self
                    @self.it(@title, opts) do
                      element = build_element sself, {}
                      context = block.arity > 0 ? self : element
    Severity: Minor
    Found in spec/spec_helper.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 render has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def render
            div do
              span { params.string } if params.string
              'lorem'
            end
    Severity: Minor
    Found in spec/react/test/matchers/render_html_matcher_spec.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 method_missing has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.method_missing(n, *args, &block)
          name = n
          if name =~ /_as_node$/
            node_only = true
            name = name.gsub(/_as_node$/, "")
    Severity: Minor
    Found in lib/react/native_library.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 define_state has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def define_state(*states, &block)
            default_initial_value = (block && block.arity == 0) ? yield : nil
            states_hash = (states.last.is_a?(Hash)) ? states.pop : {}
            states.each { |name| states_hash[name] = default_initial_value }
            (self.initial_state ||= {}).merge! states_hash
    Severity: Minor
    Found in lib/react/component/class_methods.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 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

    Method _react_param_conversion has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

            def self._react_param_conversion(json, validate_only)
              new(json[:bazwoggle]) if json[:bazwoggle]
            end
    Severity: Minor
    Found in spec/react/param_declaration_spec.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

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

        it 'invokes `after_mount` registered methods when `componentDidMount()`' do
          Foo.class_eval do
            after_mount :bar3, :bar4
            def bar3; end
            def bar4; end
    Severity: Minor
    Found in spec/react/component_spec.rb and 1 other location - About 25 mins to fix
    spec/react/component_spec.rb on lines 44..54

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

    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

    Identical blocks of code found in 3 locations. Consider refactoring.
    Open

        before do
          stub_const 'Greeter', Class.new
          Greeter.class_eval do
            include React::Component
    
    
    Severity: Minor
    Found in spec/react/test/session_spec.rb and 2 other locations - About 25 mins to fix
    spec/react/test/rspec_spec.rb on lines 5..15
    spec/react/test/rspec_spec.rb on lines 43..53

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

    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

        it 'invokes `before_mount` registered methods when `componentWillMount()`' do
          Foo.class_eval do
            before_mount :bar, :bar2
            def bar; end
            def bar2; end
    Severity: Minor
    Found in spec/react/component_spec.rb and 1 other location - About 25 mins to fix
    spec/react/component_spec.rb on lines 57..67

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

    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

    Severity
    Category
    Status
    Source
    Language