From e429f2ace087454f1903fde4432a5b57b20a08ef Mon Sep 17 00:00:00 2001 From: Tejas Bubane Date: Fri, 21 May 2021 01:15:57 +0530 Subject: [PATCH] [Fix #36] `Rake/Desc` should not generate offense for prerequisite declarations Closes #36 --- CHANGELOG.md | 2 ++ lib/rubocop/cop/rake/desc.rb | 5 +++++ spec/rubocop/cop/rake/desc_spec.rb | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d169798..60cb44d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * [#33](https://github.com/rubocop/rubocop-rake/pull/33): Drop support for Ruby 2.3. ([@koic][]) * [#34](https://github.com/rubocop/rubocop-rake/pull/34): Require RuboCop 1.0 or higher. ([@koic][]) +* [#36](https://github.com/rubocop/rubocop-rake/issues/36): Fix `Rake/Desc` to not generate offense for prerequisite declarations. ([@tejasbubane][]) ## 0.5.1 (2020-02-14) @@ -57,3 +58,4 @@ [@pocke]: https://github.com/pocke [@jaruuuu]: https://github.com/jaruuuu [@koic]: https://github.com/koic +[@tejasbubane]: https://github.com/tejasbubane diff --git a/lib/rubocop/cop/rake/desc.rb b/lib/rubocop/cop/rake/desc.rb index c0f8f99..846faef 100644 --- a/lib/rubocop/cop/rake/desc.rb +++ b/lib/rubocop/cop/rake/desc.rb @@ -33,9 +33,14 @@ class Desc < Base MSG = 'Describe the task with `desc` method.' + def_node_matcher :prerequisite_declaration?, <<~PATTERN + (send nil? :task (hash ...)) + PATTERN + def on_task(node) return if task_with_desc?(node) return if Helper::TaskName.task_name(node) == :default + return if prerequisite_declaration?(node) add_offense(node) end diff --git a/spec/rubocop/cop/rake/desc_spec.rb b/spec/rubocop/cop/rake/desc_spec.rb index cfe7ca5..44613c9 100644 --- a/spec/rubocop/cop/rake/desc_spec.rb +++ b/spec/rubocop/cop/rake/desc_spec.rb @@ -63,4 +63,10 @@ task.name RUBY end + + it 'does not register an offense for prerequisite declarations' do + expect_no_offenses(<<~RUBY) + task release: 'changelog:check_clean' + RUBY + end end