lib/active_mocker/mock_creator/class_methods.rb
Assignment Branch Condition size for associations_by_class is too high. [19.1/15] (http://c2.com/cgi/wiki?AbcMetric) Open
Open
def associations_by_class
schema_scrapper.associations.to_a.each_with_object({}) do |r, hash|
hash[r.class_name.to_s] ||= {}
hash[r.class_name.to_s][r.type] ||= []
hash[r.class_name.to_s][r.type] << r.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
Use delegate
to define delegations. Open
Open
def table_name
- Read upRead up
- Exclude checks
This cop looks for delegations that could have been created
automatically with the delegate
method.
Safe navigation &.
is ignored because Rails' allow_nil
option checks not just for nil but also delegates if nil
responds to the delegated method.
The EnforceForPrefixed
option (defaulted to true
) means that
using the target object as a prefix of the method name
without using the delegate
method will be a violation.
When set to false
, this case is legal.
Example:
# bad
def bar
foo.bar
end
# good
delegate :bar, to: :foo
# good
def bar
foo&.bar
end
# good
private
def bar
foo.bar
end
# EnforceForPrefixed: true
# bad
def foo_bar
foo.bar
end
# good
delegate :bar, to: :foo, prefix: true
# EnforceForPrefixed: false
# good
def foo_bar
foo.bar
end
# good
delegate :bar, to: :foo, prefix: true
Add an empty line after magic comments. (https://github.com/bbatsov/ruby-style-guide#separate-magic-comments-from-code) Open
Open
require_relative "attributes"
- 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