Skip to content

Use File.open instead of Kernel#open. #583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rdoc/encoding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module RDoc::Encoding
# unknown character in the target encoding will be replaced with '?'

def self.read_file filename, encoding, force_transcode = false
content = open filename, "rb" do |f| f.read end
content = File.open filename, "rb" do |f| f.read end
content.gsub!("\r\n", "\n") if RUBY_PLATFORM =~ /mswin|mingw/

utf8 = content.sub!(/\A\xef\xbb\xbf/, '')
Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc/erbio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#
# erbio = RDoc::ERBIO.new '<%= "hello world" %>', nil, nil
#
# open 'hello.txt', 'w' do |io|
# File.open 'hello.txt', 'w' do |io|
# erbio.result binding
# end
#
Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ def warn message
def write_options
RDoc.load_yaml

open '.rdoc_options', 'w' do |io|
File.open '.rdoc_options', 'w' do |io|
io.set_encoding Encoding::UTF_8

YAML.dump self, io
Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def self.can_parse_by_name file_name
# Returns the file type from the modeline in +file_name+

def self.check_modeline file_name
line = open file_name do |io|
line = File.open file_name do |io|
io.gets
end

Expand Down
4 changes: 2 additions & 2 deletions lib/rdoc/rdoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def setup_output_dir(dir, force)
error "#{dir} exists and is not a directory" unless File.directory? dir

begin
open flag_file do |io|
File.open flag_file do |io|
unless force then
Time.parse io.gets

Expand Down Expand Up @@ -233,7 +233,7 @@ def store= store
def update_output_dir(op_dir, time, last = {})
return if @options.dry_run or not @options.update_output_dir

open output_flag_file(op_dir), "w" do |f|
File.open output_flag_file(op_dir), "w" do |f|
f.puts time.rfc2822
last.each do |n, t|
f.puts "#{n}\t#{t.rfc2822}"
Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc/ri/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def self.default_options
def self.dump data_path
require 'pp'

open data_path, 'rb' do |io|
File.open data_path, 'rb' do |io|
pp Marshal.load(io.read)
end
end
Expand Down
16 changes: 8 additions & 8 deletions lib/rdoc/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ def load_all
def load_cache
#orig_enc = @encoding

open cache_path, 'rb' do |io|
File.open cache_path, 'rb' do |io|
@cache = Marshal.load io.read
end

Expand Down Expand Up @@ -596,7 +596,7 @@ def load_class klass_name
def load_class_data klass_name
file = class_file klass_name

open file, 'rb' do |io|
File.open file, 'rb' do |io|
Marshal.load io.read
end
rescue Errno::ENOENT => e
Expand All @@ -611,7 +611,7 @@ def load_class_data klass_name
def load_method klass_name, method_name
file = method_file klass_name, method_name

open file, 'rb' do |io|
File.open file, 'rb' do |io|
obj = Marshal.load io.read
obj.store = self
obj.parent =
Expand All @@ -631,7 +631,7 @@ def load_method klass_name, method_name
def load_page page_name
file = page_file page_name

open file, 'rb' do |io|
File.open file, 'rb' do |io|
obj = Marshal.load io.read
obj.store = self
obj
Expand Down Expand Up @@ -778,7 +778,7 @@ def save_cache

marshal = Marshal.dump @cache

open cache_path, 'wb' do |io|
File.open cache_path, 'wb' do |io|
io.write marshal
end
end
Expand Down Expand Up @@ -854,7 +854,7 @@ def save_class klass

marshal = Marshal.dump klass

open path, 'wb' do |io|
File.open path, 'wb' do |io|
io.write marshal
end
end
Expand All @@ -879,7 +879,7 @@ def save_method klass, method

marshal = Marshal.dump method

open method_file(full_name, method.full_name), 'wb' do |io|
File.open method_file(full_name, method.full_name), 'wb' do |io|
io.write marshal
end
end
Expand All @@ -901,7 +901,7 @@ def save_page page

marshal = Marshal.dump page

open path, 'wb' do |io|
File.open path, 'wb' do |io|
io.write marshal
end
end
Expand Down
18 changes: 9 additions & 9 deletions test/test_rdoc_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def setup
def test_class_binary_eh_ISO_2022_JP
iso_2022_jp = File.join Dir.tmpdir, "test_rdoc_parser_#{$$}.rd"

open iso_2022_jp, 'wb' do |io|
File.open iso_2022_jp, 'wb' do |io|
io.write "# coding: ISO-2022-JP\n"
io.write ":\e$B%3%^%s%I\e(B:\n"
end
Expand All @@ -31,7 +31,7 @@ def test_class_binary_eh_ISO_2022_JP

def test_class_binary_eh_marshal
marshal = File.join Dir.tmpdir, "test_rdoc_parser_#{$$}.marshal"
open marshal, 'wb' do |io|
File.open marshal, 'wb' do |io|
io.write Marshal.dump('')
io.write 'lots of text ' * 500
end
Expand Down Expand Up @@ -92,7 +92,7 @@ def test_class_can_parse
def test_class_for_executable
temp_dir do
content = "#!/usr/bin/env ruby -w\n"
open 'app', 'w' do |io| io.write content end
File.open 'app', 'w' do |io| io.write content end
app = @store.add_file 'app'

parser = @RP.for app, 'app', content, @options, :stats
Expand Down Expand Up @@ -126,7 +126,7 @@ def test_class_for_modeline
temp_dir do
content = "# -*- rdoc -*-\n= NEWS\n"

open 'NEWS', 'w' do |io| io.write content end
File.open 'NEWS', 'w' do |io| io.write content end
app = @store.add_file 'NEWS'

parser = @RP.for app, 'NEWS', content, @options, :stats
Expand All @@ -140,7 +140,7 @@ def test_class_for_modeline
def test_can_parse_modeline
readme_ext = File.join Dir.tmpdir, "README.EXT.#{$$}"

open readme_ext, 'w' do |io|
File.open readme_ext, 'w' do |io|
io.puts "# README.EXT - -*- rdoc -*- created at: Mon Aug 7 16:45:54 JST 1995"
io.puts
io.puts "This document explains how to make extension libraries for Ruby."
Expand All @@ -162,7 +162,7 @@ def test_class_can_parse_zip
def test_check_modeline
readme_ext = File.join Dir.tmpdir, "README.EXT.#{$$}"

open readme_ext, 'w' do |io|
File.open readme_ext, 'w' do |io|
io.puts "# README.EXT - -*- RDoc -*- created at: Mon Aug 7 16:45:54 JST 1995"
io.puts
io.puts "This document explains how to make extension libraries for Ruby."
Expand All @@ -176,7 +176,7 @@ def test_check_modeline
def test_check_modeline_coding
readme_ext = File.join Dir.tmpdir, "README.EXT.#{$$}"

open readme_ext, 'w' do |io|
File.open readme_ext, 'w' do |io|
io.puts "# -*- coding: utf-8 -*-"
end

Expand All @@ -188,7 +188,7 @@ def test_check_modeline_coding
def test_check_modeline_with_other
readme_ext = File.join Dir.tmpdir, "README.EXT.#{$$}"

open readme_ext, 'w' do |io|
File.open readme_ext, 'w' do |io|
io.puts "# README.EXT - -*- mode: RDoc; indent-tabs-mode: nil -*-"
io.puts
io.puts "This document explains how to make extension libraries for Ruby."
Expand All @@ -202,7 +202,7 @@ def test_check_modeline_with_other
def test_check_modeline_no_modeline
readme_ext = File.join Dir.tmpdir, "README.EXT.#{$$}"

open readme_ext, 'w' do |io|
File.open readme_ext, 'w' do |io|
io.puts "This document explains how to make extension libraries for Ruby."
end

Expand Down
18 changes: 9 additions & 9 deletions test/test_rdoc_rdoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def test_load_options

def test_load_options_invalid
temp_dir do
open '.rdoc_options', 'w' do |io|
File.open '.rdoc_options', 'w' do |io|
io.write "a: !ruby.yaml.org,2002:str |\nfoo"
end

Expand Down Expand Up @@ -187,7 +187,7 @@ def test_parse_file
temp_dir do |dir|
@rdoc.options.root = Pathname(Dir.pwd)

open 'test.txt', 'w' do |io|
File.open 'test.txt', 'w' do |io|
io.puts 'hi'
end

Expand Down Expand Up @@ -223,7 +223,7 @@ def test_parse_file_include_root
temp_dir do |dir|
@rdoc.options.parse %W[--root #{test_path}]

open 'include.txt', 'w' do |io|
File.open 'include.txt', 'w' do |io|
io.puts ':include: test.txt'
end

Expand All @@ -244,7 +244,7 @@ def test_parse_file_page_dir
@rdoc.options.page_dir = Pathname('pages')
@rdoc.options.root = Pathname(Dir.pwd)

open 'pages/test.txt', 'w' do |io|
File.open 'pages/test.txt', 'w' do |io|
io.puts 'hi'
end

Expand All @@ -263,7 +263,7 @@ def test_parse_file_relative
temp_dir do |dir|
@rdoc.options.root = Pathname(dir)

open 'test.txt', 'w' do |io|
File.open 'test.txt', 'w' do |io|
io.puts 'hi'
end

Expand Down Expand Up @@ -339,7 +339,7 @@ def test_remove_unparseable

def test_remove_unparseable_tags_emacs
temp_dir do
open 'TAGS', 'wb' do |io| # emacs
File.open 'TAGS', 'wb' do |io| # emacs
io.write "\f\nlib/foo.rb,43\n"
end

Expand All @@ -353,7 +353,7 @@ def test_remove_unparseable_tags_emacs

def test_remove_unparseable_tags_vim
temp_dir do
open 'TAGS', 'w' do |io| # emacs
File.open 'TAGS', 'w' do |io| # emacs
io.write "!_TAG_"
end

Expand Down Expand Up @@ -392,7 +392,7 @@ def test_setup_output_dir_dry_run

def test_setup_output_dir_exists
Dir.mktmpdir {|path|
open @rdoc.output_flag_file(path), 'w' do |io|
File.open @rdoc.output_flag_file(path), 'w' do |io|
io.puts Time.at 0
io.puts "./lib/rdoc.rb\t#{Time.at 86400}"
end
Expand All @@ -406,7 +406,7 @@ def test_setup_output_dir_exists

def test_setup_output_dir_exists_empty_created_rid
Dir.mktmpdir {|path|
open @rdoc.output_flag_file(path), 'w' do end
File.open @rdoc.output_flag_file(path), 'w' do end

e = assert_raises RDoc::Error do
@rdoc.setup_output_dir path, false
Expand Down
2 changes: 1 addition & 1 deletion test/test_rdoc_ri_paths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def setup
specs.each do |spec|
spec.loaded_from = spec.spec_file

open spec.spec_file, 'w' do |file|
File.open spec.spec_file, 'w' do |file|
file.write spec.to_ruby_for_cache
end

Expand Down
2 changes: 1 addition & 1 deletion test/test_rdoc_servlet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_asset
FileUtils.mkdir 'css'

now = Time.now
open 'css/rdoc.css', 'w' do |io| io.write 'h1 { color: red }' end
File.open 'css/rdoc.css', 'w' do |io| io.write 'h1 { color: red }' end
File.utime now, now, 'css/rdoc.css'

@s.asset_dirs[:darkfish] = '.'
Expand Down
12 changes: 6 additions & 6 deletions test/test_rdoc_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def test_load_cache

Dir.mkdir @tmpdir

open File.join(@tmpdir, 'cache.ri'), 'wb' do |io|
File.open File.join(@tmpdir, 'cache.ri'), 'wb' do |io|
Marshal.dump cache, io
end

Expand Down Expand Up @@ -441,7 +441,7 @@ def test_load_cache_encoding_differs

Dir.mkdir @tmpdir

open File.join(@tmpdir, 'cache.ri'), 'wb' do |io|
File.open File.join(@tmpdir, 'cache.ri'), 'wb' do |io|
Marshal.dump cache, io
end

Expand Down Expand Up @@ -490,7 +490,7 @@ def test_load_cache_legacy

Dir.mkdir @tmpdir

open File.join(@tmpdir, 'cache.ri'), 'wb' do |io|
File.open File.join(@tmpdir, 'cache.ri'), 'wb' do |io|
Marshal.dump cache, io
end

Expand Down Expand Up @@ -538,7 +538,7 @@ def test_load_method_legacy

file = @s.method_file @klass.full_name, @meth.full_name

open file, 'wb' do |io|
File.open file, 'wb' do |io|
io.write "\x04\bU:\x14RDoc::AnyMethod[\x0Fi\x00I" +
"\"\vmethod\x06:\x06EF\"\x11Klass#method0:\vpublic" +
"o:\eRDoc::Markup::Document\x06:\v@parts[\x06" +
Expand Down Expand Up @@ -633,7 +633,7 @@ def test_save

expected[:ancestors]['Object'] = %w[BasicObject]

open File.join(@tmpdir, 'cache.ri'), 'rb' do |io|
File.open File.join(@tmpdir, 'cache.ri'), 'rb' do |io|
cache = Marshal.load io.read

assert_equal expected, cache
Expand Down Expand Up @@ -701,7 +701,7 @@ def test_save_cache

expected[:ancestors]['Object'] = %w[BasicObject]

open File.join(@tmpdir, 'cache.ri'), 'rb' do |io|
File.open File.join(@tmpdir, 'cache.ri'), 'rb' do |io|
cache = Marshal.load io.read

assert_equal expected, cache
Expand Down