Skip to content

Add frozen_string_literal: true to all Ruby files - #21

Merged
olleolleolle merged 1 commit into
masterfrom
frozen-string-literal-onto-master
Nov 16, 2026
Merged

olleolleolle merged 1 commit into
masterfrom
frozen-string-literal-onto-master

Conversation

@olleolleolle

Copy link
Copy Markdown
Contributor

This re-lands #19 on master. #19 was stacked on the "Remove redundant coding comments" PR (#18), and after #18 merged, #19 merged into #18's branch instead of master, so master never got these changes. This PR contains the same change, rebased onto the current master.

Why

Ruby 4.0 warns when code mutates a string literal ("chilled strings"), and a future Ruby version is expected to freeze string literals by default. Files with # frozen_string_literal: true already behave that way today, so adding the comment makes the gem's behaviour the same now and after that change.

What changed

  • Added # frozen_string_literal: true, followed by a blank line, to all Ruby files (lib, specs, gemspec, Gemfile, Rakefile, script/turbux_rspec).
  • Enabled Style/FrozenStringLiteralComment and Layout/EmptyLineAfterMagicComment in .rubocop.yml, so new files keep the comment.

No code changes were needed:

  • The parser's << calls append to arrays (tokens, entries, the parse stack), not strings.
  • Sie::Document::Renderer builds its output with interpolation, +, gsub and encode, which all return new strings, and writes into its own StringIO.new buffer, which isn't frozen.

How it was verified

  • bundle exec rake: 34 + 4 examples, 0 failures.
  • With frozen string literals turned on globally (RUBYOPT=--enable-frozen-string-literal), which freezes every literal in the gem and its specs: 34 + 4 examples, 0 failures.
  • With RUBYOPT=-W:deprecated: no chilled-string warnings.

Risk

Low: the diff only adds magic comments and RuboCop config.

@olleolleolle
olleolleolle merged commit f282109 into master Nov 16, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant