From 538b0d856e4ac2346d2c3c169fffa1a9d7c67411 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Sun, 18 Sep 2022 16:06:33 +0900 Subject: [PATCH] Use `contains_comment?` instead of deprecated API Follow up #8405. --- lib/rubocop/cop/lint/empty_class.rb | 4 +++- lib/rubocop/cop/style/empty_method.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/rubocop/cop/lint/empty_class.rb b/lib/rubocop/cop/lint/empty_class.rb index c90d10fecf8..3b90ea0394f 100644 --- a/lib/rubocop/cop/lint/empty_class.rb +++ b/lib/rubocop/cop/lint/empty_class.rb @@ -85,7 +85,9 @@ def on_sclass(node) private def body_or_allowed_comment_lines?(node) - node.body || (cop_config['AllowComments'] && comment_lines?(node)) + return true if node.body + + cop_config['AllowComments'] && processed_source.contains_comment?(node.source_range) end end end diff --git a/lib/rubocop/cop/style/empty_method.rb b/lib/rubocop/cop/style/empty_method.rb index ef7df0bf98f..4bd5de193d8 100644 --- a/lib/rubocop/cop/style/empty_method.rb +++ b/lib/rubocop/cop/style/empty_method.rb @@ -52,7 +52,7 @@ class EmptyMethod < Base MSG_EXPANDED = 'Put the `end` of empty method definitions on the next line.' def on_def(node) - return if node.body || comment_lines?(node) + return if node.body || processed_source.contains_comment?(node.source_range) return if correct_style?(node) add_offense(node) do |corrector|