Skip to content

Commit

Permalink
Merge pull request #37 from tejasbubane/fix-36
Browse files Browse the repository at this point in the history
[Fix #36] `Rake/Desc` should not generate offense for prerequisite declarations
  • Loading branch information
koic authored Jun 28, 2021
2 parents 22d72bc + 6e1d513 commit 8a82de7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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&.array_type?

add_offense(node)
end

Expand Down
13 changes: 13 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,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 8a82de7

Please sign in to comment.