diff --git a/changelog/fix_fix_valid_shareable_constant_value.md b/changelog/fix_fix_valid_shareable_constant_value.md new file mode 100644 index 00000000000..cd1bd0cb1fa --- /dev/null +++ b/changelog/fix_fix_valid_shareable_constant_value.md @@ -0,0 +1 @@ +* [#9598](https://github.com/rubocop/rubocop/pull/9598): Fix RuboCop::MagicComment#valid_shareable_constant_value?. ([@kachick][]) diff --git a/lib/rubocop/magic_comment.rb b/lib/rubocop/magic_comment.rb index 20150a1c077..baa70679837 100644 --- a/lib/rubocop/magic_comment.rb +++ b/lib/rubocop/magic_comment.rb @@ -47,7 +47,7 @@ def valid_literal_value? end def valid_shareable_constant_value? - %w[none literal experimental_everything experimental_copy].include?(shareable_constant_values) + %w[none literal experimental_everything experimental_copy].include?(shareable_constant_value) end # Was a magic comment for the frozen string literal found? diff --git a/spec/rubocop/magic_comment_spec.rb b/spec/rubocop/magic_comment_spec.rb index d81bc2056d9..fff97c88a96 100644 --- a/spec/rubocop/magic_comment_spec.rb +++ b/spec/rubocop/magic_comment_spec.rb @@ -151,4 +151,44 @@ include_examples 'magic comment', '# vim:fileencoding=utf-8', encoding: nil + + describe '#valid_shareable_constant_value?' do + subject { described_class.parse(comment).valid_shareable_constant_value? } + + context 'when given comment specified as `none`' do + let(:comment) { '# shareable_constant_value: none' } + + it { is_expected.to eq(true) } + end + + context 'when given comment specified as `literal`' do + let(:comment) { '# shareable_constant_value: literal' } + + it { is_expected.to eq(true) } + end + + context 'when given comment specified as `experimental_everything`' do + let(:comment) { '# shareable_constant_value: experimental_everything' } + + it { is_expected.to eq(true) } + end + + context 'when given comment specified as `experimental_copy`' do + let(:comment) { '# shareable_constant_value: experimental_copy' } + + it { is_expected.to eq(true) } + end + + context 'when given comment specified as unknown value' do + let(:comment) { '# shareable_constant_value: unknown' } + + it { is_expected.to eq(false) } + end + + context 'when given comment is not specified' do + let(:comment) { '' } + + it { is_expected.to eq(false) } + end + end end