Showing 44 of 44 total issues
File component_spec.rb
has 582 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'spec_helper'
if opal?
describe React::Component, type: :component do
after(:each) do
Method render
has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring. Open
def self.render(name, *args, &block)
remove_nodes_from_args(args)
@buffer = [] unless @buffer
if block
element = build do
- 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 define_state_methods
has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring. Open
def define_state_methods(this, name, from = nil, &block)
this.define_method("#{name}") do
self.class.deprecation_warning "Direct access to state `#{name}`. Use `state.#{name}` instead." if from.nil? || from == this
State.get_state(from || self, name)
end
- 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 render
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
def render
paths_searched = []
if params.component_name.start_with? "::"
paths_searched << params.component_name.gsub(/^\:\:/,"")
component = params.component_name.gsub(/^\:\:/,"").split("::").inject(Module) { |scope, next_const| scope.const_get(next_const, false) } rescue nil
- 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 define_param
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
def self.define_param(name, param_type)
if param_type == Observable
define_method("#{name}") do
value_for(name)
end
- 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
Class Validator
has 21 methods (exceeds 20 allowed). Consider refactoring. Open
class Validator
attr_accessor :errors
attr_reader :props_wrapper
private :errors, :props_wrapper
Method create_native_react_class
has 54 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.create_native_react_class(type)
raise "Provided class should define `render` method" if !(type.method_defined? :render)
render_fn = (type.method_defined? :_render_wrapper) ? :_render_wrapper : :render
# this was hashing type.to_s, not sure why but .to_s does not work as it Foo::Bar::View.to_s just returns "View"
@@component_classes[type] ||= %x{
Consider simplifying this complex logical expression. Open
if !name && ( # !name means called from outer render so we check that it has rendered correctly
(@buffer.count > 1) || # should only render one element
(@buffer.count == 1 && @buffer.last != result) || # it should return that element
(@buffer.count == 0 && !(result.is_a?(String) || (result.respond_to?(:acts_as_string?) && result.acts_as_string?) || result.is_a?(Element))) #for convience we will also convert the return value to a span if its a string
)
Method const_missing
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def self.const_missing(name)
if renames_and_exclusions.has_key? name
if native_name = renames_and_exclusions[name]
native_name
else
- 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 render
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def render(component_name, props, prerender_options)
if prerender_options.is_a?(Hash)
if v8_runtime? && prerender_options[:context_initializer]
raise PrerenderError.new(component_name, props, "you must use 'therubyracer' with the prerender[:context] option") unless v8_runtime?
else
- 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 render
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.render(name, *args, &block)
remove_nodes_from_args(args)
@buffer = [] unless @buffer
if block
element = build do
Method convert_props
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def self.convert_props(properties)
raise "Component parameters must be a hash. Instead you sent #{properties}" unless properties.is_a? Hash
props = {}
properties.map do |key, value|
if key == "class_name" && value.is_a?(Hash)
- 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 define_param
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.define_param(name, param_type)
if param_type == Observable
define_method("#{name}") do
value_for(name)
end
Method included
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.included(base)
base.include(API)
base.include(Callbacks)
base.class_eval do
class_attribute :initial_state
Method rendering
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def rendering(title, &block)
klass = Class.new do
include React::Component
def self.block
Method define_state_methods
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def define_state_methods(this, name, from = nil, &block)
this.define_method("#{name}") do
self.class.deprecation_warning "Direct access to state `#{name}`. Use `state.#{name}` instead." if from.nil? || from == this
State.get_state(from || self, name)
end
Method set_state_context_to
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def set_state_context_to(observer)
if `typeof window.reactive_ruby_timing !== 'undefined'`
@nesting_level = (@nesting_level || 0) + 1
start_time = Time.now.to_f
observer_name = (observer.class.respond_to?(:name) ? observer.class.name : observer.to_s) rescue "object:#{observer.object_id}"
- 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 remove_nodes_from_args
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def self.remove_nodes_from_args(args)
args[0].each do |key, value|
value.as_node if value.is_a?(Element) rescue nil
end if args[0] && args[0].is_a?(Hash)
end
- 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 render
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def render
React.create_element('div') { params[:foo] ? 'exist' : 'null' }
end
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
describe '.html_tag?' do
it 'is truthy for valid html tags' do
expect(React.html_tag?('a')).to be_truthy
expect(React.html_tag?('div')).to be_truthy
end
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76