module Rubocop::Cop::Style::FavorModifier
def body_has_comment?(body, comments)
def body_has_comment?(body, comments) comment_lines = comments.map(&:location).map(&:line) body_line = body.loc.expression.line comment_lines.include?(body_line) end
def body_length(body)
def body_length(body) if body && body.loc.expression body.loc.expression.size else 0 end end
def check(sexp, comments)
def check(sexp, comments) case sexp.loc.keyword.source when 'if' then cond, body, _else = *sexp when 'unless' then cond, _else, body = *sexp else cond, body = *sexp end if length(sexp) > 3 false else body_length = body_length(body) if body_length == 0 false else indentation = sexp.loc.keyword.column kw_length = sexp.loc.keyword.size cond_length = cond.loc.expression.size space = 1 total = indentation + body_length + space + kw_length + space + cond_length total <= LineLength.max && !body_has_comment?(body, comments) end end end
def length(sexp)
def length(sexp) sexp.loc.expression.source.lines.to_a.size end