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 20, 2021
1 parent 4549fa0 commit e429f2a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -57,3 +58,4 @@
[@pocke]: https://github.com/pocke
[@jaruuuu]: https://github.com/jaruuuu
[@koic]: https://github.com/koic
[@tejasbubane]: https://github.com/tejasbubane
5 changes: 5 additions & 0 deletions lib/rubocop/cop/rake/desc.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 e429f2a

Please sign in to comment.