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 Jun 26, 2021
1 parent 22d72bc commit 1ddb697
Show file tree
Hide file tree
Showing 3 changed files with 21 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
7 changes: 7 additions & 0 deletions lib/rubocop/cop/rake/desc.rb
Expand Up @@ -33,10 +33,17 @@ class Desc < Base

MSG = 'Describe the task with `desc` method.'

def_node_matcher :prerequisites, <<~PATTERN
(send nil? :task (hash (pair _ $_)))
PATTERN

def on_task(node)
return if task_with_desc?(node)
return if Helper::TaskName.task_name(node) == :default

requirements = prerequisites(node)
return if requirements && requirements.array_type?

add_offense(node)
end

Expand Down
13 changes: 13 additions & 0 deletions spec/rubocop/cop/rake/desc_spec.rb
Expand Up @@ -63,4 +63,17 @@
task.name
RUBY
end

it 'registers an offense for one prerequisite declaration (alias)' do
expect_offense(<<~RUBY)
task release: 'changelog:check_clean'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Describe the task with `desc` method.
RUBY
end

it 'does not register an offense for multiple prerequisite declarations' do
expect_no_offenses(<<~RUBY)
task release: ['changelog:check_clean', 'changelog:create']
RUBY
end
end

0 comments on commit 1ddb697

Please sign in to comment.