shakacode/react_on_rails

View on GitHub
lib/react_on_rails/helper.rb

Summary

Maintainability
C
1 day
Test Coverage

File helper.rb has 368 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require "react_on_rails/prerender_error"
require "addressable/uri"
require "react_on_rails/utils"
require "react_on_rails/json_output"
require "active_support/concern"
Severity: Minor
Found in lib/react_on_rails/helper.rb - About 4 hrs to fix

    Method server_render_js has 45 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def server_render_js(js_expression, options = {})
          render_options = ReactOnRails::ReactComponent::RenderOptions
                           .new(react_component_name: "generic-js", options: options)
    
          js_code = <<-JS.strip_heredoc
    Severity: Minor
    Found in lib/react_on_rails/helper.rb - About 1 hr to fix

      Method rails_context has 37 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def rails_context(server_side: true)
            # ALERT: Keep in sync with node_package/src/types/index.ts for the properties of RailsContext
            @rails_context ||= begin
              result = {
                railsEnv: Rails.env,
      Severity: Minor
      Found in lib/react_on_rails/helper.rb - About 1 hr to fix

        Method react_component has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def react_component(component_name, options = {})
              internal_result = internal_react_component(component_name, options)
              server_rendered_html = internal_result[:result]["html"]
              console_script = internal_result[:result]["consoleReplayScript"]
              render_options = internal_result[:render_options]
        Severity: Minor
        Found in lib/react_on_rails/helper.rb - About 1 hr to fix

          Method server_rendered_react_component has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def server_rendered_react_component(render_options)
                return { "html" => "", "consoleReplayScript" => "" } unless render_options.prerender
          
                react_component_name = render_options.react_component_name
                props = render_options.props
          Severity: Minor
          Found in lib/react_on_rails/helper.rb - About 1 hr to fix

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

                def load_pack_for_generated_component(react_component_name, render_options)
                  return unless render_options.auto_load_bundle
            
                  ReactOnRails::WebpackerUtils.raise_nested_entries_disabled unless ReactOnRails::WebpackerUtils.nested_entries?
                  if Rails.env.development?
            Severity: Minor
            Found in lib/react_on_rails/helper.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 json_safe_and_pretty has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def json_safe_and_pretty(hash_or_string)
                  return "{}" if hash_or_string.nil?
            
                  unless hash_or_string.is_a?(String) || hash_or_string.is_a?(Hash)
                    raise ReactOnRails::Error, "#{__method__} only accepts String or Hash as argument " \
            Severity: Minor
            Found in lib/react_on_rails/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

            There are no issues that match your filters.

            Category
            Status