Skip to content

Deprecate EnsureNode#body in favour of EnsureNode#branch#337

Merged
marcandre merged 1 commit into
rubocop:masterfrom
dvandersluis:deprecate-ensure-body
Nov 13, 2024
Merged

Deprecate EnsureNode#body in favour of EnsureNode#branch#337
marcandre merged 1 commit into
rubocop:masterfrom
dvandersluis:deprecate-ensure-body

Conversation

@dvandersluis

Copy link
Copy Markdown
Member

Given the upcoming method change in #336, but also the fact that the tests of that PR cannot pass as-is since rubocop is still relying on the old definition, I thought it would make sense to deprecate EnsureNode#body and add #branch as an alias. Once released, I can update the uses of EnsureNode#body in rubocop (and extensions) without breaking anything, which will allow the "Main Gem Specs" CI to pass.

Comment on lines +15 to +28
# @deprecated Use `EnsureNode#branch`
def body
first_caller = caller(1..1).first

unless DEPRECATION_WARNING_LOCATION_CACHE.include?(first_caller)
warn '`EnsureNode#body` is deprecated and will be changed in the next major version of ' \
'rubocop-ast. Use `EnsureNode#branch` instead to get the body of the `ensure` branch.'
warn "Called from:\n#{caller.join("\n")}\n\n"

DEPRECATION_WARNING_LOCATION_CACHE << first_caller
end

branch
end

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is overkill?

I thought it'd be useful to output a warning given that the method will no longer work the same post #336 release. At the same time, I am going to update all the @rubocop org repos to use the new method name, so the risk is only to 3rd party extensions that might use EnsureNode#body.

I also wanted it to not spam deprecation warnings, hence the cache to make sure each warning is just output once.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Earlopain it looks like StrictWarnings is causing the rubocop master specs to fail because of the warning 🤦. Any ideas?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this is awkward. I didn't anticipate this interaction.

Currently there is nothing to disable this but it is easy enough to control through environment variable. It already does nothing if CI is not set but I don't think that would be appropriate here. I can make a PR tomorrow.

Rails sets STRICT_WARNINGS=1 in their CI instead of relying on something generic, once again I should just have followed what they do.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is overkill?

I don't think so, I like it.

@dvandersluis

Copy link
Copy Markdown
Member Author

Thank you @Earlopain! Everything is green now. Marking this PR as ready for review.

@marcandre

Copy link
Copy Markdown
Contributor

Great. Could you add a Changelog entry please 🙏

@dvandersluis

Copy link
Copy Markdown
Member Author

Yes! Updated now.

@marcandre marcandre merged commit ec4cfc0 into rubocop:master Nov 13, 2024
@marcandre

Copy link
Copy Markdown
Contributor

Thanks so much ❤️

Released as 1.36.0

@Earlopain

Copy link
Copy Markdown
Contributor

One consideration, I don't believe this should show the deprecation warning rightaway. There is currently no RuboCop version that will not show this warning

@Earlopain

Copy link
Copy Markdown
Contributor

#339

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.

3 participants