Unescaped parameter value rendered inline Open
render text: js, layout: false
- Read upRead up
- Exclude checks
Class has too many lines. [122/100] Open
class ExtendedFieldsController < ApplicationController
helper ExtendedFieldsHelper
# everything else is handled by application.rb
before_filter :login_required, only: %i[list index add_field_to_multiples fetch_subchoices fetch_topics_from_topic_type validate_topic_type_entry]
- Read upRead up
- Exclude checks
This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Assignment Branch Condition size for fetch_topics_from_topic_type is too high. [49.28/15] Open
def fetch_topics_from_topic_type
begin
extended_field = ExtendedField.find(params[:extended_field_id])
parent_topic_type = extended_field.topic_type.to_i
extended_field_key = @template.send(:id_for_extended_field, extended_field).gsub('_extended_content_values_', '').gsub(/_$/, '')
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric
Assignment Branch Condition size for fetch_subchoices is too high. [46.16/15] Open
def fetch_subchoices
extended_field = ExtendedField.find(params[:options][:extended_field_id])
# Find the current choice
current_choice = extended_field.choices.matching(params[:label], params[:value])
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric
Method has too many lines. [31/10] Open
def fetch_topics_from_topic_type
begin
extended_field = ExtendedField.find(params[:extended_field_id])
parent_topic_type = extended_field.topic_type.to_i
extended_field_key = @template.send(:id_for_extended_field, extended_field).gsub('_extended_content_values_', '').gsub(/_$/, '')
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method has too many lines. [22/10] Open
def fetch_subchoices
extended_field = ExtendedField.find(params[:options][:extended_field_id])
# Find the current choice
current_choice = extended_field.choices.matching(params[:label], params[:value])
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Assignment Branch Condition size for validate_topic_type_entry is too high. [27.46/15] Open
def validate_topic_type_entry
extended_field = ExtendedField.find(params[:extended_field_id])
parent_topic_type = TopicType.find(extended_field.topic_type.to_i)
value, field_id = params[:value], params[:field_id]
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric
Method has too many lines. [20/10] Open
def validate_topic_type_entry
extended_field = ExtendedField.find(params[:extended_field_id])
parent_topic_type = TopicType.find(extended_field.topic_type.to_i)
value, field_id = params[:value], params[:field_id]
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method fetch_topics_from_topic_type
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def fetch_topics_from_topic_type
begin
extended_field = ExtendedField.find(params[:extended_field_id])
parent_topic_type = extended_field.topic_type.to_i
extended_field_key = @template.send(:id_for_extended_field, extended_field).gsub('_extended_content_values_', '').gsub(/_$/, '')
Method fetch_subchoices
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def fetch_subchoices
extended_field = ExtendedField.find(params[:options][:extended_field_id])
# Find the current choice
current_choice = extended_field.choices.matching(params[:label], params[:value])
- 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 validate_topic_type_entry
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def validate_topic_type_entry
extended_field = ExtendedField.find(params[:extended_field_id])
parent_topic_type = TopicType.find(extended_field.topic_type.to_i)
value, field_id = params[:value], params[:field_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
Avoid using rescue
in its modifier form. Open
topic_type_ids = TopicType.where(id: parent_topic_type).full_set.collect { |a| a.id } rescue []
- Read upRead up
- Exclude checks
This cop checks for uses of rescue in its modifier form.
Example:
# bad
some_method rescue handle_error
# good
begin
some_method
rescue
handle_error
end
Pass &:id
as an argument to collect
instead of a block. Open
valid_topic_type_ids = parent_topic_type.full_set.collect { |topic_type| topic_type.id }
- Read upRead up
- Exclude checks
Use symbols as procs when possible.
Example:
# bad
something.map { |s| s.upcase }
# good
something.map(&:upcase)
Pass &:id
as an argument to collect
instead of a block. Open
topic_type_ids = TopicType.where(id: parent_topic_type).full_set.collect { |a| a.id } rescue []
- Read upRead up
- Exclude checks
Use symbols as procs when possible.
Example:
# bad
something.map { |s| s.upcase }
# good
something.map(&:upcase)
Do not use parallel assignment. Open
value, field_id = params[:value], params[:field_id]
- Read upRead up
- Exclude checks
Checks for simple usages of parallel assignment. This will only complain when the number of variables being assigned matched the number of assigning variables.
Example:
# bad
a, b, c = 1, 2, 3
a, b, c = [1, 2, 3]
# good
one, two = *foo
a, b = foo()
a, b = b, a
a = 1
b = 2
c = 3
Redundant curly braces around a hash parameter. Open
@template.text_field_tag(input_name, value, { id: 'record_base_url' })
- Read upRead up
- Exclude checks
This cop checks for braces around the last parameter in a method call
if the last parameter is a hash.
It supports braces
, no_braces
and context_dependent
styles.
Example: EnforcedStyle: braces
# The `braces` style enforces braces around all method
# parameters that are hashes.
# bad
some_method(x, y, a: 1, b: 2)
# good
some_method(x, y, {a: 1, b: 2})
Example: EnforcedStyle: no_braces (default)
# The `no_braces` style checks that the last parameter doesn't
# have braces around it.
# bad
some_method(x, y, {a: 1, b: 2})
# good
some_method(x, y, a: 1, b: 2)
Example: EnforcedStyle: context_dependent
# The `context_dependent` style checks that the last parameter
# doesn't have braces around it, but requires braces if the
# second to last parameter is also a hash literal.
# bad
some_method(x, y, {a: 1, b: 2})
some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)
# good
some_method(x, y, a: 1, b: 2)
some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})
Avoid rescuing without specifying an error class. Open
rescue
- Read upRead up
- Exclude checks
This cop checks for rescuing StandardError
. There are two supported
styles implicit
and explicit
. This cop will not register an offense
if any error other than StandardError
is specified.
Example: EnforcedStyle: implicit
# `implicit` will enforce using `rescue` instead of
# `rescue StandardError`.
# bad
begin
foo
rescue StandardError
bar
end
# good
begin
foo
rescue
bar
end
# good
begin
foo
rescue OtherError
bar
end
# good
begin
foo
rescue StandardError, SecurityError
bar
end
Example: EnforcedStyle: explicit (default)
# `explicit` will enforce using `rescue StandardError`
# instead of `rescue`.
# bad
begin
foo
rescue
bar
end
# good
begin
foo
rescue StandardError
bar
end
# good
begin
foo
rescue OtherError
bar
end
# good
begin
foo
rescue StandardError, SecurityError
bar
end