Showing 21 of 21 total issues
Method can_use_for_client_side_validation?
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
def can_use_for_client_side_validation?(attr, validator, force)
if validator_turned_off?(attr, validator, force)
result = false
else
# Yeah yeah, #new_record? is not part of ActiveModel :p
- 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 client_side_form_settings
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def client_side_form_settings(object, options, builder)
if options[:validate]
if options[:id]
var_name = options[:id]
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 form_for
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def form_for(record, *args, &block)
raise ArgumentError, "Missing block" unless block_given?
options = args.extract_options!
if options[:validate]
- 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 client_side_validation_hash
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def client_side_validation_hash(force = nil)
_validators.inject({}) do |attr_hash, attr|
unless [nil, :block].include?(attr[0])
validator_hash = attr[1].inject(Hash.new { |h,k| h[k] = []}) do |kind_hash, validator|
- 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 is_unique?
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def self.is_unique?(klass, attribute, value, params)
klass = find_topmost_superclass(klass)
value = type_cast_value(klass, attribute, value)
column = klass.columns_hash[attribute.to_s]
value = column.limit ? value.to_s.mb_chars[0, column.limit] : value.to_s if column.text?
- 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 client_side_hash
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def client_side_hash(model, attribute, force = nil)
options = self.options.dup
hash = { :messages => { :numericality => model.errors.generate_message(attribute, :not_a_number, options) } }
if options[:only_integer]
- 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
module Exclusion
def client_side_hash(model, attribute, force = nil)
if options[:in].respond_to?(:call)
if force
- 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 56.
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
module Inclusion
def client_side_hash(model, attribute, force = nil)
if options[:in].respond_to?(:call)
if force
- 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 56.
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
Method build_validation_options
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def build_validation_options(method, options = {})
if @options[:validate]
index = @default_options[:index].present? ? "[#{@default_options[:index]}]" : ''
name = options[:name] || "#{@object_name}#{index}[#{method}]"
child_index = @options[:child_index] ? "(\\d+|#{Regexp.escape(@options[:child_index].to_s)})" : "\\d+"
- 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 is_unique?
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.is_unique?(klass, attribute, value, params)
klass = find_topmost_superclass(klass)
value = type_cast_value(klass, attribute, value)
column = klass.columns_hash[attribute.to_s]
value = column.limit ? value.to_s.mb_chars[0, column.limit] : value.to_s if column.text?
Function exports
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
shell: {
precompile: {
Method client_side_hash
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def client_side_hash(model, attribute, force = nil)
options = self.options.dup
hash = { :messages => {} }
hash[:js_tokenizer] = options[:js_tokenizer] if options[:js_tokenizer]
hash[:allow_blank] = true if options[:allow_blank]
- 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 form_for
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def form_for(record, *args, &block)
raise ArgumentError, "Missing block" unless block_given?
options = args.extract_options!
if options[:validate]
Method included
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.included(base)
(base.field_helpers.map(&:to_s) - %w(apply_form_for_options! label check_box radio_button fields_for hidden_field)).each do |selector|
base.class_eval <<-RUBY_EVAL
def #{selector}_with_rails4_client_side_validations(method, options = {})
build_validation_options(method, options)
Method grouped_collection_select_with_rails4_client_side_validations
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
def grouped_collection_select_with_rails4_client_side_validations(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
Method client_side_hash
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def client_side_hash(model, attribute, force = nil)
options = self.options.dup
if options[:with].respond_to?(:call)
if force
options[:with] = options[:with].call(model)
- 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 collection_select_with_rails4_client_side_validations
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def collection_select_with_rails4_client_side_validations(method, collection, value_method, text_method, options = {}, html_options = {})
Method client_side_hash
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def client_side_hash(model, attribute, force = nil)
hash = {}
hash[:message] = model.errors.generate_message(attribute, message_type, options.except(:scope))
hash[:case_sensitive] = options[:case_sensitive]
hash[:id] = model.id unless model.new_record?
- 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 client_side_hash
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def client_side_hash(model, attribute, force = nil)
if options[:in].respond_to?(:call)
if force
options = self.options.dup
options[:in] = options[:in].call(model)
- 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 construct_validators
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def construct_validators
@validators.inject({}) do |validator_hash, object_opts|
option_hash = object_opts[1].inject({}) do |option_hash, attr|
option_hash.merge!(attr[0] => attr[1][:options])
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"