lib/react_on_rails/helper.rb
File helper.rb
has 368 lines of code (exceeds 250 allowed). Consider refactoring. Open
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"
Method server_render_js
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
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
Method rails_context
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
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,
Method react_component
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
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]
Method server_rendered_react_component
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
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
Method load_pack_for_generated_component
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
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?
- Read upRead up
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
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 " \
- Read upRead up
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"