Skip to content

Commit 92c3c6f

Browse files
authored
Merge pull request #185 from hanachin/allow_task_with_no_block
[Fix #184] Fix Rake/Environment to allow task with no block
2 parents cc9eea3 + 12771be commit 92c3c6f

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## master (unreleased)
44

5+
### Bug fixes
6+
7+
* [#184](https://github.com/rubocop-hq/rubocop-rails/issues/184): Fix `Rake/Environment` to allow task with no block. ([@hanachin][])
8+
59
## 2.4.1 (2019-12-25)
610

711
### Bug fixes
@@ -122,3 +126,4 @@
122126
[@ngouy]: https://github.com/ngouy
123127
[@mvz]: https://github.com/mvz
124128
[@fidalgo]: https://github.com/fidalgo
129+
[@hanachin]: https://github.com/hanachin

lib/rubocop/cop/rails/rake_environment.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@ class RakeEnvironment < Cop
2929
MSG = 'Include `:environment` task as a dependency for all Rake tasks.'
3030

3131
def_node_matcher :task_definition?, <<~PATTERN
32-
(send nil? :task ...)
32+
(block $(send nil? :task ...) ...)
3333
PATTERN
3434

35-
def on_send(node)
36-
return unless task_definition?(node)
37-
return if task_name(node) == :default
38-
return if with_dependencies?(node)
35+
def on_block(node)
36+
task_definition?(node) do |task_method|
37+
return if task_name(task_method) == :default
38+
return if with_dependencies?(task_method)
3939

40-
add_offense(node)
40+
add_offense(task_method)
41+
end
4142
end
4243

4344
private

spec/rubocop/cop/rails/rake_environment_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,10 @@
8383
task default: :spec
8484
RUBY
8585
end
86+
87+
it 'does not register an offense to task with no block' do
88+
expect_no_offenses(<<~RUBY)
89+
task(:foo).do_something
90+
RUBY
91+
end
8692
end

0 commit comments

Comments
 (0)