Enable Style/FrozenStringLiteralComment - #181
Merged
Merged
Conversation
Remove the `Style/FrozenStringLiteralComment: Enabled: false` entry from .rubocop.yml so the cop runs with its default EnforcedStyle (always). Add `# frozen_string_literal: true` (via `rubocop -A --only Style/FrozenStringLiteralComment`, plus the blank line Layout/EmptyLineAfterMagicComment wants) to the 11 files that lacked it: Gemfile, code_ownership.gemspec, bin/codeownership, rakelib/*.rake, spec/spec_helper.rb, spec/support/application_fixtures.rb and spec/lib/code_ownership/cli_spec.rb. In bin/codeownership the pragma goes after the shebang and before the `# typed: strict` sigil. lib/, the Rakefile and extconf.rb already had it. No mutation fixes were needed. A static review of every string-mutating call in lib/, bin/, rakelib/, the gemspec, Gemfile and the specs found no mutation of a frozen literal. The one in-place append, `messages.last << "\n"` in ForFileOutputBuilder, always receives an interpolated (unfrozen) string, and the gem requires Ruby >= 3.3. The spec suite, the CLI, `rake pkg:ruby` and `gem build` also pass with the pragma, and the suite also passes under --enable-frozen-string-literal.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
# frozen_string_literal: truemakes string literals immutable. Accidental in-place mutation of a literal then fails loudly with aFrozenErrorinstead of silently changing shared state. Each evaluation of a literal also stops allocating a freshString. Everything underlib/, plus theRakefileandext/code_ownership/extconf.rb, already had the pragma. This PR turns the cop on so the rest of the repo follows the same rule and new files can't drift.Config change
.rubocop.yml: removed the block that disabled the cop:EnforcedStylestays at the default (always). NoExcludeor.rubocop_todo.ymlwas needed.Files that got the pragma (11)
Gemfilecode_ownership.gemspecbin/codeownership(after the shebang, before# typed: strict; checked that literals are frozen under both parse.y and Prism)rakelib/compile.rake,rakelib/env.rake,rakelib/helpers.rake,rakelib/pkg.rake,rakelib/spec.rakespec/spec_helper.rb,spec/support/application_fixtures.rb,spec/lib/code_ownership/cli_spec.rbExclusions: none. The generated Sorbet RBIs under
sorbet/rbi/aren't RuboCop targets (rubocop --list-target-files) and are never loaded at runtime, so they were left alone.Runtime fixes
None were needed. No newly frozen literal reaches a mutating call. The only in-place string mutation in the repo is
messages.last << "\n"atlib/code_ownership/private/for_file_output_builder.rb:73. Its receiver is always an interpolated string (L70 or L79). Interpolated strings are not frozen on Ruby >= 3.0, and the gemspec requires >= 3.3. That file also already had the pragma onmain.Verification
bundle exec rake(the CI command:env:dev,compile,spec) on Ruby 4.0.7. Before and after: 91 examples, 0 failures, 1 pending. The pending example is the Ruby < 3.4 backtrace-format case, pending by design on 3.4+. WithRUBYOPT=-W:deprecatedthere were no "literal string will be frozen" (chilled string) warnings. The suite also passes on Ruby 3.3.11, the CI floor. It passes too underRUBYOPT="--enable-frozen-string-literal --debug-frozen-string-literal", which freezes every literal in every file, gems included.Style/FrozenStringLiteralCommentreports none. The one remaining offense,spec/lib/code_ownership_spec.rb:572Style/RegexpLiteral, is already onmainand is out of scope here.srb tcis clean.StringandVec<String>, so Ruby strings are copied, never mutated. None of them is mutated.validate,for_file,for_team,version,help) against a fixture project, including combined, abbreviated and invalid flags.path_from_klass,remove_file_annotation!error branches, andPackOwnershipValidator#callvia packwerk.gem build;rake pkg:rubywith realcargo vendor;rake pkg:<platform>:testwith a real gem install; the rake-compiler native/cross gem tasks that CD uses;rake -T,clean,clobber.FrozenErroranywhere.Unrelated and not changed here:
rake pkg:ruby:test(installing the source gem) fails during the native build with a cargo JSON parse error. It fails the same way onmain.