-
-
Notifications
You must be signed in to change notification settings - Fork 266
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/Exit
cop not catching all uses of exit
?
#1274
Comments
This cop by default exclude rake tasks. You can probably work around this by adding it to the includes yourself (make sure to use the proper I guess, what would the difference be when you use |
A Closing this as it's apparently intended behaviour (which seems yikes-y, honestly). 😬 |
Cany you explain what is yikes here? To me there doesn't seem to be much difference between The behaviour has been so since the cops introduction. I looked at the PR and issue for it but didn't find anything rationalizing why that folder is excluded. If there is a good case for it to run over rake tasks, I don't see why it can't change to do so. |
If your test suite includes rake tasks, a stray IMO, since any |
That sounds like a pretty valid reason to me and perfectly in line for what this cop is supposed to do, per its own documentation
So, feel free to reopen. Though I'm curious. I'm not very well-versed in how rake tasks integrate with running tests in rails: how would I write a rake task in such a way that it is getting executed during my test suite (in a way that |
(This appears to have been closed prematurely. M'bad.) |
Ideally, your Rake task is completely oblivious to how the test suite operates, and instead the test itself will stub certain class/instance method calls and/or create fixtures for any data sources to be accessed, then the task is triggered via |
Thinking about this a bit more I'm not so sure anymore. Rails defines a few rake tasks, and these do explicitly fail with I can see reasoning for both sides, though I'm a lot less certain now and would err on the side of caution for this cop (i.e. how it is currently). |
That's fair, and I'd argue Rails sets an example by writing Rake tasks that fail with a non-0 exit code (which does not break test/CI tooling). Perhaps the issue isn't that the cop doesn't run on Rake tasks, but that if a Rake task is going to bail prematurely, it should do so with either a Not looking to push my opinion, however, and I'll accept your call on this one way or the other. |
Well, depending on how you write your rake tasks you definitly don't want to write exit but there are also valid use-cases where you do. Disallowing For me it sounds good to leave this open in case someone else has opinions on this. Maybe testing frameworks can be improved to warn on early exits like this but I'm not sure if that is even possible with ruby. |
Preamble: Spent an entire day tracking down a CI issue that came down to an
exit
in a Rails task. That seemed to me like the kind of thing 'rubocop-rails' should catch, so I popped in here to make a feature request only to realize (as I was doing my pre-issue due diligence) that there is a cop for it and it just didn't catch this for whatever reason.The Problem: An
exit
in a Rails task went unreported by RuboCop. The project's RuboCop config has no exceptions for this rule, nor is the path ignored.Offending Code:
Expected behavior
A RuboCop error from the
Rails/Exit
cop for file "lib/tasks/weekly_update.rake" on theexit
line.Actual behavior
Steps to reproduce the problem
Offending code (and config) is provided above.
RuboCop version
Include the output of
rubocop -V
orbundle exec rubocop -V
if using Bundler. Here's an example:You can see extension cop versions (e.g. rubocop-rails, rubocop-performance, and others) output by rubocop -V,
include them as well. Here's an example:
The text was updated successfully, but these errors were encountered: