-
-
Notifications
You must be signed in to change notification settings - Fork 263
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
Add Rails/RakeEnvironment cop #130
Conversation
Hm. I tend to have quite a few tasks with other dependencies, e.g.: task prime: "db:setup" so the less aggressive style would be nice. |
That is a good point. I agree with you. # `foo` task is not checked by the cop
task foo: :bar
# `bar` task is checked by the cop, so totally the cop detects an offense expectedly.
task :bar do
end So I'll change the style to the less aggressive style. |
7ff07b7
to
63e9699
Compare
I updated the cop to not add offense aggressively. |
I’d like to review this one. Please wait a moment. |
config/default.yml
Outdated
@@ -333,6 +333,14 @@ Rails/Present: | |||
# Convert usages of `unless blank?` to `if present?` | |||
UnlessBlank: true | |||
|
|||
Rails/RakeEnvironment: | |||
Description: 'Set :environment task as a dependency to all rake task.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you enclose :environment
in backticks?
# end | ||
# | ||
class RakeEnvironment < Cop | ||
MSG = 'Set :environment task as a dependency to all rake task.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
Rails/RakeEnvironment: | ||
Description: 'Set :environment task as a dependency to all rake task.' | ||
Enabled: true | ||
VersionAdded: '2.4' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not a problem in most cases, but it is likely that calling :environment
task will break a behavior. It may be better to mark it as Safe: false
. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you. I added Safe: false
. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
Can you squash your commits into one?
rebased. THanks! |
Thanks! |
Any suggestions how to fix a no-op task-defintion like this?
|
@OneDivZero As this is a closed PR, I think it would be better to open a new issue for this. |
This pull request will add
Rails/RakeEnvironment
cop to check rake task definition without:environment
dependency.Please read the cop's documentation comment for the motivation for the cop.
rubocop-rake
I'm developing rubocop-rake. It is a RuboCop plugin for rake. I was trying to implement the cop to rubocop-rake, but I thought it should be implemented to rubocop-rails on second thought.
Because most of the rubocop-rails users can enable the cop, but not all rubocop-rake users need the cop.
auto-correct
I think we can implement auto-correction for the cop, but this pull request omits it. I think it is enough for the first step.
I guess implementing auto-correction is a bit of difficult. Because Rake has many styles to define a task.
Aggressive offense
The cop is not aware of nested dependencies.
In this case,
bar
invokseenvironment
, so the cop should not add any offenses tofoo
.But the cop is not aware of the nested dependencies. It means the cop does not know
bar
to invokeenvironment
.We can choose the following two styles.
I choose the latter, which is a more aggressive style, for the first implementation.
I think someone can implement another style in the future if necessary.
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).and description in grammatically correct, complete sentences.
bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.