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.

```console
cd /path/to/rubocop/repo
% ruby -v
ruby 2.6.0dev (2018-10-21 trunk 65252) [x86_64-darwin17]
bundle exec rspec

(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.
```
  • Loading branch information
koic authored and bbatsov committed Oct 20, 2018
1 parent 1c261d7 commit 741cd6c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/rubocop/config_loader.rb
Expand Up @@ -181,6 +181,14 @@ def yaml_safe_load(yaml_code, filename)
if defined?(SafeYAML) && SafeYAML.respond_to?(:load)
SafeYAML.load(yaml_code, filename,
whitelisted_tags: %w[!ruby/regexp])
elsif RUBY_VERSION >= '2.6'
YAML.safe_load(
yaml_code,
whitelist_classes: [Regexp, Symbol],
whitelist_symbols: [],
aliases: false,
filename: filename
)
else
YAML.safe_load(yaml_code, [Regexp, Symbol], [], false, filename)
end
Expand Down

0 comments on commit 741cd6c

Please sign in to comment.