-
-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
The good code is bad, and the bad code is good.
Methods should be defined inside tasks (only)
(but not namespaces), as it is the only way they will not be globally scoped, and thereby silently conflict with all other same-named globally scoped methods.
Obviously it is also fine to define methods in classes or modules... that's outside the scope of this issue.
definition location | scope | rubocop-rake should consider | rubocop-rake currently considers |
---|---|---|---|
top-level | global | bad 🛑 | good ✅ |
namespace block | global | bad 🛑 | bad 🛑 |
task block | task | good ✅ | bad 🛑 |
"Good Code" example for task
:
namespace :foo_namespace do
desc 'foo task'
task :foo do
def greet
puts 'Hello from foo.rake'
end
puts 'In foo task'
greet
end
end
"Bad Code" example for namespace
:
namespace :foo_namespace do
desc 'foo task'
task :foo do
puts 'In foo task'
greet
end
def greet
puts 'Hello from foo.rake'
end
end
"Bad Code" example for top-level
:
desc 'foo task'
task :foo do
puts 'In foo task'
greet
end
def greet
puts 'Hello from foo.rake'
end
reference: https://www.albertoalmagro.com/en/ruby-methods-defined-in-rake-tasks/
austinbachman, bbuchalter, MatzFan and socherbyc
Metadata
Metadata
Assignees
Labels
No labels