app/policies/exception_policy.rb
Method has too many lines. [11/10] Open
Open
def method_missing(method_sym, *arguments, &block)
method_str = method_sym.to_s
if method_str.end_with?("?")
exc_method = method_str[0..-2] + "!"
begin
- 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.
Favor unless
over if
for negative conditions. Open
Open
if !guard
# will need to replace this when a new version of pundit arrives
caller_name = caller_locations(1, 1)[0].label
raise Pundit::NotAuthorizedError.new(query: caller_name.to_sym, record: @record, policy: self, message: message)
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
When using method_missing
, define respond_to_missing?
. Open
Open
def method_missing(method_sym, *arguments, &block)
method_str = method_sym.to_s
if method_str.end_with?("?")
exc_method = method_str[0..-2] + "!"
begin
- Read upRead up
- Exclude checks
This cop checks for the presence of method_missing
without also
defining respond_to_missing?
and falling back on super
.
Example:
#bad
def method_missing(name, *args)
# ...
end
#good
def respond_to_missing?(name, include_private)
# ...
end
def method_missing(name, *args)
# ...
super
end