From 49ea20f45a6e436f416855f703ca05159d13692d Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Fri, 22 May 2020 11:13:44 +0900 Subject: [PATCH] [Fix #111] Fix an error for `Performance/DeletePrefix` and `Performance/DeleteSuffix` Fixes #111. This PR fixes an error for `Performance/DeletePrefix` and `Performance/DeleteSuffix` cops when using autocorrection with RuboCop 0.81 or lower. --- CHANGELOG.md | 4 ++++ lib/rubocop/cop/performance/delete_prefix.rb | 4 +++- lib/rubocop/cop/performance/delete_suffix.rb | 4 +++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c96c56b90..6560e8f168 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## master (unreleased) +### Bug fixes + +* [#111](https://github.com/rubocop-hq/rubocop-performance/issues/111): Fix an error for `Performance/DeletePrefix` and `Performance/DeleteSuffix` cops when using autocorrection with RuboCop 0.81 or lower. ([@koic][]) + ## 1.6.0 (2020-05-22) ### New features diff --git a/lib/rubocop/cop/performance/delete_prefix.rb b/lib/rubocop/cop/performance/delete_prefix.rb index f2867720dc..9ec809ff04 100644 --- a/lib/rubocop/cop/performance/delete_prefix.rb +++ b/lib/rubocop/cop/performance/delete_prefix.rb @@ -62,7 +62,9 @@ def autocorrect(node) new_code = "#{receiver.source}.#{good_method}(#{string_literal})" - corrector.replace(node, new_code) + # TODO: `source_range` is no longer required when RuboCop 0.81 or lower support will be dropped. + # https://github.com/rubocop-hq/rubocop/commit/82eb350d2cba16 + corrector.replace(node.source_range, new_code) end end end diff --git a/lib/rubocop/cop/performance/delete_suffix.rb b/lib/rubocop/cop/performance/delete_suffix.rb index 8d727dd57f..2b3c3d4554 100644 --- a/lib/rubocop/cop/performance/delete_suffix.rb +++ b/lib/rubocop/cop/performance/delete_suffix.rb @@ -62,7 +62,9 @@ def autocorrect(node) new_code = "#{receiver.source}.#{good_method}(#{string_literal})" - corrector.replace(node, new_code) + # TODO: `source_range` is no longer required when RuboCop 0.81 or lower support will be dropped. + # https://github.com/rubocop-hq/rubocop/commit/82eb350d2cba16 + corrector.replace(node.source_range, new_code) end end end