Skip to content

Commit

Permalink
[Fix rubocop#36] Rake/Desc should not generate offense for prerequi…
Browse files Browse the repository at this point in the history
…site declarations

Closes rubocop#36
  • Loading branch information
tejasbubane committed May 21, 2021
1 parent 22d72bc commit 91e700a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,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][])
* [#38](https://github.com/rubocop/rubocop-rake/pull/37): Drop support for Ruby 2.4. ([@tejasbubane])
* [#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)

Expand Down
5 changes: 5 additions & 0 deletions lib/rubocop/cop/rake/desc.rb
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/rake/desc_spec.rb
Expand Up @@ -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

0 comments on commit 91e700a

Please sign in to comment.