shakacode/react_on_rails

View on GitHub

Showing 44 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

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

        <div>
          <h3>Hello, {name}!</h3>
          <hr />
          <form>
            <label className={style.bright} htmlFor="name">
    lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx on lines 6..18

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

    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

      <div>
        <h3>
          Hello,
          {name}!
        </h3>
    lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx on lines 9..18

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

    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

    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
                            Severity
                            Category
                            Status
                            Source
                            Language