about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <bofh@yhbt.net>2024-02-08 11:58:58 +0000
committerEric Wong <bofh@yhbt.net>2024-03-23 17:30:48 +0000
commita36cf00dee5d7657bf95b66bd4559feaab010989 (patch)
tree7e17cce1d259715baec9846846c21bb876707a69 /lib
parent0a20ff1ffabf99de80182be438f43f2c5e03e25b (diff)
downloadraindrops-a36cf00dee5d7657bf95b66bd4559feaab010989.tar.gz
Once again Ruby seems ready to introduce more incompatibilities
and force busywork upon maintainers[1].  In order to avoid
incompatibilities in the future, I used the following Perl
script to prepend `frozen_string_literal: false' to every
Ruby file:

use v5.12;
use autodie;
my $usage = 'perl /path/to/script <LIST_OF_RB_FILES>';
my $fsl = "# frozen_string_literal: false\n";
for my $f (@ARGV) {
	open my $fh, '<', $f;
	my $s = do { local $/; <$fh> } // die "read($f): $!";
	next if $s =~ /^#\s*frozen_string_literal:/sm;

	# fsl must be after encoding: line if it exists:
	if ($s =~ s/^([ \t]*\#[ \t\-\*\#]+encoding:[^\n]+\n)/$1$fsl/sm
			# or after the shebang
			|| $s =~ s/^(#![^\n]+\n)/$1$fsl/
			# or after embedded switches in rackup files:
			|| ($f =~ /\.ru$/ &&
				$s =~ s/^(#\\[^\n]+\n)/$1$fsl/)
			# or prepend as a last resort:
			|| (substr($s, 0, 0) = $fsl)) {
		open $fh, '>', $f;
		print $fh $s;
		close $fh;
	}
}

Somebody interested will have to go through every Ruby source
file and enable frozen_string_literal once they've thoroughly
verified it's safe to do so.

[1] https://bugs.ruby-lang.org/issues/20205
Diffstat (limited to 'lib')
-rw-r--r--lib/raindrops.rb1
-rw-r--r--lib/raindrops/aggregate.rb1
-rw-r--r--lib/raindrops/aggregate/last_data_recv.rb1
-rw-r--r--lib/raindrops/aggregate/pmq.rb1
-rw-r--r--lib/raindrops/last_data_recv.rb1
-rw-r--r--lib/raindrops/linux.rb1
-rw-r--r--lib/raindrops/middleware.rb1
-rw-r--r--lib/raindrops/middleware/proxy.rb1
-rw-r--r--lib/raindrops/struct.rb1
-rw-r--r--lib/raindrops/watcher.rb1
10 files changed, 10 insertions, 0 deletions
diff --git a/lib/raindrops.rb b/lib/raindrops.rb
index dc61952..c071d57 100644
--- a/lib/raindrops.rb
+++ b/lib/raindrops.rb
@@ -1,4 +1,5 @@
 # -*- encoding: binary -*-
+# frozen_string_literal: false
 #
 # Each Raindrops object is a container that holds several counters.
 # It is internally a page-aligned, shared memory area that allows
diff --git a/lib/raindrops/aggregate.rb b/lib/raindrops/aggregate.rb
index 4fb731f..9ed7eb7 100644
--- a/lib/raindrops/aggregate.rb
+++ b/lib/raindrops/aggregate.rb
@@ -1,4 +1,5 @@
 # -*- encoding: binary -*-
+# frozen_string_literal: false
 #
 # raindrops may use the {aggregate}[https://github.com/josephruscio/aggregate]
 # RubyGem to aggregate statistics from TCP_Info lookups.
diff --git a/lib/raindrops/aggregate/last_data_recv.rb b/lib/raindrops/aggregate/last_data_recv.rb
index 32908f2..2205208 100644
--- a/lib/raindrops/aggregate/last_data_recv.rb
+++ b/lib/raindrops/aggregate/last_data_recv.rb
@@ -1,4 +1,5 @@
 # -*- encoding: binary -*-
+# frozen_string_literal: false
 require "socket"
 #
 #
diff --git a/lib/raindrops/aggregate/pmq.rb b/lib/raindrops/aggregate/pmq.rb
index 64d0a4f..94bdf4f 100644
--- a/lib/raindrops/aggregate/pmq.rb
+++ b/lib/raindrops/aggregate/pmq.rb
@@ -1,4 +1,5 @@
 # -*- encoding: binary -*-
+# frozen_string_literal: false
 require "tempfile"
 require "aggregate"
 require "posix_mq"
diff --git a/lib/raindrops/last_data_recv.rb b/lib/raindrops/last_data_recv.rb
index b4808a1..e6c47e1 100644
--- a/lib/raindrops/last_data_recv.rb
+++ b/lib/raindrops/last_data_recv.rb
@@ -1,4 +1,5 @@
 # -*- encoding: binary -*-
+# frozen_string_literal: false
 require "raindrops"
 
 # This is highly experimental!
diff --git a/lib/raindrops/linux.rb b/lib/raindrops/linux.rb
index 9842ae1..a76192c 100644
--- a/lib/raindrops/linux.rb
+++ b/lib/raindrops/linux.rb
@@ -1,4 +1,5 @@
 # -*- encoding: binary -*-
+# frozen_string_literal: false
 
 # For reporting TCP ListenStats, users of older \Linux kernels need to ensure
 # that the the "inet_diag" and "tcp_diag" kernel modules are loaded as they do
diff --git a/lib/raindrops/middleware.rb b/lib/raindrops/middleware.rb
index 20e573c..25b5a1e 100644
--- a/lib/raindrops/middleware.rb
+++ b/lib/raindrops/middleware.rb
@@ -1,4 +1,5 @@
 # -*- encoding: binary -*-
+# frozen_string_literal: false
 require 'raindrops'
 require 'thread'
 
diff --git a/lib/raindrops/middleware/proxy.rb b/lib/raindrops/middleware/proxy.rb
index a7c8e66..433950c 100644
--- a/lib/raindrops/middleware/proxy.rb
+++ b/lib/raindrops/middleware/proxy.rb
@@ -1,4 +1,5 @@
 # -*- encoding: binary -*-
+# frozen_string_literal: false
 # :stopdoc:
 # This class is used by Raindrops::Middleware to proxy application
 # response bodies.  There should be no need to use it directly.
diff --git a/lib/raindrops/struct.rb b/lib/raindrops/struct.rb
index e81a78e..7233ce8 100644
--- a/lib/raindrops/struct.rb
+++ b/lib/raindrops/struct.rb
@@ -1,4 +1,5 @@
 # -*- encoding: binary -*-
+# frozen_string_literal: false
 
 # This is a wrapper around Raindrops objects much like the core Ruby
 # \Struct can be seen as a wrapper around the core \Array class.
diff --git a/lib/raindrops/watcher.rb b/lib/raindrops/watcher.rb
index ac5b895..8fc0772 100644
--- a/lib/raindrops/watcher.rb
+++ b/lib/raindrops/watcher.rb
@@ -1,4 +1,5 @@
 # -*- encoding: binary -*-
+# frozen_string_literal: false
 require "thread"
 require "time"
 require "socket"