From 2813931e896677cbeb6c714855662fd9615e931c Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Sat, 26 Sep 2026 09:18:37 -0700 Subject: [PATCH] Enable Style/FrozenStringLiteralComment Remove the .rubocop.yml entry that disabled Style/FrozenStringLiteralComment so the cop runs with its default EnforcedStyle (always). Add "# frozen_string_literal: true" to the 11 files the cop flagged: Gemfile, Rakefile, parse_packwerk.gemspec, every file under lib/ that lacked it, and spec/support/have_matching_package.rb. In files with a Sorbet "# typed:" sigil, the pragma goes on the line after the sigil, matching the existing package_set.rb. Drop the now-redundant .freeze calls on the string constants in lib/parse_packwerk/constants.rb (Style/RedundantFreeze). The literals are still frozen, now through the pragma. No mutation fixes were needed. The suite shows no FrozenError and no "literal string will be frozen" warnings under -W:deprecated, and a static sweep of lib/ and the build files found no string-mutating call on a literal. One visible effect: Package#public_path defaults to 'app/public', which is now a frozen String. Package.from already returned the shared DEFAULT_PUBLIC_PATH constant, so mutating it would have corrupted every package; now it raises instead. --- .rubocop.yml | 4 ---- Gemfile | 2 ++ Rakefile | 1 + lib/parse_packwerk.rb | 1 + lib/parse_packwerk/configuration.rb | 1 + lib/parse_packwerk/constants.rb | 25 +++++++++++++------------ lib/parse_packwerk/extensions.rb | 1 + lib/parse_packwerk/package.rb | 1 + lib/parse_packwerk/package_todo.rb | 1 + lib/parse_packwerk/violation.rb | 1 + parse_packwerk.gemspec | 2 ++ spec/support/have_matching_package.rb | 2 ++ 12 files changed, 26 insertions(+), 16 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 64c7add..30ac7aa 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -35,10 +35,6 @@ Lint/DuplicateBranch: Style/NegatedIf: Enabled: false -# Disabling for now until it's clearer why we want this -Style/FrozenStringLiteralComment: - Enabled: false - # It's nice to be able to read the condition first before reading the code within the condition Style/GuardClause: Enabled: false diff --git a/Gemfile b/Gemfile index 79c8851..0961f6e 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' # Specify your gem's dependencies in modularization_tools.gemspec diff --git a/Rakefile b/Rakefile index 806deab..088722c 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,5 @@ # typed: ignore +# frozen_string_literal: true require 'bundler/gem_tasks' require 'rspec/core/rake_task' diff --git a/lib/parse_packwerk.rb b/lib/parse_packwerk.rb index bca4329..47e759c 100644 --- a/lib/parse_packwerk.rb +++ b/lib/parse_packwerk.rb @@ -1,4 +1,5 @@ # typed: strict +# frozen_string_literal: true require 'sorbet-runtime' require 'yaml' diff --git a/lib/parse_packwerk/configuration.rb b/lib/parse_packwerk/configuration.rb index e288421..4c0d922 100644 --- a/lib/parse_packwerk/configuration.rb +++ b/lib/parse_packwerk/configuration.rb @@ -1,4 +1,5 @@ # typed: strict +# frozen_string_literal: true module ParsePackwerk class Configuration < T::Struct diff --git a/lib/parse_packwerk/constants.rb b/lib/parse_packwerk/constants.rb index 5504db5..c3f5038 100644 --- a/lib/parse_packwerk/constants.rb +++ b/lib/parse_packwerk/constants.rb @@ -1,18 +1,19 @@ # typed: strict +# frozen_string_literal: true module ParsePackwerk - ROOT_PACKAGE_NAME = T.let('.'.freeze, String) - PACKAGE_YML_NAME = T.let('package.yml'.freeze, String) - PACKWERK_YML_NAME = T.let('packwerk.yml'.freeze, String) - PACKAGE_TODO_YML_NAME = T.let('package_todo.yml'.freeze, String) - ENFORCE_DEPENDENCIES = T.let('enforce_dependencies'.freeze, String) - ENFORCE_PRIVACY = T.let('enforce_privacy'.freeze, String) - ENFORCE_LAYERS = T.let('enforce_layers'.freeze, String) - DEPENDENCY_VIOLATION_TYPE = T.let('dependency'.freeze, String) - PRIVACY_VIOLATION_TYPE = T.let('privacy'.freeze, String) - PUBLIC_PATH = T.let('public_path'.freeze, String) - METADATA = T.let('metadata'.freeze, String) - DEPENDENCIES = T.let('dependencies'.freeze, String) + ROOT_PACKAGE_NAME = T.let('.', String) + PACKAGE_YML_NAME = T.let('package.yml', String) + PACKWERK_YML_NAME = T.let('packwerk.yml', String) + PACKAGE_TODO_YML_NAME = T.let('package_todo.yml', String) + ENFORCE_DEPENDENCIES = T.let('enforce_dependencies', String) + ENFORCE_PRIVACY = T.let('enforce_privacy', String) + ENFORCE_LAYERS = T.let('enforce_layers', String) + DEPENDENCY_VIOLATION_TYPE = T.let('dependency', String) + PRIVACY_VIOLATION_TYPE = T.let('privacy', String) + PUBLIC_PATH = T.let('public_path', String) + METADATA = T.let('metadata', String) + DEPENDENCIES = T.let('dependencies', String) # Since this metadata is unstructured YAML, it could be any type. We leave it to clients of `ParsePackwerk::Package` # to add types based on their known usage of metadata. diff --git a/lib/parse_packwerk/extensions.rb b/lib/parse_packwerk/extensions.rb index adc57ae..4c8c4fc 100644 --- a/lib/parse_packwerk/extensions.rb +++ b/lib/parse_packwerk/extensions.rb @@ -1,4 +1,5 @@ # typed: strict +# frozen_string_literal: true module ParsePackwerk module Extensions diff --git a/lib/parse_packwerk/package.rb b/lib/parse_packwerk/package.rb index c40b1c0..a97278d 100644 --- a/lib/parse_packwerk/package.rb +++ b/lib/parse_packwerk/package.rb @@ -1,4 +1,5 @@ # typed: strict +# frozen_string_literal: true module ParsePackwerk class Package < T::Struct diff --git a/lib/parse_packwerk/package_todo.rb b/lib/parse_packwerk/package_todo.rb index 59eb4cf..b70ae72 100644 --- a/lib/parse_packwerk/package_todo.rb +++ b/lib/parse_packwerk/package_todo.rb @@ -1,4 +1,5 @@ # typed: strict +# frozen_string_literal: true module ParsePackwerk class PackageTodo < T::Struct diff --git a/lib/parse_packwerk/violation.rb b/lib/parse_packwerk/violation.rb index 247e216..57a8965 100644 --- a/lib/parse_packwerk/violation.rb +++ b/lib/parse_packwerk/violation.rb @@ -1,4 +1,5 @@ # typed: strict +# frozen_string_literal: true module ParsePackwerk class Violation < T::Struct diff --git a/parse_packwerk.gemspec b/parse_packwerk.gemspec index c3b81b2..98fa3e5 100644 --- a/parse_packwerk.gemspec +++ b/parse_packwerk.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Gem::Specification.new do |spec| spec.name = 'parse_packwerk' spec.version = '0.27.0' diff --git a/spec/support/have_matching_package.rb b/spec/support/have_matching_package.rb index 8944fc3..1a4950b 100644 --- a/spec/support/have_matching_package.rb +++ b/spec/support/have_matching_package.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec::Matchers.define(:have_matching_package) do |expected_package, expected_package_todo| match do |actual_packages| @actual_packages = actual_packages