From c87aea3b92752c22f5ebfb856b93fd1b2290c708 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Wed, 24 Oct 2018 14:11:08 +0900 Subject: [PATCH] Suppress deprecation warnings of `Psych.safe_load` args in Ruby 2.6 Follow up of #6395 (comment). The interface of `Psych.safe_load` will change from Ruby 2.6. https://github.com/ruby/ruby/commit/1c92766bf0b7394057c00f576fce5464a3037fd9 This PR suppresses the following wargnins in Ruby 2.6.0-dev. ```console % cd path/to/codeclimate/repo % ruby -v ruby 2.6.0dev (2018-10-21 trunk 65252) [x86_64-darwin17] % bundle exec rake (snip) warning: Passing whitelist_classes with the 2nd argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, whitelist_classes: ...) instead. warning: Passing whitelist_symbols with the 3rd argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, whitelist_symbols: ...) instead. warning: Passing aliases with the 4th argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, aliases: ...) instead. warning: Passing filename with the 5th argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, filename: ...) instead. (snip) Failures: 1) CC::CLI::VersionChecker prints nothing when up to date Failure/Error: expect(stderr).to eq "" expected: "" got: "warning: Passing whitelist_classes with the 2nd argument of Psych.safe_load is deprecated. Use keywo....safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, filename: ...) instead.\n" (snip) 2) CC::CLI::VersionChecker does nothing when API is unavailable Failure/Error: expect(stderr).to eq "" expected: "" got: "warning: Passing whitelist_classes with the 2nd argument of Psych.safe_load is deprecated. Use keywo....safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, filename: ...) instead.\n" (snip) 3) CC::CLI::VersionChecker does nothing if checked recently Failure/Error: expect(stderr).to eq "" expected: "" got: "warning: Passing whitelist_classes with the 2nd argument of Psych.safe_load is deprecated. Use keywo....safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, filename: ...) instead.\n" (snip) Finished in 0.63326 seconds (files took 0.71064 seconds to load) 338 examples, 3 failures Failed examples: rspec ./spec/cc/cli/version_checker_spec.rb:71 # CC::CLI::VersionChecker prints nothing when up to date rspec ./spec/cc/cli/version_checker_spec.rb:81 # CC::CLI::VersionChecker does nothing when API is unavailable rspec ./spec/cc/cli/version_checker_spec.rb:96 # CC::CLI::VersionChecker does nothing if checked recently ``` --- lib/cc/cli/file_store.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/cc/cli/file_store.rb b/lib/cc/cli/file_store.rb index f90eeec30..a1a678357 100644 --- a/lib/cc/cli/file_store.rb +++ b/lib/cc/cli/file_store.rb @@ -31,7 +31,17 @@ def load_data @data = if File.exist? self.class::FILE_NAME File.open(self.class::FILE_NAME, "r:bom|utf-8") do |f| - YAML.safe_load(f, [Time], [], false, self.class::FILE_NAME) || {} + if RUBY_VERSION >= '2.6' + YAML.safe_load( + f, + whitelist_classes: [Time], + whitelist_symbols: [], + aliases: false, + filename: self.class::FILE_NAME, + ) || {} + else + YAML.safe_load(f, [Time], [], false, self.class::FILE_NAME) || {} + end end else {}