Skip to content

Commit

Permalink
Suppress deprecation warnings of Psych.safe_load args in Ruby 2.6
Browse files Browse the repository at this point in the history
Follow up of #6395 (comment).

The interface of `Psych.safe_load` will change from Ruby 2.6.
ruby/ruby@1c92766

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
```
  • Loading branch information
koic committed Oct 24, 2018
1 parent 984f675 commit c87aea3
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/cc/cli/file_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
{}
Expand Down

0 comments on commit c87aea3

Please sign in to comment.