Repository navigation
Enable Style/FrozenStringLiteralComment - #193
Merged
Merged
Conversation
Remove the .rubocop.yml entry that disabled Style/FrozenStringLiteralComment, so the cop now runs with rubocop-gusto's EnforcedStyle: always_true. Add "# frozen_string_literal: true" to the 40 files the cop flagged: everything under lib/, bin/packs, the remaining specs, Gemfile, Rakefile and packs.gemspec. Where a file has a Sorbet "# typed:" sigil, the pragma goes on the line below it, matching the files that already had the pragma (spec_helper.rb, sorbet/tapioca/require.rb, the interactive CLI specs). Gemfile and packs.gemspec also get the blank line that Layout/EmptyLineAfterMagicComment requires. No mutation fixes were needed. A static sweep of every newly frozen literal found none that is mutated in place, either in this repo or by the libraries they are passed to (Thor, tty-prompt/tty-reader, Rainbow, Pastel, CSV, parse_packwerk, packwerk). The spec suite, a run with -W:deprecated (which reported no chilled-string warnings), and smoke runs of every bin/packs command and interactive use case all pass.
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
With
# frozen_string_literal: true, an accidental in-place change to a string literal raises aFrozenErrorright where it happens, rather than quietly changing shared state. The pragma also means each literal is allocated once instead of every time the line runs. On Ruby 3.4+, files without the pragma already emit "literal string will be frozen in the future" deprecation warnings when they mutate a literal, so turning the cop on now keeps us ahead of that.Config change
.rubocop.yml: removed this block:With it gone, the cop picks up
EnforcedStyle: always_truefrom the inheritedrubocop-gustoconfig/default.yml..rubocop_todo.ymlhad no entry for this cop, so it is unchanged.Files changed
lib/, plusbin/packs,Gemfile,Rakefile,packs.gemspec,spec/packs_spec.rb,spec/packs/private/cli_spec.rbandspec/verify_docs_spec.rb.bin/rubocop,bin/tapioca,sorbet/tapioca/require.rb,spec/spec_helper.rb, and two interactive CLI specs). That makes 46, the number of files rubocop inspects.sorbet/rbi/**/*.rbi, which rubocop already skips.bin/packs, the pragma goes on line 3, after the shebang and# typed: strict. Ruby still honors it there.Runtime fixes
None were needed. No spec failed. A static review of every string literal in
lib/andbin/found none that reaches an in-place String mutation. Every<<inlib/appends to an Array, and the gems that receive our literals (Thor, tty-prompt/tty-reader, Pastel, Rainbow, CSV, parse_packwerk, code_ownership, packwerk) either copy them or never change them.Heads-up for downstream code: a few public methods now return frozen Strings. These are the
<<~MSGheredocs without interpolation inPacks::UserEventLogger#after_make_publicand#after_add_dependency, the literal in#documentation_link, andPacks::Private.rename_pack. A custom logger that didsuper << "..."would now raiseFrozenError. Nothing in this repo or its docs does that, and a GitHub code search turned up no such overrides. It was already deprecated too: onmain, that pattern warns on Ruby 3.4+.Verification
origin/maingave 119 examples, 0 failures. This branch gives 119 examples, 0 failures on Ruby 4.0.7 and on 3.3.11, the lowest version in the CI matrix. Those runs used-W:deprecated --debug-frozen-string-literaland produced no chilled-string warnings orFrozenErrors. The suite also passes withRUBYOPT=--enable-frozen-string-literal.srb tchas no errors.lib/andbin/and traced each one to what consumes it. That covered method return values, default arguments, Hash and Array values, and arguments handed to gems. For the gems, I read the source of the exact locked versions.required_ruby_versionis>= 3.3, so interpolated strings stay unfrozen.main.bin/packsCLI invocations: every subcommand,helpfor all 16 commands, and the error paths.TTY::Prompt::Test, plus real-PTY runs of the menu, Rename, Create and Ctrl-C.gem buildandrake -T.main.Checklist