From 73975f96546ffa4d7cdd50d2ecb4b64c8b268fab Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Sun, 6 Jun 2021 02:58:04 +0900 Subject: [PATCH] Remove redundant code for `Style/MultilineWhenThen` I noticed this in the implementation of #9834. --- lib/rubocop/cop/style/multiline_when_then.rb | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/lib/rubocop/cop/style/multiline_when_then.rb b/lib/rubocop/cop/style/multiline_when_then.rb index e13c09eae41..d851eeb0866 100644 --- a/lib/rubocop/cop/style/multiline_when_then.rb +++ b/lib/rubocop/cop/style/multiline_when_then.rb @@ -35,17 +35,7 @@ class MultilineWhenThen < Base MSG = 'Do not use `then` for multiline `when` statement.' def on_when(node) - # Without `then`, there's no offense - return unless node.then? - - # Single line usage of `then` is not an offense - return if !node.children.last.nil? && !node.multiline? - - # Requires `then` for write `when` and its body on the same line. - return if require_then?(node) - - # For arrays and hashes there's no offense - return if accept_node_type?(node.body) + return if !node.then? || require_then?(node) range = node.loc.begin add_offense(range) do |corrector| @@ -57,6 +47,7 @@ def on_when(node) private + # Requires `then` for write `when` and its body on the same line. def require_then?(when_node) unless when_node.conditions.first.first_line == when_node.conditions.last.last_line return true