Repository navigation
Enable Style/FrozenStringLiteralComment - #24
Merged
Merged
Conversation
Remove the `Style/FrozenStringLiteralComment: Enabled: false` entry from .rubocop.yml so the cop runs with its default EnforcedStyle (always). Every file RuboCop inspects already starts with `# frozen_string_literal: true`, so no pragmas needed adding and no mutation fixes were required. The cop now keeps new files from dropping the pragma. The string-mutation sites that remain were reviewed and are safe: - `msg <<` in Api.print_env and PrintEnvTool.call appends to interpolated heredocs, which are not frozen on Ruby >= 3.0 (the gem requires >= 3.3). - BaseView#say appends to an explicit `+''` buffer.
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 plain string literals immutable. Accidental in-place mutation of a literal then fails loudly with aFrozenErrorinstead of silently changing shared state, and repeated literals share one object instead of allocating a new one on each evaluation. Every Ruby file in this repo already carries the pragma, butStyle/FrozenStringLiteralCommentwas disabled, so nothing kept new files from leaving it out.Config change
.rubocop.yml: removedWith that removed, the cop uses its defaults (
Enabled: true,EnforcedStyle: always). NoExcludewas added for the cop. The existingAllCopsExclude(bin/**/*,vendor/**/*) is unchanged, and thebin/Ruby binstubs already have the pragma anyway.Files that got the pragma
0. All 37 files rubocop inspects (
lib/,spec/,exe/chatwerk,chatwerk.gemspec,Gemfile,Rakefile,config.ru) already had# frozen_string_literal: trueonmain, so the whole diff is the.rubocop.ymldeletion. There are no exclusions. Inlib/chatwerk.rbandlib/chatwerk/api.rbthe pragma sits on line 2, after# typed: strict. The cop andSorbet/ValidSigilboth accept that order, and I checked that Ruby 3.3, 3.4 and 4.0 still honor the pragma there.Runtime fixes
None needed. Every file already had the pragma, so runtime behavior on this branch is identical to
main. I still audited the code for literal mutation, and every mutation site is safe:lib/chatwerk/api.rb:15,17(Api.print_env) andlib/chatwerk/tools/print_env_tool.rb:24,26(PrintEnvTool.call) domsg << ....msgis an interpolated<<~MESSAGEheredoc, and interpolated strings are not frozen on Ruby >= 3.0 (the gemspec requires>= 3.3).Api.print_envhas no spec coverage; I exercised it by hand (see below).lib/chatwerk/views/base_view.rb:32-33(BaseView#say) appends to a+''buffer. Themessage = ''default and"\n"are only read.input_schemahashes,Responsetext, and the server name go to mcp 1.4.0;descstrings andmap %w[...]go to thor 1.5.0;metadatavalues andIO.popenargv go to RubyGems.Verification
Specs:
main(9a9cfc4) had 58 examples and 0 failures on Ruby 3.4.2. This branch has 58 examples and 0 failures on Ruby 3.3.11, 3.4.2 and 4.0.2, matching the CI matrix. It also passes withRUBYOPT=--enable-frozen-string-literaland with-W:deprecated, with no "literal string will be frozen" warnings.rubocop: 37 files inspected, no offenses. I confirmed the cop is now active: a file without the pragma is flagged.
Static sweep: I read every Ruby file in
lib/,exe/,bin/,spec/, the gemspec,Gemfile,Rakefileandconfig.ru, looking for mutatingStringcalls (<<,concat, bang methods,force_encoding, buffer arguments, mutated default arguments and constants). I also traced literals returned from methods and passed into mcp, thor and query_packwerk.Dynamic checks: I used a small packwerk fixture and an empty directory, and ran:
exe/chatwerkwithversion,help,print_env,packages,package,package_todosandpackage_violations, covering hit, filtered, no-match, multiple-match and missing cases.Chatwerk::Mcp.server.handle_jsonwithinitialize,tools/list, andtools/callon all 5 tools.Api.print_env, the exact-match branch offind_package, and theBaseViewfallbacks.No
FrozenErrorcame up on Ruby 3.3, 3.4 or 4.0.Fresh Eyes: local pre-push review against
origin/mainfound 0 blockers, 0 major, 0 minor and 0 info findings.Pre-existing issues found (not addressed here, unrelated to frozen strings)
chatwerk mcpraisesLoadErrorformcp/transports/stdio, because mcp 1.4.0 moved it tomcp/server/transports/stdio_transport(lib/chatwerk/cli.rb:11-13).config.rureferencesChatwerk::MCPServer, which doesn't exist.lib/chatwerk/views/package_view.rb:9:consumers.uniq.sort!throws away its result.ViolationsDetailsViewreturns only thesayoutput (the "No sources/files found" lines) when anysayfires, which drops the grouped file listing.Helpers.find_package's "Found multiple packages" message is lost when theApimethods rewrap it in a secondChatwerk::Error.