Module has too many lines. [220/100] Open
module OaiDcHelpers
unless included_modules.include? OaiDcHelpers
def self.included(klass)
klass.send :include, XmlHelpers
end
- Read upRead up
- Exclude checks
This cop checks if the length a module exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method has too many lines. [36/10] Open
def oai_dc_xml_dc_identifier(xml, passed_request = nil)
if !passed_request.nil?
host = passed_request[:host]
else
host = simulated_request[:host]
- 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 oai_dc_xml_oai_datestamp is too high. [40.12/15] Open
def oai_dc_xml_oai_datestamp(xml)
most_recent_updated_at = updated_at
if is_a?(Topic)
# topics can be on either side of the content_item_relation join model
- 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 oai_dc_xml_dc_identifier is too high. [30.35/15] Open
def oai_dc_xml_dc_identifier(xml, passed_request = nil)
if !passed_request.nil?
host = passed_request[:host]
else
host = simulated_request[:host]
- 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 oai_dc_xml_dc_relations_and_subjects is too high. [28.35/15] Open
def oai_dc_xml_dc_relations_and_subjects(xml, passed_request = {})
# in theory, direct comments might be added in as relations here
# but since there url is the thing they are commenting on
# then it's overkill
# however, if we are in the comment record,
- 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. [21/10] Open
def oai_dc_xml_oai_datestamp(xml)
most_recent_updated_at = updated_at
if is_a?(Topic)
# topics can be on either side of the content_item_relation join model
- 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. [19/10] Open
def oai_dc_xml_dc_rights(xml)
terms_and_conditions_topic = Basket.about_basket.topics.find(
:first,
conditions: "UPPER(title) like '%TERMS AND CONDITIONS'"
)
- 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. [18/10] Open
def oai_dc_xml_dc_relations_and_subjects(xml, passed_request = {})
# in theory, direct comments might be added in as relations here
# but since there url is the thing they are commenting on
# then it's overkill
# however, if we are in the comment record,
- 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 oai_dc_xml_oai_datestamp
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def oai_dc_xml_oai_datestamp(xml)
most_recent_updated_at = updated_at
if is_a?(Topic)
# topics can be on either side of the content_item_relation join 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 has too many lines. [15/10] Open
def oai_dc_xml_dc_format(xml)
# item's content type is the default
format = ''
html_classes = %w(Topic Comment WebLink)
case self.class.name
- 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 oai_dc_xml_dc_relations_and_subjects
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def oai_dc_xml_dc_relations_and_subjects(xml, passed_request = {})
# in theory, direct comments might be added in as relations here
# but since there url is the thing they are commenting on
# then it's overkill
# however, if we are in the comment 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
Cyclomatic complexity for oai_dc_xml_oai_datestamp is too high. [9/6] Open
def oai_dc_xml_oai_datestamp(xml)
most_recent_updated_at = updated_at
if is_a?(Topic)
# topics can be on either side of the content_item_relation join model
- Read upRead up
- Exclude checks
This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.
An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.
Perceived complexity for oai_dc_xml_oai_datestamp is too high. [10/7] Open
def oai_dc_xml_oai_datestamp(xml)
most_recent_updated_at = updated_at
if is_a?(Topic)
# topics can be on either side of the content_item_relation join model
- Read upRead up
- Exclude checks
This cop tries to produce a complexity score that's a measure of the
complexity the reader experiences when looking at a method. For that
reason it considers when
nodes as something that doesn't add as much
complexity as an if
or a &&
. Except if it's one of those special
case
/when
constructs where there's no expression after case
. Then
the cop treats it as an if
/elsif
/elsif
... and lets all the when
nodes count. In contrast to the CyclomaticComplexity cop, this cop
considers else
nodes as adding complexity.
Example:
def my_method # 1
if cond # 1
case var # 2 (0.8 + 4 * 0.2, rounded)
when 1 then func_one
when 2 then func_two
when 3 then func_three
when 4..10 then func_other
end
else # 1
do_something until a && b # 2
end # ===
end # 7 complexity points
Method oai_dc_xml_dc_identifier
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
def oai_dc_xml_dc_identifier(xml, passed_request = nil)
if !passed_request.nil?
host = passed_request[:host]
else
host = simulated_request[:host]
Method oai_dc_xml_dc_description
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def oai_dc_xml_dc_description(xml, passed_description = nil, options = {})
unless passed_description.blank?
# strip out embedded html
# it only adds clutter at this point and fails oai_dc validation, too
# also pulling out some entities that sneak in
- 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 oai_dc_xml_dc_identifier
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def oai_dc_xml_dc_identifier(xml, passed_request = nil)
if !passed_request.nil?
host = passed_request[:host]
else
host = simulated_request[:host]
- 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 oai_dc_xml_dc_format
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def oai_dc_xml_dc_format(xml)
# item's content type is the default
format = ''
html_classes = %w(Topic Comment WebLink)
case self.class.name
- 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 oai_dc_xml_dc_creators_and_date
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def oai_dc_xml_dc_creators_and_date(xml)
# some sites, such as those that have lots of imported archival material,
# will find that the date created is not useful in their search record
# and will want to handle date data explicitly in their extended fields
# only turn it on if specified in the system setting
- 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 more than 3 levels of block nesting. Open
if last_relation.updated_at > most_recent_updated_at
most_recent_updated_at = last_relation.updated_at
end
- Read upRead up
- Exclude checks
This cop checks for excessive nesting of conditional and looping constructs.
You can configure if blocks are considered using the CountBlocks
option. When set to false
(the default) blocks are not counted
towards the nesting level. Set to true
to count blocks as well.
The maximum level of nesting allowed is configurable.
Avoid more than 3 levels of block nesting. Open
xml.send('dc:subject') do
xml.cdata related.title
end unless [SystemSetting.blank_title, SystemSetting.no_public_version_title].include?(related.title)
- Read upRead up
- Exclude checks
This cop checks for excessive nesting of conditional and looping constructs.
You can configure if blocks are considered using the CountBlocks
option. When set to false
(the default) blocks are not counted
towards the nesting level. Set to true
to count blocks as well.
The maximum level of nesting allowed is configurable.
TODO found Open
# TODO: this attribute isn't coming over even though it's in the select
- Exclude checks
TODO found Open
# TODO: evaluate whether we can simply go with SystemSetting.full_site_url
- Exclude checks
include
is used at the top level. Use inside class
or module
. Open
include ActionView::Helpers::SanitizeHelper
- Read upRead up
- Exclude checks
This cop checks that include
, extend
and prepend
exists at
the top level.
Using these at the top level affects the behavior of Object
.
There will not be using include
, extend
and prepend
at
the top level. Let's use it inside class
or module
.
Example:
# bad
include M
class C
end
# bad
extend M
class C
end
# bad
prepend M
class C
end
# good
class C
include M
end
# good
class C
extend M
end
# good
class C
prepend M
end
Favor a normal unless-statement over a modifier clause in a multiline statement. Open
xml.send('dc:subject') do
xml.cdata commented_on_item.title
end unless [SystemSetting.blank_title, SystemSetting.no_public_version_title].include?(commented_on_item.title)
- Read upRead up
- Exclude checks
Checks for uses of if/unless modifiers with multiple-lines bodies.
Example:
# bad
{
result: 'this should not happen'
} unless cond
# good
{ result: 'ok' } if cond
Convert if
nested inside else
to elsif
. Open
if respond_to?(:private) && private?
- Read upRead up
- Exclude checks
If the else
branch of a conditional consists solely of an if
node,
it can be combined with the else
to become an elsif
.
This helps to keep the nesting level from getting too deep.
Example:
# bad
if condition_a
action_a
else
if condition_b
action_b
else
action_c
end
end
# good
if condition_a
action_a
elsif condition_b
action_b
else
action_c
end
Favor a normal unless-statement over a modifier clause in a multiline statement. Open
xml.send('dc:subject') do
xml.cdata related.title
end unless [SystemSetting.blank_title, SystemSetting.no_public_version_title].include?(related.title)
- Read upRead up
- Exclude checks
Checks for uses of if/unless modifiers with multiple-lines bodies.
Example:
# bad
{
result: 'this should not happen'
} unless cond
# good
{ result: 'ok' } if cond
Use the return of the conditional for variable assignment and comparison. Open
if !passed_request.nil?
request_uri = passed_request[:original_url]
else
request_uri = simulated_request[:original_url]
end
- Exclude checks
Use all_relations.size.positive?
instead of all_relations.size > 0
. Open
if all_relations.size > 0
- Read upRead up
- Exclude checks
This cop checks for usage of comparison operators (==
,
>
, <
) to test numbers as zero, positive, or negative.
These can be replaced by their respective predicate methods.
The cop can also be configured to do the reverse.
The cop disregards #nonzero?
as it its value is truthy or falsey,
but not true
and false
, and thus not always interchangeable with
!= 0
.
The cop ignores comparisons to global variables, since they are often
populated with objects which can be compared with integers, but are
not themselves Interger
polymorphic.
Example: EnforcedStyle: predicate (default)
# bad
foo == 0
0 > foo
bar.baz > 0
# good
foo.zero?
foo.negative?
bar.baz.positive?
Example: EnforcedStyle: comparison
# bad
foo.zero?
foo.negative?
bar.baz.positive?
# good
foo == 0
0 > foo
bar.baz > 0
include
is used at the top level. Use inside class
or module
. Open
include Utf8UrlFor
- Read upRead up
- Exclude checks
This cop checks that include
, extend
and prepend
exists at
the top level.
Using these at the top level affects the behavior of Object
.
There will not be using include
, extend
and prepend
at
the top level. Let's use it inside class
or module
.
Example:
# bad
include M
class C
end
# bad
extend M
class C
end
# bad
prepend M
class C
end
# good
class C
include M
end
# good
class C
extend M
end
# good
class C
prepend M
end
Favor unless
over if
for negative conditions. Open
if !original_file.nil?
format = original_file.content_type
end
- Read upRead up
- Exclude checks
Checks for uses of if with a negated condition. Only ifs without else are considered. There are three different styles:
- both
- prefix
- postfix
Example: EnforcedStyle: both (default)
# enforces `unless` for `prefix` and `postfix` conditionals
# bad
if !foo
bar
end
# good
unless foo
bar
end
# bad
bar if !foo
# good
bar unless foo
Example: EnforcedStyle: prefix
# enforces `unless` for just `prefix` conditionals
# bad
if !foo
bar
end
# good
unless foo
bar
end
# good
bar if !foo
Example: EnforcedStyle: postfix
# enforces `unless` for just `postfix` conditionals
# bad
bar if !foo
# good
bar unless foo
# good
if !foo
bar
end
Use the return of the conditional for variable assignment and comparison. Open
if !passed_request.nil?
host = passed_request[:host]
else
host = simulated_request[:host]
end
- Exclude checks
Use content_item_relations.count.positive?
instead of content_item_relations.count > 0
. Open
if content_item_relations.count > 0
- Read upRead up
- Exclude checks
This cop checks for usage of comparison operators (==
,
>
, <
) to test numbers as zero, positive, or negative.
These can be replaced by their respective predicate methods.
The cop can also be configured to do the reverse.
The cop disregards #nonzero?
as it its value is truthy or falsey,
but not true
and false
, and thus not always interchangeable with
!= 0
.
The cop ignores comparisons to global variables, since they are often
populated with objects which can be compared with integers, but are
not themselves Interger
polymorphic.
Example: EnforcedStyle: predicate (default)
# bad
foo == 0
0 > foo
bar.baz > 0
# good
foo.zero?
foo.negative?
bar.baz.positive?
Example: EnforcedStyle: comparison
# bad
foo.zero?
foo.negative?
bar.baz.positive?
# good
foo == 0
0 > foo
bar.baz > 0
%w
-literals should be delimited by [
and ]
. Open
html_classes = %w(Topic Comment WebLink)
- Read upRead up
- Exclude checks
This cop enforces the consistent usage of %
-literal delimiters.
Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.
Example:
# Style/PercentLiteralDelimiters:
# PreferredDelimiters:
# default: '[]'
# '%i': '()'
# good
%w[alpha beta] + %i(gamma delta)
# bad
%W(alpha #{beta})
# bad
%I(alpha beta)
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if !format.blank?
- Read upRead up
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression
Example:
# bad
def test
if something
work
end
end
# good
def test
return unless something
work
end
# also good
def test
work if something
end
# bad
if something
raise 'exception'
else
ok
end
# good
raise 'exception' if something
ok
Favor unless
over if
for negative conditions. Open
if !format.blank?
xml.send('dc:format', format)
end
- Read upRead up
- Exclude checks
Checks for uses of if with a negated condition. Only ifs without else are considered. There are three different styles:
- both
- prefix
- postfix
Example: EnforcedStyle: both (default)
# enforces `unless` for `prefix` and `postfix` conditionals
# bad
if !foo
bar
end
# good
unless foo
bar
end
# bad
bar if !foo
# good
bar unless foo
Example: EnforcedStyle: prefix
# enforces `unless` for just `prefix` conditionals
# bad
if !foo
bar
end
# good
unless foo
bar
end
# good
bar if !foo
Example: EnforcedStyle: postfix
# enforces `unless` for just `postfix` conditionals
# bad
bar if !foo
# good
bar unless foo
# good
if !foo
bar
end
include
is used at the top level. Use inside class
or module
. Open
include KeteUrlFor
- Read upRead up
- Exclude checks
This cop checks that include
, extend
and prepend
exists at
the top level.
Using these at the top level affects the behavior of Object
.
There will not be using include
, extend
and prepend
at
the top level. Let's use it inside class
or module
.
Example:
# bad
include M
class C
end
# bad
extend M
class C
end
# bad
prepend M
class C
end
# good
class C
include M
end
# good
class C
extend M
end
# good
class C
prepend M
end
Favor modifier if
usage when having a single-line body. Another good alternative is the usage of control flow &&
/||
. Open
if !format.blank?
- Read upRead up
- Exclude checks
Checks for if and unless statements that would fit on one line
if written as a modifier if/unless. The maximum line length is
configured in the Metrics/LineLength
cop.
Example:
# bad
if condition
do_stuff(bar)
end
unless qux.empty?
Foo.do_something
end
# good
do_stuff(bar) if condition
Foo.do_something unless qux.empty?
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if ::Import::VALID_ARCHIVE_CLASSES.include?(self.class.name)
- Read upRead up
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression
Example:
# bad
def test
if something
work
end
end
# good
def test
return unless something
work
end
# also good
def test
work if something
end
# bad
if something
raise 'exception'
else
ok
end
# good
raise 'exception' if something
ok
Use the return of the conditional for variable assignment and comparison. Open
if !passed_request.nil?
host = passed_request[:host]
else
host = simulated_request[:host]
end
- Exclude checks
Do not use unless
with else
. Rewrite these with the positive case first. Open
unless passed_description.blank?
# strip out embedded html
# it only adds clutter at this point and fails oai_dc validation, too
# also pulling out some entities that sneak in
xml.send('dc:description', options) do
- Read upRead up
- Exclude checks
This cop looks for unless expressions with else clauses.
Example:
# bad
unless foo_bar.nil?
# do something...
else
# do a different thing...
end
# good
if foo_bar.present?
# do something...
else
# do a different thing...
end
Favor modifier if
usage when having a single-line body. Another good alternative is the usage of control flow &&
/||
. Open
if !original_file.nil?
- Read upRead up
- Exclude checks
Checks for if and unless statements that would fit on one line
if written as a modifier if/unless. The maximum line length is
configured in the Metrics/LineLength
cop.
Example:
# bad
if condition
do_stuff(bar)
end
unless qux.empty?
Foo.do_something
end
# good
do_stuff(bar) if condition
Foo.do_something unless qux.empty?
Use child_content_item_relations.count.positive?
instead of child_content_item_relations.count > 0
. Open
if child_content_item_relations.count > 0
- Read upRead up
- Exclude checks
This cop checks for usage of comparison operators (==
,
>
, <
) to test numbers as zero, positive, or negative.
These can be replaced by their respective predicate methods.
The cop can also be configured to do the reverse.
The cop disregards #nonzero?
as it its value is truthy or falsey,
but not true
and false
, and thus not always interchangeable with
!= 0
.
The cop ignores comparisons to global variables, since they are often
populated with objects which can be compared with integers, but are
not themselves Interger
polymorphic.
Example: EnforcedStyle: predicate (default)
# bad
foo == 0
0 > foo
bar.baz > 0
# good
foo.zero?
foo.negative?
bar.baz.positive?
Example: EnforcedStyle: comparison
# bad
foo.zero?
foo.negative?
bar.baz.positive?
# good
foo == 0
0 > foo
bar.baz > 0
Use !empty?
instead of size > 0
. Open
if all_relations.size > 0
- Read upRead up
- Exclude checks
This cop checks for numeric comparisons that can be replaced by a predicate method, such as receiver.length == 0, receiver.length > 0, receiver.length != 0, receiver.length < 1 and receiver.size == 0 that can be replaced by receiver.empty? and !receiver.empty.
Example:
# bad
[1, 2, 3].length == 0
0 == "foobar".length
array.length < 1
{a: 1, b: 2}.length != 0
string.length > 0
hash.size > 0
# good
[1, 2, 3].empty?
"foobar".empty?
array.empty?
!{a: 1, b: 2}.empty?
!string.empty?
!hash.empty?
Use the return of the conditional for variable assignment and comparison. Open
if respond_to?(:license) && !license.blank?
rights = license.url
else
rights = utf8_url_for(
host: SITE_NAME,
- Exclude checks
Use content_item_relations.count.positive?
instead of content_item_relations.count > 0
. Open
elsif !is_a?(Comment) && content_item_relations.count > 0 &&
- Read upRead up
- Exclude checks
This cop checks for usage of comparison operators (==
,
>
, <
) to test numbers as zero, positive, or negative.
These can be replaced by their respective predicate methods.
The cop can also be configured to do the reverse.
The cop disregards #nonzero?
as it its value is truthy or falsey,
but not true
and false
, and thus not always interchangeable with
!= 0
.
The cop ignores comparisons to global variables, since they are often
populated with objects which can be compared with integers, but are
not themselves Interger
polymorphic.
Example: EnforcedStyle: predicate (default)
# bad
foo == 0
0 > foo
bar.baz > 0
# good
foo.zero?
foo.negative?
bar.baz.positive?
Example: EnforcedStyle: comparison
# bad
foo.zero?
foo.negative?
bar.baz.positive?
# good
foo == 0
0 > foo
bar.baz > 0