Skip to content

Commit

Permalink
Copyedit RakeEnvironment cop documentation
Browse files Browse the repository at this point in the history
* Tweak wording of offense message and supporting documentation to
  increase readability.
  • Loading branch information
dylnclrk committed Dec 4, 2019
1 parent 5707bb9 commit 1eec660
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ Rails/Present:
UnlessBlank: true

Rails/RakeEnvironment:
Description: 'Set `:environment` task as a dependency to all rake task.'
Description: 'Include `:environment` as a dependency for all rake tasks.'
Enabled: true
Safe: false
VersionAdded: '2.4'
Expand Down
11 changes: 5 additions & 6 deletions lib/rubocop/cop/rails/rake_environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
module RuboCop
module Cop
module Rails
# This cop checks rake task definition without `environment` dependency.
# `environment` dependency is important because it loads application code
# for the rake task. The rake task cannot use application code, such as
# models, without `environment` dependency.
# This cop checks for Rake tasks without the `environment` dependency. The
# `environment` task loads application code for other Rake tasks. Without
# it, tasks cannot make use of application code like models.
#
# You can ignore the offense if the task satisfies at least one of the
# following conditions:
#
# * The task does not need application code.
# * The task invokes :environment task.
# * The task invokes the :environment task.
#
# @example
# # bad
Expand All @@ -26,7 +25,7 @@ module Rails
# end
#
class RakeEnvironment < Cop
MSG = 'Set `:environment` task as a dependency to all rake task.'
MSG = 'Include `:environment` as a dependency for all Rake tasks.'

def_node_matcher :task_definition?, <<~PATTERN
(send nil? :task ...)
Expand Down
9 changes: 4 additions & 5 deletions manual/cops_rails.md
Original file line number Diff line number Diff line change
Expand Up @@ -1666,16 +1666,15 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
--- | --- | --- | --- | ---
Enabled | No | No | 2.4 | -

This cop checks rake task definition without `environment` dependency.
`environment` dependency is important because it loads application code
for the rake task. The rake task cannot use application code, such as
models, without `environment` dependency.
This cop checks for Rake tasks without the `environment` dependency. The
`environment` task loads application code for other Rake tasks. Without
it, tasks cannot make use of application code like models.

You can ignore the offense if the task satisfies at least one of the
following conditions:

* The task does not need application code.
* The task invokes :environment task.
* The task invokes the :environment task.

### Examples

Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cop/rails/rake_environment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
it 'registers an offense to task without :environment' do
expect_offense(<<~RUBY)
task :foo do
^^^^^^^^^ Set `:environment` task as a dependency to all rake task.
^^^^^^^^^ Include `:environment` as a dependency for all Rake tasks.
end
RUBY
end
Expand Down

0 comments on commit 1eec660

Please sign in to comment.