shakacode/react_on_rails

View on GitHub

Showing 36 of 44 total issues

File helper.rb has 375 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 5 hrs to fix

    Class PacksGenerator has 25 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class PacksGenerator
        CONTAINS_CLIENT_OR_SERVER_REGEX = /\.(server|client)($|\.)/
        MINIMUM_SHAKAPACKER_VERSION = [6, 5, 1].freeze
    
        def self.instance
    Severity: Minor
    Found in lib/react_on_rails/packs_generator.rb - About 2 hrs to fix

      ReactOnRails has 23 functions (exceeds 20 allowed). Consider refactoring.
      Open

      ctx.ReactOnRails = {
        options: {},
        /**
         * Main entry point to using the react-on-rails npm package. This is how Rails will be able to
         * find you components for rendering.
      Severity: Minor
      Found in node_package/src/ReactOnRails.ts - About 2 hrs to fix

        File clientStartup.ts has 263 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import ReactDOM from 'react-dom';
        import type { ReactElement } from 'react';
        import type {
          RailsContext,
          ReactOnRails as ReactOnRailsType,
        Severity: Minor
        Found in node_package/src/clientStartup.ts - About 2 hrs to fix

          Class RenderOptions has 21 methods (exceeds 20 allowed). Consider refactoring.
          Open

              class RenderOptions
                include Utils::Required
          
                attr_accessor :request_digest
          
          
          Severity: Minor
          Found in lib/react_on_rails/react_component/render_options.rb - About 2 hrs to fix

            Function createReactOutput has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
            Open

            export default function createReactOutput({
              componentObj,
              props,
              railsContext,
              domNodeId,
            Severity: Minor
            Found in node_package/src/createReactOutput.ts - 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 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

              Function consoleReplay has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
              Open

              export function consoleReplay(customConsoleHistory: typeof console['history'] | undefined = undefined): string {
                // console.history is a global polyfill used in server rendering.
                const consoleHistory = customConsoleHistory ?? console.history;
              
                if (!(Array.isArray(consoleHistory))) {
              Severity: Minor
              Found in node_package/src/buildConsoleReplay.ts - 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 ensure_assets_compiled has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
              Open

                  def self.ensure_assets_compiled(webpack_assets_status_checker: nil,
                                                  webpack_assets_compiler: nil,
                                                  source_path: nil,
                                                  generated_assets_full_path: nil,
                                                  webpack_generated_files: nil)
              Severity: Minor
              Found in lib/react_on_rails/test_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 exec_server_render_js has 38 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                      def exec_server_render_js(js_code, render_options, js_evaluator = nil)
                        js_evaluator ||= self
                        if render_options.trace
                          @file_index ||= 1
                          trace_js_code_used("Evaluating code to server render.", js_code,

                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

                  Function render has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function render(el: Element, context: Context, railsContext: RailsContext): void {
                    // This must match lib/react_on_rails/helper.rb
                    const name = el.getAttribute('data-component-name') || '';
                    const domNodeId = domNodeIdForEl(el);
                    const props = (el.textContent !== null) ? JSON.parse(el.textContent) : {};
                  Severity: Minor
                  Found in node_package/src/clientStartup.ts - About 1 hr to fix

                    Function render has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                    Open

                    function render(el: Element, context: Context, railsContext: RailsContext): void {
                      // This must match lib/react_on_rails/helper.rb
                      const name = el.getAttribute('data-component-name') || '';
                      const domNodeId = domNodeIdForEl(el);
                      const props = (el.textContent !== null) ? JSON.parse(el.textContent) : {};
                    Severity: Minor
                    Found in node_package/src/clientStartup.ts - 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 33 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        def initialize(node_modules_location: nil, server_bundle_js_file: nil, prerender: nil,
                                       replay_console: nil, make_generated_server_bundle_the_entrypoint: nil,
                                       trace: nil, development_mode: nil,
                                       logging_on_server: nil, server_renderer_pool_size: nil,
                                       server_renderer_timeout: nil, raise_on_prerender_error: true,
                    Severity: Minor
                    Found in lib/react_on_rails/configuration.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 ensure_assets_compiled has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            def self.ensure_assets_compiled(webpack_assets_status_checker: nil,
                                                            webpack_assets_compiler: nil,
                                                            source_path: nil,
                                                            generated_assets_full_path: nil,
                                                            webpack_generated_files: nil)
                        Severity: Minor
                        Found in lib/react_on_rails/test_helper.rb - About 1 hr to fix

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

                                  def exec_server_render_js(js_code, render_options, js_evaluator = nil)
                                    js_evaluator ||= self
                                    if render_options.trace
                                      @file_index ||= 1
                                      trace_js_code_used("Evaluating code to server render.", js_code,

                          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 configuration has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            def self.configuration
                              @configuration ||= Configuration.new(
                                node_modules_location: nil,
                                generated_assets_dirs: nil,
                                # generated_assets_dirs is deprecated
                          Severity: Minor
                          Found in lib/react_on_rails/configuration.rb - About 1 hr to fix

                            Method add_js_dependencies has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                  def add_js_dependencies
                                    major_minor_patch_only = /\A\d+\.\d+\.\d+\z/
                                    if ReactOnRails::VERSION.match?(major_minor_patch_only)
                                      package_json.manager.add(["react-on-rails@#{ReactOnRails::VERSION}"])
                                    else
                            Severity: Minor
                            Found in lib/generators/react_on_rails/base_generator.rb - About 1 hr to fix

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

                                  def check_autobundling_requirements
                                    raise_missing_components_subdirectory if auto_load_bundle && !components_subdirectory.present?
                                    return unless components_subdirectory.present?
                              
                                    ReactOnRails::PackerUtils.raise_shakapacker_not_installed unless ReactOnRails::PackerUtils.using_packer?
                              Severity: Minor
                              Found in lib/react_on_rails/configuration.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

                              Severity
                              Category
                              Status
                              Source
                              Language