Assignment Branch Condition size for process_attr is too high. [32.34/15] (http://c2.com/cgi/wiki?AbcMetric) Open
def process_attr(attr)
enums = enums(attr.name)
attr.default = Virtus::Attribute.build(attr.type).coerce(attr.default)
attr.attribute_writer = "write_attribute(:#{attr.name}, val)"
attr.attribute_reader = "read_attribute(:#{attr.name})"
- 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. [26/10] (https://github.com/bbatsov/ruby-style-guide#short-methods) Open
def process_attr(attr)
enums = enums(attr.name)
attr.default = Virtus::Attribute.build(attr.type).coerce(attr.default)
attr.attribute_writer = "write_attribute(:#{attr.name}, val)"
attr.attribute_reader = "read_attribute(:#{attr.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 has too many lines. [13/10] (https://github.com/bbatsov/ruby-style-guide#short-methods) Open
def enums(attribute)
@enums ||= begin
raw_enums = class_introspector
.class_macros
.select { |hash| hash.key?(:enum) }
- 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 process_attr
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def process_attr(attr)
enums = enums(attr.name)
attr.default = Virtus::Attribute.build(attr.type).coerce(attr.default)
attr.attribute_writer = "write_attribute(:#{attr.name}, val)"
attr.attribute_reader = "read_attribute(:#{attr.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 process_attr
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def process_attr(attr)
enums = enums(attr.name)
attr.default = Virtus::Attribute.build(attr.type).coerce(attr.default)
attr.attribute_writer = "write_attribute(:#{attr.name}, val)"
attr.attribute_reader = "read_attribute(:#{attr.name})"
Line is too long. [167/120] (https://github.com/bbatsov/ruby-style-guide#80-character-limits) Open
attr.attribute_reader = "@#{attr.name}_enum_type ||= Virtus::Attribute.build(#{enum_type})\n@#{attr.name}_enum_type.get_key(read_attribute(:#{attr.name}))"
- Exclude checks
Line is too long. [172/120] (https://github.com/bbatsov/ruby-style-guide#80-character-limits) Open
attr.attribute_writer = "@#{attr.name}_enum_type ||= Virtus::Attribute.build(#{enum_type})\nwrite_attribute(:#{attr.name}, @#{attr.name}_enum_type.coerce(val))"
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression. (https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals) Open
unless enums.empty?
- 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 modifier if
usage when having a single-line body. Another good alternative is the usage of control flow &&
/||
. (https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier) Open
if attr.default
- 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?
Align .select
with class_introspector
on line 46. Open
.select { |hash| hash.key?(:enum) }
- Read upRead up
- Exclude checks
This cop checks the indentation of the method name part in method calls that span more than one line.
Example: EnforcedStyle: aligned
# bad
while myvariable
.b
# do something
end
# good
while myvariable
.b
# do something
end
# good
Thing.a
.b
.c
Example: EnforcedStyle: indented
# good
while myvariable
.b
# do something
end
Example: EnforcedStyle: indentedrelativeto_receiver
# good
while myvariable
.a
.b
# do something
end
# good
myvariable = Thing
.a
.b
.c
Align .class_macros
with class_introspector
on line 46. Open
.class_macros
- Read upRead up
- Exclude checks
This cop checks the indentation of the method name part in method calls that span more than one line.
Example: EnforcedStyle: aligned
# bad
while myvariable
.b
# do something
end
# good
while myvariable
.b
# do something
end
# good
Thing.a
.b
.c
Example: EnforcedStyle: indented
# good
while myvariable
.b
# do something
end
Example: EnforcedStyle: indentedrelativeto_receiver
# good
while myvariable
.a
.b
# do something
end
# good
myvariable = Thing
.a
.b
.c
Favor modifier if
usage when having a single-line body. Another good alternative is the usage of control flow &&
/||
. (https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier) Open
if attr.default
- 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?
Add an empty line after magic comments. (https://github.com/bbatsov/ruby-style-guide#separate-magic-comments-from-code) Open
module ActiveMocker
- Read upRead up
- Exclude checks
Checks for a newline after the final magic comment.
Example:
# good
# frozen_string_literal: true
# Some documentation for Person
class Person
# Some code
end
# bad
# frozen_string_literal: true
# Some documentation for Person
class Person
# Some code
end