You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
note the &. after the node['maas'] It essentially says if node['maas'] is nil, discontinue this expression and return nil.
This is the same as the elvis operator in other languages. (e.g. ?. in c#)
adding a '.rubocop.yml' to my project with:
AllCops:
TargetRubyVersion: 2.4
effectively enables the use of &. however it introduces new cookstyle errors of recipes/default.rb:1:1: C: Missing magic comment # frozen_string_literal: true. in every other file in my cookbook. Now that chef 12 is EOL, all supported versions of chef are ruby 2.3+, of which, ruby 2.3 was the introduction of this operator.
I don't know how big of an issue that frozen_string_literal error is - if there were a PR to update the ruby version, could this error be suppressed at the same time without repurcussions?
otherwise, all of the code generators would need updated to include that 'frozen_string_literals' in all of their files in order to accept this update.
The same remains true if I use TargetRubyVersion: 2.3
The text was updated successfully, but these errors were encountered:
I would like to enable this nil checking syntax:
admins = node['maas']&.key?('admin_name') ? Array(node['maas']['admin_name']) : data_bag('metal_admins')
note the
&.
after thenode['maas']
It essentially says if node['maas'] is nil, discontinue this expression and return nil.This is the same as the elvis operator in other languages. (e.g.
?.
in c#)adding a '.rubocop.yml' to my project with:
effectively enables the use of
&.
however it introduces new cookstyle errors ofrecipes/default.rb:1:1: C: Missing magic comment # frozen_string_literal: true.
in every other file in my cookbook. Now that chef 12 is EOL, all supported versions of chef are ruby 2.3+, of which, ruby 2.3 was the introduction of this operator.I don't know how big of an issue that frozen_string_literal error is - if there were a PR to update the ruby version, could this error be suppressed at the same time without repurcussions?
otherwise, all of the code generators would need updated to include that 'frozen_string_literals' in all of their files in order to accept this update.
The same remains true if I use
TargetRubyVersion: 2.3
The text was updated successfully, but these errors were encountered: