Skip to content

Commit b7449e4

Browse files
authored
Merge pull request #551 from aycabta/use-frozen_string_literal-true
Use frozen_string_literal: true
2 parents d9529ad + 8ffc114 commit b7449e4

File tree

194 files changed

+391
-351
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+391
-351
lines changed

Rakefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ parsed_files = PARSER_FILES.map do |parser_file|
6363
racc = Gem.bin_path 'racc', 'racc'
6464
rb_file = parser_file.gsub(/\.ry\z/, ".rb")
6565
ruby "#{racc} -l -o #{rb_file} #{parser_file}"
66+
open(rb_file, 'r+') do |f|
67+
newtext = "# frozen_string_literal: true\n#{f.read}"
68+
f.rewind
69+
f.write newtext
70+
end
6671
elsif parser_file =~ /\.kpeg\z/ # need kpeg
6772
kpeg = Gem.bin_path 'kpeg', 'kpeg'
6873
rb_file = parser_file.gsub(/\.kpeg\z/, ".rb")

lib/rdoc.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# frozen_string_literal: false
1+
# frozen_string_literal: true
22
$DEBUG_RDOC = nil
33

44
# :main: README.rdoc

lib/rdoc/alias.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# frozen_string_literal: false
1+
# frozen_string_literal: true
22
##
33
# Represent an alias, which is an old_name/new_name pair associated with a
44
# particular context

lib/rdoc/anon_class.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# frozen_string_literal: false
1+
# frozen_string_literal: true
22
##
33
# An anonymous class like:
44
#

lib/rdoc/any_method.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# frozen_string_literal: false
1+
# frozen_string_literal: true
22
##
33
# AnyMethod is the base class for objects representing methods
44

@@ -244,9 +244,9 @@ def param_list
244244
if @block_params then
245245
# If this method has explicit block parameters, remove any explicit
246246
# &block
247-
params.sub!(/,?\s*&\w+/, '')
247+
params = params.sub(/,?\s*&\w+/, '')
248248
else
249-
params.sub!(/\&(\w+)/, '\1')
249+
params = params.sub(/\&(\w+)/, '\1')
250250
end
251251

252252
params = params.gsub(/\s+/, '').split(',').reject(&:empty?)
@@ -274,11 +274,11 @@ def param_seq
274274
if @block_params then
275275
# If this method has explicit block parameters, remove any explicit
276276
# &block
277-
params.sub!(/,?\s*&\w+/, '')
277+
params = params.sub(/,?\s*&\w+/, '')
278278

279279
block = @block_params.tr_s("\n ", " ")
280280
if block[0] == ?(
281-
block.sub!(/^\(/, '').sub!(/\)/, '')
281+
block = block.sub(/^\(/, '').sub(/\)/, '')
282282
end
283283
params << " { |#{block}| ... }"
284284
end

lib/rdoc/attr.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# frozen_string_literal: false
1+
# frozen_string_literal: true
22
##
33
# An attribute created by \#attr, \#attr_reader, \#attr_writer or
44
# \#attr_accessor

lib/rdoc/class_module.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# frozen_string_literal: false
1+
# frozen_string_literal: true
22
##
33
# ClassModule is the base class for objects representing either a class or a
44
# module.

lib/rdoc/code_object.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# frozen_string_literal: false
1+
# frozen_string_literal: true
22
##
33
# Base class for the RDoc code tree.
44
#
@@ -144,7 +144,7 @@ def comment=(comment)
144144
# HACK correct fix is to have #initialize create @comment
145145
# with the correct encoding
146146
if String === @comment and @comment.empty? then
147-
@comment.force_encoding comment.encoding
147+
@comment = RDoc::Encoding.change_encoding @comment, comment.encoding
148148
end
149149
@comment
150150
end

lib/rdoc/code_objects.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# frozen_string_literal: false
1+
# frozen_string_literal: true
22
# This file was used to load all the RDoc::CodeObject subclasses at once. Now
33
# autoload handles this.
44

lib/rdoc/comment.rb

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# frozen_string_literal: false
1+
# frozen_string_literal: true
22
##
33
# A comment holds the text comment for a RDoc::CodeObject and provides a
44
# unified way of cleaning it up and parsing it into an RDoc::Markup::Document.
@@ -45,7 +45,7 @@ class RDoc::Comment
4545

4646
def initialize text = nil, location = nil
4747
@location = location
48-
@text = text
48+
@text = text.nil? ? nil : text.dup
4949

5050
@document = nil
5151
@format = 'rdoc'
@@ -114,10 +114,14 @@ def extract_call_seq method
114114

115115
method.call_seq = seq.chomp
116116

117-
elsif @text.sub!(/^\s*:?call-seq:(.*?)(^\s*$|\z)/m, '') then
118-
seq = $1
119-
seq.gsub!(/^\s*/, '')
120-
method.call_seq = seq
117+
else
118+
regexp = /^\s*:?call-seq:(.*?)(^\s*$|\z)/m
119+
if regexp =~ @text then
120+
@text = @text.sub(regexp, '')
121+
seq = $1
122+
seq.gsub!(/^\s*/, '')
123+
method.call_seq = seq
124+
end
121125
end
122126

123127
method
@@ -133,8 +137,14 @@ def empty?
133137
##
134138
# HACK dubious
135139

136-
def force_encoding encoding
137-
@text.force_encoding encoding
140+
def encode! encoding
141+
# TODO: Remove this condition after Ruby 2.2 EOL
142+
if RUBY_VERSION < '2.3.0'
143+
@text = @text.force_encoding encoding
144+
else
145+
@text = String.new @text, encoding: encoding
146+
end
147+
self
138148
end
139149

140150
##
@@ -200,7 +210,7 @@ def parse
200210
def remove_private
201211
# Workaround for gsub encoding for Ruby 1.9.2 and earlier
202212
empty = ''
203-
empty.force_encoding @text.encoding
213+
empty = RDoc::Encoding.change_encoding empty, @text.encoding
204214

205215
@text = @text.gsub(%r%^\s*([#*]?)--.*?^\s*(\1)\+\+\n?%m, empty)
206216
@text = @text.sub(%r%^\s*[#*]?--.*%m, '')
@@ -216,7 +226,7 @@ def text= text
216226
@text.nil? and @document
217227

218228
@document = nil
219-
@text = text
229+
@text = text.nil? ? nil : text.dup
220230
end
221231

222232
##

0 commit comments

Comments
 (0)