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

Add auto-correction to RedundantBegin cop #964

Merged
merged 1 commit into from
Apr 9, 2014
Merged

Add auto-correction to RedundantBegin cop #964

merged 1 commit into from
Apr 9, 2014

Conversation

tamird
Copy link
Contributor

@tamird tamird commented Apr 6, 2014

This correction leaves some whitespace around, but other cops should handle that, right?

@bbatsov
Copy link
Collaborator

bbatsov commented Apr 6, 2014

👍 for having auto-correct in this cop. Not sure about the implementation, though. Ideally the auto-correct should leave the code in a clean state, as people might not be using whitespace-related cops. @jonas054 Thoughts?

@jonas054
Copy link
Collaborator

jonas054 commented Apr 6, 2014

Yes. Much better if indentation is in a good state after the change. @tamird So please make the example code in the spec a little longer (and do the necessary adjustments in RedundantBegin#autocorrect) so it's clear that indentation is taken care of.

@tamird
Copy link
Contributor Author

tamird commented Apr 6, 2014

@jonas054 is there an existing facility with this kind of block unwrapping?

@tamird
Copy link
Contributor Author

tamird commented Apr 6, 2014

cc @yujinakayama

@tamird
Copy link
Contributor Author

tamird commented Apr 7, 2014

one question: how can you know what the correct indentation here will be? presumably you guys wanted me to assume that the user has indented inside the begin bit, but we really don't know that. I think this cop should probably not correct the whitespace at all, and leave that to another cop (which doesn't exist at the moment, i believe). WDYT?

@bbatsov
Copy link
Collaborator

bbatsov commented Apr 8, 2014

Doesn't really matter how the begin was indented as we're removing it anyways. There's only only valid indentation point for the rescue in the final code and should not care if the core code in the begin and rescue's body was properly indented.

@tamird
Copy link
Contributor Author

tamird commented Apr 9, 2014

Alright, this code is much uglier now, but it does the whitespace stuff. PTAL

@bbatsov
Copy link
Collaborator

bbatsov commented Apr 9, 2014

The code looks good to me, but I also see two unrelated commits in the PR.

@tamird
Copy link
Contributor Author

tamird commented Apr 9, 2014

They both fix the same issue, just two different cops. Would you like this split into two PRs?

@tamird
Copy link
Contributor Author

tamird commented Apr 9, 2014

oh, sorry, mistook this for the other PR. i'll leave those changes up to you to do elsewhere

@bbatsov
Copy link
Collaborator

bbatsov commented Apr 9, 2014

I think you're looking at the wrong PR. :-)

@tamird
Copy link
Contributor Author

tamird commented Apr 9, 2014

Fixed!

@bbatsov
Copy link
Collaborator

bbatsov commented Apr 9, 2014

Btw, something did came to mind. You might add an example showing what will happen to a single-line begin block. Something like:

begin x; y rescue z end

@tamird
Copy link
Contributor Author

tamird commented Apr 9, 2014

yeah, this code doesn't fix that case very well at all. I'll add a test case to the cop as well and take another stab

@tamird
Copy link
Contributor Author

tamird commented Apr 9, 2014

@bbatsov added

@tamird
Copy link
Contributor Author

tamird commented Apr 9, 2014

the code actually handles it fine, it just takes some special syntax to get the same AST

bbatsov added a commit that referenced this pull request Apr 9, 2014
Add auto-correction to RedundantBegin cop
@bbatsov bbatsov merged commit 7f49735 into rubocop:master Apr 9, 2014
@bbatsov
Copy link
Collaborator

bbatsov commented Apr 9, 2014

👍 Looks good! Keeps those improvements coming! :-)

@tamird tamird deleted the redundant-begin-autocorrect branch April 9, 2014 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants