Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails/RakeEnvironment false positive when using Capistrano #206

Closed
sinsoku opened this issue Feb 25, 2020 · 2 comments · Fixed by #207
Closed

Rails/RakeEnvironment false positive when using Capistrano #206

sinsoku opened this issue Feb 25, 2020 · 2 comments · Fixed by #207
Labels
bug Something isn't working

Comments

@sinsoku
Copy link
Contributor

sinsoku commented Feb 25, 2020

For projects using Capistrano, we create rake files in lib/capistrano/tasks/*.rake.
In these files we do not need to invoke the :environment task.

Expected behavior

The Cop should not be offense.

Actual behavior

Save the following file as lib/capistrano/tasks/sidekiq.rake.

# frozen_string_literal: true

task :restart_sidekiq do
  on roles(:worker) do
    execute :service, 'sidekiq restart'
  end
end
after 'deploy:published', 'restart_sidekiq'

Then run RuboCop.

$ bundle exec rubocop -P
Inspecting 118 files
.......................................................................................C..............................

Offenses:

lib/capistrano/tasks/sidekiq.rake:3:1: C: Rails/RakeEnvironment: Include :environment task as a dependency for all Rake tasks.
task :restart_sidekiq do
^^^^^^^^^^^^^^^^^^^^^

118 files inspected, 1 offense detected

RuboCop version

0.79.0 (using Parser 2.7.0.2, running on ruby 2.6.5 x86_64-darwin19)

@pocke
Copy link
Contributor

pocke commented Feb 25, 2020

Good point.

I think this cop should ignore lib/capistrano/tasks/**/*.rake by default.
Because capistrano tasks don't need :environment, and the directory structure is the official way.
https://github.com/capistrano/capistrano#capify-your-project

@pocke pocke added the bug Something isn't working label Feb 25, 2020
@koic
Copy link
Member

koic commented Feb 25, 2020

Thanks for the feedback. I agree with @pocke.

sinsoku added a commit to sinsoku/rubocop-rails that referenced this issue Feb 28, 2020
It excludes the directory where Capistrano tasks are located.
Because these tasks don't need to invoke the `:environment` task,
and the directory structure is the official way.
ref: https://github.com/capistrano/capistrano/tree/v3.12.0#capify-your-project

Fixes rubocop#206
sinsoku added a commit to sinsoku/rubocop-rails that referenced this issue Feb 28, 2020
…en using Capistrano

It excludes the directory where Capistrano tasks are located.
Because these tasks don't need to invoke the `:environment` task,
and the directory structure is the official way.
ref: https://github.com/capistrano/capistrano/tree/v3.12.0#capify-your-project

Fixes rubocop#206
sinsoku added a commit to sinsoku/rubocop-rails that referenced this issue Feb 28, 2020
…en using Capistrano

It excludes the directory where Capistrano tasks are located.
Because these tasks don't need to invoke the `:environment` task,
and the directory structure is the official way.
ref: https://github.com/capistrano/capistrano/tree/v3.12.0#capify-your-project

Fixes rubocop#206
@koic koic closed this as completed in #207 Feb 28, 2020
koic added a commit that referenced this issue Feb 28, 2020
[Fix #206] Fix a false positive for `Rails/RakeEnvironment` when using Capistrano
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants