Skip to content

Commit c61ae92

Browse files
authored
ci: run against Ruby 3.4 (#3079)
* ci: run against Ruby 3.4 * fix: frozen string warning Fixes warning `literal string will be frozen in the future` in `faker/default/json.rb` by adding frozen-string literal pragma, but creating a mutable string when needed by calling `#dup`.
1 parent 0d741ed commit c61ae92

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

.github/workflows/ruby.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- uses: actions/checkout@v3
2525
- uses: ruby/setup-ruby@v1
2626
with:
27-
ruby-version: '3.0'
27+
ruby-version: '3.4'
2828

2929
- name: Install dependencies
3030
run: bundle install
@@ -42,6 +42,7 @@ jobs:
4242
- '3.1'
4343
- '3.2'
4444
- '3.3'
45+
- '3.4'
4546
- 'head'
4647
- truffleruby-head
4748
continue-on-error: ${{ endsWith(matrix.ruby, 'head') }}

.rubocop.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ Style/FormatStringToken:
7878

7979
Style/FrozenStringLiteralComment:
8080
Description: Add the frozen_string_literal comment to the top of files to help transition from Ruby 2.3.0 to Ruby 3.0.
81-
Exclude:
82-
- 'lib/faker/default/json.rb'
83-
- 'test/faker/default/test_faker_json.rb'
8481

8582
Style/For:
8683
Description: Checks use of for or each in multiline loops.

lib/faker/default/json.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Faker
24
class Json < Base
35
require 'json'
@@ -104,17 +106,20 @@ def add_hash_to_bottom(hash, key_array, width, options)
104106
end
105107

106108
def add_hash(key_array, hash, width, options)
107-
string_to_eval = 'hash'
109+
string_to_eval = 'hash'.dup
110+
108111
key_array.length.times do |index|
109112
string_to_eval << "['#{key_array[index]}']"
110113
end
111114
string_to_eval << " = #{build_shallow_hash(width, options)}"
112115
eval(string_to_eval)
116+
113117
hash
114118
end
115119

116120
def build_keys_from_array(key_array)
117-
key_string = ''
121+
key_string = ''.dup
122+
118123
key_array.each do |value|
119124
key_string << "['#{value}']"
120125
end

test/faker/default/test_faker_json.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require_relative '../../test_helper'
24

35
class TestFakerJson < Test::Unit::TestCase

0 commit comments

Comments
 (0)