Preserve and utilize Warning categories#86
Preserve and utilize Warning categories#86thoughtbot-summer wants to merge 1 commit intoShopify:mainfrom
Warning categories#86Conversation
|
I have signed the CLA! |
|
Thanks for your contribution! We should definitely preserve and pass the But we don't need |
It's definitely possible! It would be a pretty straightforward change, and it would feel much more elegant to me. But it would also be a breaking change. At the moment, since Deprecation Toolkit nullifies a warning's category, it effectively enables the |
|
So the thing I'm seeing is that removing the explicit setting of Testing with RSpec, I also don't see any regression regarding Also worth noting that Ruby still sends the warning to Ruby script that shows warnings are sent even if the category is not enabledmodule WarningExt
def warn(message, category: nil)
super "#{"[#{category.upcase}] " if category}#{message}"
end
end
Warning.extend(WarningExt)
p deprecated: Warning[:deprecated], experimental: Warning[:experimental]
warn "foo"
warn "deprecated", category: :deprecated
warn "experimental", category: :experimental
warn "bar", category: :bar rescue p $!outputs when called with If we enable warnings with Taking a step back:
1 feels like we should respect the In general, I wouldn't be in favor of configuring things "behind the back" of the application authors (hence why I asked about this) but given that in test/development, using deprecation toolkit, is truly the best time to enable deprecation warnings and track them in order to take care of them some time before the deprecated behavior is removed, I feel like it's fair to enable them. So by combining those two, maybe what we want is to check if the warning is of a category that's enabled, and also enable |
Currently Deprecation Toolkit does not utilize
Warning's:deprecatedcategory, and in fact it nullifies any category that is set when callingsuper. This change will preserve the category that is passed toWarning.warn; it will automatically enable the:deprecatedcategory, which the user can disable or restore with a new config option; and it will treat any warning with the:deprecatedcategory as a deprecation, if the category is enabled.