Skip to content

Commit

Permalink
Merge pull request #817 from ydah/change/presence
Browse files Browse the repository at this point in the history
Preserve multiline semantics on `Rails/Presence`
  • Loading branch information
koic committed Oct 20, 2022
2 parents e7f9546 + 43fa456 commit d7db4d1
Show file tree
Hide file tree
Showing 2 changed files with 287 additions and 104 deletions.
12 changes: 11 additions & 1 deletion lib/rubocop/cop/rails/presence.rb
Expand Up @@ -106,7 +106,17 @@ def ignore_other_node?(node)
end

def message(node, receiver, other)
format(MSG, prefer: replacement(receiver, other), current: node.source)
prefer = replacement(receiver, other).gsub(/^\s*|\n/, '')
current = current(node).gsub(/^\s*|\n/, '')
format(MSG, prefer: prefer, current: current)
end

def current(node)
if node.source.include?("\n")
"#{node.loc.keyword.with(end_pos: node.condition.loc.selector.end_pos).source} ... end"
else
node.source
end
end

def replacement(receiver, other)
Expand Down

0 comments on commit d7db4d1

Please sign in to comment.