From 3c915658cd4cb24c2d2c8115080b387ab2025963 Mon Sep 17 00:00:00 2001 From: takahashim Date: Mon, 12 Aug 2019 17:19:47 +0900 Subject: [PATCH 1/2] rubocop: make `Style/MethodCallWithArgsParentheses` enable cf. #1357 --- .rubocop.yml | 21 ++++++ bin/review-catalog-converter | 2 +- bin/review-check | 10 +-- bin/review-checkdep | 2 +- bin/review-compile | 6 +- bin/review-index | 12 ++-- bin/review-preproc | 20 +++--- bin/review-validate | 2 +- bin/review-vol | 8 +-- lib/review/book.rb | 2 +- lib/review/book/base.rb | 8 +-- lib/review/book/index.rb | 20 +++--- lib/review/builder.rb | 34 +++++----- lib/review/catalog.rb | 2 +- lib/review/compiler.rb | 64 +++++++++---------- lib/review/epubmaker.rb | 4 +- lib/review/htmlbuilder.rb | 32 +++++----- lib/review/htmltoc.rb | 2 +- lib/review/i18n.rb | 4 +- lib/review/idgxmlbuilder.rb | 22 +++---- lib/review/init.rb | 28 ++++---- lib/review/latexbuilder.rb | 12 ++-- lib/review/lineinput.rb | 2 +- lib/review/makerhelper.rb | 2 +- lib/review/markdownbuilder.rb | 8 +-- lib/review/pdfmaker.rb | 6 +- lib/review/plaintextbuilder.rb | 58 ++++++++--------- lib/review/preprocessor.rb | 24 +++---- lib/review/rstbuilder.rb | 46 ++++++------- lib/review/tocparser.rb | 30 ++++----- lib/review/tocprinter.rb | 16 ++--- lib/review/topbuilder.rb | 6 +- lib/review/update.rb | 28 ++++---- lib/review/webmaker.rb | 6 +- review.gemspec | 4 +- samples/sample-book/src/lib/tasks/review.rake | 16 ++--- .../src/lib/tasks/z01_copy_sty.rake | 6 +- samples/syntax-book/lib/tasks/review.rake | 14 ++-- .../syntax-book/lib/tasks/z01_copy_sty.rake | 6 +- test/test_catalog.rb | 4 +- test/test_catalog_converter_cmd.rb | 2 +- test/test_epubmaker_cmd.rb | 4 +- test/test_htmlbuilder.rb | 8 +-- test/test_i18n.rb | 22 +++---- test/test_idgxmlbuilder.rb | 4 +- test/test_image_finder.rb | 12 ++-- test/test_latexbuilder.rb | 6 +- test/test_latexbuilder_v2.rb | 4 +- test/test_makerhelper.rb | 6 +- test/test_pdfmaker.rb | 2 +- test/test_pdfmaker_cmd.rb | 2 +- test/test_textutils.rb | 4 +- test/test_topbuilder.rb | 2 +- test/test_update.rb | 4 +- test/test_yamlloader.rb | 26 ++++---- 55 files changed, 364 insertions(+), 343 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 43352ba9f..741096611 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -193,6 +193,27 @@ Style/LineEndConcatenation: Style/MethodCallWithoutArgsParentheses: Enabled: true +Style/MethodCallWithArgsParentheses: + IgnoredMethods: + - 'require' + - 'include' + - 'file' + - 'task' + - 'desc' + - 'info' + - 'gem' + - 'exit' + - 'print' + - 'puts' + - 'warn' + - 'error' + - 'raise' + - 'yield' + - 'source' + - 'assert' + - 'assert_equal' + Enabled: true + Style/MixinUsage: Enabled: false diff --git a/bin/review-catalog-converter b/bin/review-catalog-converter index e0115fcf9..10dfa1ccd 100755 --- a/bin/review-catalog-converter +++ b/bin/review-catalog-converter @@ -140,7 +140,7 @@ end def replace_old_style_part(dir) catalog = ReVIEW::Catalog.new(File.open("#{dir}/catalog.yml")) Array.new(catalog.parts.split("\n")).each_with_index do |part, part_idx| - next if part.end_with? '.re' + next if part.end_with?('.re') allow_overwrite = true part_name = sprintf('part%d.re', part_idx + 1) diff --git a/bin/review-check b/bin/review-check index bd9f9f134..49c2daa44 100755 --- a/bin/review-check +++ b/bin/review-check @@ -50,7 +50,7 @@ def main end opts.on('--text', 'Check text.') do modes ||= [] - modes.push :text + modes.push(:text) end opts.on('--help', 'print this message and quit.') do puts opts.help @@ -72,7 +72,7 @@ def main modes.each do |mode| case mode when :text - check_text files + check_text(files) else raise 'must not happen' end @@ -122,9 +122,9 @@ def words_re(rc) next if line[0, 1] == '#' if / !/ =~ line line, n = *line.split('!', 2) - nega.push n.strip + nega.push(n.strip) end - words.push line.strip + words.push(line.strip) end return Regexp.compile(words.join('|')), nega.empty? ? nil : Regexp.compile(nega.join('|')) @@ -157,7 +157,7 @@ def each_paragraph(f) break if line.strip.empty? break if %r{\A(?:=|//[\w\}])} =~ line next if /\A\#@/ =~ line - buf.push line.strip + buf.push(line.strip) end yield buf, lineno @review_utils_word_ok = nil diff --git a/bin/review-checkdep b/bin/review-checkdep index 533a9a4db..88997a1e1 100755 --- a/bin/review-checkdep +++ b/bin/review-checkdep @@ -28,7 +28,7 @@ def main @unprovided[kw] = location end when /\A\#@provide\((.*)\)/ - provide $1 + provide($1) else line.scan(/@\{(.*?)[,\}]/) { provide $1 } end diff --git a/bin/review-compile b/bin/review-compile index 77adbacbf..9492b254c 100755 --- a/bin/review-compile +++ b/bin/review-compile @@ -88,7 +88,7 @@ def _main compiler = ReVIEW::Compiler.new(load_strategy_class(@target, @check_only)) result = compiler.compile(chap) if @output_filename - write @output_filename, result + write(@output_filename, result) else puts result unless @check_only end @@ -99,12 +99,12 @@ def _main compiler = ReVIEW::Compiler.new(load_strategy_class(@target, @check_only)) book.chapters.each do |chap| str = compiler.compile(chap) - write "#{chap.name}#{compiler.strategy.extname}", str unless @check_only + write("#{chap.name}#{compiler.strategy.extname}", str) unless @check_only end # PART book.parts_in_file.each do |part| str = compiler.compile(part) - write "#{part.name}#{compiler.strategy.extname}", str unless @check_only + write("#{part.name}#{compiler.strategy.extname}", str) unless @check_only end else raise "must not happen: #{@mode}" diff --git a/bin/review-index b/bin/review-index index 67bdebda9..753d9015a 100755 --- a/bin/review-index +++ b/bin/review-index @@ -45,13 +45,13 @@ def _main opts.on('-a', '--all', 'print all chapters.') { source = book } opts.on('-p', '--part N', 'list only part N.') do |n| source = book.part(Integer(n)) or - error_exit "part #{n} does not exist in this book" + error_exit("part #{n} does not exist in this book") end opts.on('-c', '--chapter C', 'list only chapter C.') do |c| begin source = ReVIEW::Book::Part.new(nil, 1, [book.chapter(c)]) rescue - error_exit "chapter #{c} does not exist in this book" + error_exit("chapter #{c} does not exist in this book") end end opts.on('-l', '--level N', 'list upto N level (1..4, default=4)') do |n| @@ -79,7 +79,7 @@ def _main book.load_config(yamlfile) if yamlfile if source - error_exit '-a/-s option and file arguments are exclusive' unless ARGV.empty? + error_exit('-a/-s option and file arguments are exclusive') unless ARGV.empty? else puts opts.help exit 0 @@ -88,13 +88,13 @@ def _main begin printer = printer_class.new(upper, param) if source.is_a?(ReVIEW::Book::Part) - printer.print_part source + printer.print_part(source) else - printer.print_book source + printer.print_book(source) end rescue ReVIEW::Error, Errno::ENOENT => e raise if $DEBUG - error_exit e.message + error_exit(e.message) end end diff --git a/bin/review-preproc b/bin/review-preproc index b0cb41cb3..e42f3423b 100755 --- a/bin/review-preproc +++ b/bin/review-preproc @@ -39,7 +39,7 @@ def main if ENV['REVIEW_SAFE_MODE'].to_i & 2 > 0 @logger.warn 'review-preproc-ext.rb is prohibited in safe mode. ignored.' else - Kernel.load File.expand_path('review-preproc-ext.rb') + Kernel.load(File.expand_path('review-preproc-ext.rb')) end end @@ -71,21 +71,21 @@ def main current_file = path case mode when :output - File.open(path) { |f| pp.process f, $stdout } + File.open(path) { |f| pp.process(f, $stdout) } when :replace - File.write "#{path}.pptmp", preproc(pp, path) - File.rename "#{path}.pptmp", path + File.write("#{path}.pptmp", preproc(pp, path)) + File.rename("#{path}.pptmp", path) when :diff, :check tmp = '/tmp/review.pptmp' begin - File.write tmp, preproc(pp, path) + File.write(tmp, preproc(pp, path)) if mode == :check - system "diff -qu #{path} #{tmp} >/dev/null || echo #{path}" + system("diff -qu #{path} #{tmp} >/dev/null || echo #{path}") else - system "diff -u #{path} #{tmp}" + system("diff -u #{path} #{tmp}") end ensure - FileUtils.rm_f tmp + FileUtils.rm_f(tmp) end else raise "must not happen: #{mode}" @@ -99,12 +99,12 @@ end def preproc(pp, path) buf = StringIO.new - File.open(path) { |f| pp.process f, buf } + File.open(path) { |f| pp.process(f, buf) } buf.string end def File.write(path, str) - File.open(path, 'w') { |f| f.write str } + File.open(path, 'w') { |f| f.write(str) } end sigmain diff --git a/bin/review-validate b/bin/review-validate index fc93cdd71..4277e71bf 100755 --- a/bin/review-validate +++ b/bin/review-validate @@ -48,7 +48,7 @@ ARGF.each do |line| @logger.warn "#{ln}: found '*' without the head space. Is it correct?" end elsif line =~ /\A\s+(\d+\.)\s+/ && line =~ /\A\s+\*\s+/ - unless Tw[list emlist listnum emlistnum cmd image table].include?(block) + unless Tw[list(emlist(listnum(emlistnum(cmd(image(table))))))].include?(block) @logger.warn "#{ln}: found itemized list or numbered list in #{block}. Is it correct?" end elsif block == 'table' diff --git a/bin/review-vol b/bin/review-vol index d1eed95b1..e0c7f4256 100755 --- a/bin/review-vol +++ b/bin/review-vol @@ -69,7 +69,7 @@ def main end end puts '=============================' - print_volume book.volume # puts "Total #{book.volume}" + print_volume(book.volume) # puts "Total #{book.volume}" rescue ReVIEW::ApplicationError, Errno::ENOENT => e raise if $DEBUG @logger.error "#{File.basename($PROGRAM_NAME)}: #{e.message}" @@ -79,13 +79,13 @@ end def print_chapter_volume(chap) vol = chap.volume title = chap.title - printf "%s %3dKB %6dC %5dL %3dP %s %-s\n", + printf("%s %3dKB %6dC %5dL %3dP %s %-s\n", chapnumstr(chap.number), vol.kbytes, vol.chars, vol.lines, vol.page, - "#{chap.name} ".ljust(25, '.'), title + "#{chap.name} ".ljust(25, '.'), title) end def print_volume(vol) - printf " %3dKB %6dC %5dL %3dP\n", vol.kbytes, vol.chars, vol.lines, vol.page + printf(" %3dKB %6dC %5dL %3dP\n", vol.kbytes, vol.chars, vol.lines, vol.page) end def chapnumstr(n) diff --git a/lib/review/book.rb b/lib/review/book.rb index 1890c45a7..5e1218987 100644 --- a/lib/review/book.rb +++ b/lib/review/book.rb @@ -19,7 +19,7 @@ module ReVIEW module Book def self.load(dir) - Base.load dir + Base.load(dir) end end end diff --git a/lib/review/book/base.rb b/lib/review/book/base.rb index 0cee186cd..582f5c35d 100644 --- a/lib/review/book/base.rb +++ b/lib/review/book/base.rb @@ -189,7 +189,7 @@ def catalog return @catalog if @catalog.present? catalogfile_path = filename_join(@basedir, config['catalogfile']) - if File.file? catalogfile_path + if File.file?(catalogfile_path) @catalog = File.open(catalogfile_path, 'rt:BOM|utf-8') { |f| Catalog.new(f) } end if @catalog @@ -300,13 +300,13 @@ def read_parts list = parse_chapters # NOTE: keep this = style to work this logic. if pre = prefaces - list.unshift pre + list.unshift(pre) end if app = appendix - list.push app + list.push(app) end if post = postscripts - list.push post + list.push(post) end list end diff --git a/lib/review/book/index.rb b/lib/review/book/index.rb index ef2a8aab1..942953232 100644 --- a/lib/review/book/index.rb +++ b/lib/review/book/index.rb @@ -21,7 +21,7 @@ def self.parse(src, *args) seq = 1 src.grep(%r{\A//#{item_type}}) do |line| if id = line.slice(/\[(.*?)\]/, 1) - items.push item_class.new(id, seq) + items.push(item_class.new(id, seq)) seq += 1 if id.empty? ReVIEW.logger.warn "warning: no ID of #{item_type} in #{line}" @@ -144,7 +144,7 @@ def self.parse(src) if m = /\[(.*?)\]\[(.*)\]/.match(line) m1 = m[1].gsub(/\\(\])/) { $1 } m2 = m[2].gsub(/\\(\])/) { $1 } - items.push Item.new(m1, seq, m2) + items.push(Item.new(m1, seq, m2)) end seq += 1 end @@ -161,9 +161,9 @@ def self.parse(src, *args) elements = line.split(/\[(.*?)\]/) if elements[1].present? if line =~ %r{\A//imgtable} - items.push item_class.new(elements[1], 0, elements[3]) + items.push(item_class.new(elements[1], 0, elements[3])) else ## %r<\A//(image|graph)> - items.push item_class.new(elements[1], seq, elements[3]) + items.push(item_class.new(elements[1], seq, elements[3])) seq += 1 end if elements[1] == '' @@ -203,7 +203,7 @@ def path attr_reader :image_finder def initialize(items, chapid, basedir, types, builder) - super items + super(items) items.each do |i| i.index = self end @@ -237,7 +237,7 @@ def self.parse(src, *args) seq = 1 src.grep(/@/) do |line| line.gsub(/@\{(.+?)\}/) do - items.push item_class.new($1, seq) + items.push(item_class.new($1, seq)) seq += 1 end end @@ -255,7 +255,7 @@ def self.parse(src) if m = /\[(.*?)\]\[(.*)\]/.match(line) m1 = m[1].gsub(/\\(.)/) { $1 } m2 = m[2].gsub(/\\(.)/) { $1 } - items.push Item.new(m1, seq, m2) + items.push(Item.new(m1, seq, m2)) end seq += 1 end @@ -349,11 +349,11 @@ def self.parse(src, chap) if %w[nonum notoc nodisp].include?(m[2]) headlines[index] = m[3].present? ? m[3].strip : m[4].strip - items.push Item.new(headlines.join('|'), nil, m[4].strip) + items.push(Item.new(headlines.join('|'), nil, m[4].strip)) else indexs[index] += 1 headlines[index] = m[3].present? ? m[3].strip : m[4].strip - items.push Item.new(headlines.join('|'), indexs.dup, m[4].strip) + items.push(Item.new(headlines.join('|'), indexs.dup, m[4].strip)) end end new(items, chap) @@ -401,7 +401,7 @@ def self.parse(src, *_args) caption = m[3].strip id = caption if id.nil? || id.empty? - items.push item_class.new(id, seq, caption) + items.push(item_class.new(id, seq, caption)) seq += 1 end new(items) diff --git a/lib/review/builder.rb b/lib/review/builder.rb index 62d151150..f3d9fc9dc 100644 --- a/lib/review/builder.rb +++ b/lib/review/builder.rb @@ -122,33 +122,33 @@ def line_num def list(lines, id, caption, lang = nil) begin - list_header id, caption, lang + list_header(id, caption, lang) rescue KeyError error "no such list: #{id}" end - list_body id, lines, lang + list_body(id, lines, lang) end def listnum(lines, id, caption, lang = nil) begin - list_header id, caption, lang + list_header(id, caption, lang) rescue KeyError error "no such list: #{id}" end - listnum_body lines, lang + listnum_body(lines, lang) end def source(lines, caption, lang = nil) - source_header caption - source_body lines, lang + source_header(caption) + source_body(lines, lang) end def image(lines, id, caption, metric = nil) if @chapter.image(id).bound? - image_image id, caption, metric + image_image(id, caption, metric) else warn "image not bound: #{id}" if @strict - image_dummy id, caption, lines + image_dummy(id, caption, lines) end end @@ -169,12 +169,12 @@ def table(lines, id = nil, caption = nil) begin if caption.present? - table_header id, caption + table_header(id, caption) end rescue KeyError error "no such table: #{id}" end - table_begin rows.first.size + table_begin(rows.first.size) if sepidx sepidx.times do tr(rows.shift.map { |s| th(s) }) @@ -199,7 +199,7 @@ def adjust_n_cols(rows) end n_maxcols = rows.map(&:size).max rows.each do |cols| - cols.concat [''] * (n_maxcols - cols.size) + cols.concat([''] * (n_maxcols - cols.size)) end rows end @@ -230,7 +230,7 @@ def compile_inline(s) end def inline_chapref(id) - compile_inline @book.chapter_index.display_string(id) + compile_inline(@book.chapter_index.display_string(id)) rescue KeyError error "unknown chapter: #{id}" end @@ -242,7 +242,7 @@ def inline_chap(id) end def inline_title(id) - compile_inline @book.chapter_index.title(id) + compile_inline(@book.chapter_index.title(id)) rescue KeyError error "unknown chapter: #{id}" end @@ -341,10 +341,10 @@ def text(str) end def bibpaper(lines, id, caption) - bibpaper_header id, caption + bibpaper_header(id, caption) unless lines.empty? puts - bibpaper_bibpaper id, caption, lines + bibpaper_bibpaper(id, caption, lines) end puts end @@ -558,7 +558,7 @@ def graph_plantuml(id, file_path, _line, tf_path) file_path.sub!(/\.pdf\Z/, '.eps') end system_graph(id, 'java', '-jar', 'plantuml.jar', "-t#{ext}", '-charset', 'UTF-8', tf_path) - FileUtils.mv "#{tf_path}.#{ext}", file_path + FileUtils.mv("#{tf_path}.#{ext}", file_path) file_path end @@ -567,7 +567,7 @@ def image_ext end def inline_include(file_name) - compile_inline File.read(file_name, mode: 'rt:BOM|utf-8').chomp + compile_inline(File.read(file_name, mode: 'rt:BOM|utf-8').chomp) end def ul_item_begin(lines) diff --git a/lib/review/catalog.rb b/lib/review/catalog.rb index 76ee13579..b74afbdb9 100644 --- a/lib/review/catalog.rb +++ b/lib/review/catalog.rb @@ -3,7 +3,7 @@ module ReVIEW class Catalog def initialize(file) - if file.respond_to? :read + if file.respond_to?(:read) @yaml = YAML.load(file.read) else ## as Object @yaml = file diff --git a/lib/review/compiler.rb b/lib/review/compiler.rb index 64f1b6d2b..a0dd9ef41 100644 --- a/lib/review/compiler.rb +++ b/lib/review/compiler.rb @@ -66,11 +66,11 @@ def block_allowed? SYNTAX = {} def self.defblock(name, argc, optional = false, &block) - defsyntax name, (optional ? :optional : :block), argc, &block + defsyntax(name, (optional ? :optional : :block), argc, &block) end def self.defsingle(name, argc, &block) - defsyntax name, :line, argc, &block + defsyntax(name, :line, argc, &block) end def self.defsyntax(name, type, argc, &block) @@ -217,20 +217,20 @@ def inline_defined?(name) def do_compile f = LineInput.new(StringIO.new(@chapter.content)) - @strategy.bind self, @chapter, Location.new(@chapter.basename, f) + @strategy.bind(self, @chapter, Location.new(@chapter.basename, f)) tagged_section_init while f.next? case f.peek when /\A\#@/ f.gets # Nothing to do when /\A=+[\[\s\{]/ - compile_headline f.gets + compile_headline(f.gets) when /\A\s+\*/ - compile_ulist f + compile_ulist(f) when /\A\s+\d+\./ - compile_olist f + compile_olist(f) when /\A\s*:\s/ - compile_dlist f + compile_dlist(f) when %r{\A//\}} f.gets error 'block end seen but not opened' @@ -239,10 +239,10 @@ def do_compile syntax = syntax_descriptor(name) unless syntax error "unknown command: //#{name}" - compile_unknown_command args, lines + compile_unknown_command(args, lines) next end - compile_command syntax, args, lines + compile_command(syntax, args, lines) when %r{\A//} line = f.gets warn "`//' seen but is not valid command: #{line.strip.inspect}" @@ -255,7 +255,7 @@ def do_compile f.gets next end - compile_paragraph f + compile_paragraph(f) end end close_all_tagged_section @@ -296,7 +296,7 @@ def compile_headline(line) end @headline_indexs[index] += 1 close_current_tagged_section(level) - @strategy.headline level, label, caption + @strategy.headline(level, label, caption) end end @@ -307,7 +307,7 @@ def close_current_tagged_section(level) end def headline(level, label, caption) - @strategy.headline level, label, caption + @strategy.headline(level, label, caption) end def tagged_section_init @@ -318,17 +318,17 @@ def open_tagged_section(tag, level, label, caption) mid = "#{tag}_begin" unless @strategy.respond_to?(mid) error "strategy does not support tagged section: #{tag}" - headline level, label, caption + headline(level, label, caption) return end - @tagged_section.push [tag, level] - @strategy.__send__ mid, level, label, caption + @tagged_section.push([tag, level]) + @strategy.__send__(mid, level, label, caption) end def close_tagged_section(tag, level) mid = "#{tag}_end" if @strategy.respond_to?(mid) - @strategy.__send__ mid, level + @strategy.__send__(mid, level) else error "strategy does not support block op: #{mid}" end @@ -347,7 +347,7 @@ def compile_ulist(f) buf = [text(line.sub(/\*+/, '').strip)] f.while_match(/\A\s+(?!\*)\S/) do |cont| - buf.push text(cont.strip) + buf.push(text(cont.strip)) end line =~ /\A\s+(\*+)/ @@ -355,7 +355,7 @@ def compile_ulist(f) if level == current_level @strategy.ul_item_end # body - @strategy.ul_item_begin buf + @strategy.ul_item_begin(buf) elsif level < current_level # down level_diff = current_level - level if level_diff != 1 @@ -363,7 +363,7 @@ def compile_ulist(f) end level = current_level @strategy.ul_begin { level } - @strategy.ul_item_begin buf + @strategy.ul_item_begin(buf) elsif level > current_level # up level_diff = level - current_level level = current_level @@ -373,7 +373,7 @@ def compile_ulist(f) end @strategy.ul_item_end # body - @strategy.ul_item_begin buf + @strategy.ul_item_begin(buf) end end @@ -391,9 +391,9 @@ def compile_olist(f) num = line.match(/(\d+)\./)[1] buf = [text(line.sub(/\d+\./, '').strip)] f.while_match(/\A\s+(?!\d+\.)\S/) do |cont| - buf.push text(cont.strip) + buf.push(text(cont.strip)) end - @strategy.ol_item buf, num + @strategy.ol_item(buf, num) end @strategy.ol_end end @@ -401,7 +401,7 @@ def compile_olist(f) def compile_dlist(f) @strategy.dl_begin while /\A\s*:/ =~ f.peek - @strategy.dt text(f.gets.sub(/\A\s*:/, '').strip) + @strategy.dt(text(f.gets.sub(/\A\s*:/, '').strip)) desc = f.break(/\A(\S|\s*:|\s+\d+\.\s|\s+\*\s)/).map { |line| text(line.strip) } @strategy.dd(desc) f.skip_blank_lines @@ -414,9 +414,9 @@ def compile_paragraph(f) buf = [] f.until_match(%r{\A//|\A\#@}) do |line| break if line.strip.empty? - buf.push text(line.sub(/^(\t+)\s*/) { |m| '' * m.size }.strip.gsub('', "\t")) + buf.push(text(line.sub(/^(\t+)\s*/) { |m| '' * m.size }.strip.gsub('', "\t"))) end - @strategy.paragraph buf + @strategy.paragraph(buf) end def read_command(f) @@ -439,9 +439,9 @@ def read_block(f, ignore_inline) buf = [] f.until_match(%r{\A//\}}) do |line| if ignore_inline - buf.push line + buf.push(line) elsif line !~ /\A\#@/ - buf.push text(line.rstrip) + buf.push(text(line.rstrip)) end end unless %r{\A//\}} =~ f.peek @@ -473,27 +473,27 @@ def parse_args(str, _name = nil) def compile_command(syntax, args, lines) unless @strategy.respond_to?(syntax.name) error "strategy does not support command: //#{syntax.name}" - compile_unknown_command args, lines + compile_unknown_command(args, lines) return end begin - syntax.check_args args + syntax.check_args(args) rescue CompileError => e error e.message args = ['(NoArgument)'] * syntax.min_argc end if syntax.block_allowed? - compile_block syntax, args, lines + compile_block(syntax, args, lines) else if lines error "block is not allowed for command //#{syntax.name}; ignore" end - compile_single syntax, args + compile_single(syntax, args) end end def compile_unknown_command(args, lines) - @strategy.unknown_command args, lines + @strategy.unknown_command(args, lines) end def compile_block(syntax, args, lines) diff --git a/lib/review/epubmaker.rb b/lib/review/epubmaker.rb index 4f4433382..cb225d2f1 100644 --- a/lib/review/epubmaker.rb +++ b/lib/review/epubmaker.rb @@ -348,7 +348,7 @@ def build_part(part, basetmpdir, htmlfile) @stylesheets = @producer.config['stylesheet'] tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR) tmpl = ReVIEW::Template.load(tmplfile) - f.write tmpl.result(binding) + f.write(tmpl.result(binding)) end end @@ -567,7 +567,7 @@ def build_titlepage(basetmpdir, htmlfile) @stylesheets = @producer.config['stylesheet'] tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR) tmpl = ReVIEW::Template.load(tmplfile) - f.write tmpl.result(binding) + f.write(tmpl.result(binding)) end end diff --git a/lib/review/htmlbuilder.rb b/lib/review/htmlbuilder.rb index b0c5d5f7a..b591cbb22 100644 --- a/lib/review/htmlbuilder.rb +++ b/lib/review/htmlbuilder.rb @@ -374,11 +374,11 @@ def read(lines) def list(lines, id, caption, lang = nil) puts %Q(
) begin - list_header id, caption, lang + list_header(id, caption, lang) rescue KeyError error "no such list: #{id}" end - list_body id, lines, lang + list_body(id, lines, lang) puts '
' end @@ -403,8 +403,8 @@ def list_body(_id, lines, lang) def source(lines, caption = nil, lang = nil) puts %Q(
) - source_header caption - source_body caption, lines, lang + source_header(caption) + source_body(caption, lines, lang) puts '
' end @@ -425,11 +425,11 @@ def source_body(_id, lines, lang) def listnum(lines, id, caption, lang = nil) puts %Q(
) begin - list_header id, caption, lang + list_header(id, caption, lang) rescue KeyError error "no such list: #{id}" end - listnum_body lines, lang + listnum_body(lines, lang) puts '
' end @@ -540,7 +540,7 @@ def talk(lines) def texequation(lines, id = nil, caption = '') if id - texequation_header id, caption + texequation_header(id, caption) end texequation_body(lines) @@ -615,7 +615,7 @@ def image_image(id, caption, metric) metrics = parse_metric('html', metric) puts %Q(
) puts %Q(#{escape(compile_inline(caption))}) - image_header id, caption + image_header(id, caption) puts '
' end @@ -627,7 +627,7 @@ def image_dummy(id, caption, lines) puts detab(line) end puts '' - image_header id, caption + image_header(id, caption) puts '' end @@ -663,12 +663,12 @@ def table(lines, id = nil, caption = nil) end begin if caption.present? - table_header id, caption + table_header(id, caption) end rescue KeyError error "no such table: #{id}" end - table_begin rows.first.size + table_begin(rows.first.size) if sepidx sepidx.times do tr(rows.shift.map { |s| th(s) }) @@ -719,14 +719,14 @@ def table_end def imgtable(lines, id, caption = nil, metric = nil) unless @chapter.image(id).bound? warn "image not bound: #{id}" - image_dummy id, caption, lines + image_dummy(id, caption, lines) return end puts %Q(
) begin if caption.present? - table_header id, caption + table_header(id, caption) end rescue KeyError error "no such table: #{id}" @@ -749,7 +749,7 @@ def emtable(lines, caption = nil) def comment(lines, comment = nil) return unless @book.config['draft'] lines ||= [] - lines.unshift escape(comment) unless comment.blank? + lines.unshift(escape(comment)) unless comment.blank? str = lines.join('
') puts %Q(
#{str}
) end @@ -977,8 +977,8 @@ def text(str) def bibpaper(lines, id, caption) puts %Q(
) - bibpaper_header id, caption - bibpaper_bibpaper id, caption, lines unless lines.empty? + bibpaper_header(id, caption) + bibpaper_bibpaper(id, caption, lines) unless lines.empty? puts '
' end diff --git a/lib/review/htmltoc.rb b/lib/review/htmltoc.rb index cad80e1f2..ad859520e 100644 --- a/lib/review/htmltoc.rb +++ b/lib/review/htmltoc.rb @@ -8,7 +8,7 @@ def initialize(basedir) def add_item(level, filename, title, args) args_str = encode_args(args) line = [level, filename, title, args_str].join("\t") - File.open(tocfilename, 'a') { |f| f.write "#{line}\n" } + File.open(tocfilename, 'a') { |f| f.write("#{line}\n") } end def each_item diff --git a/lib/review/i18n.rb b/lib/review/i18n.rb index a8d98b4e6..4c524b238 100644 --- a/lib/review/i18n.rb +++ b/lib/review/i18n.rb @@ -90,7 +90,7 @@ def update_localefile(path) end else user_i18n.each do |key, values| - raise KeyError, "Invalid locale file: #{path}" unless values.is_a? Hash + raise KeyError, "Invalid locale file: #{path}" unless values.is_a?(Hash) @store[key].merge!(values) end end @@ -165,7 +165,7 @@ def t(str, args = nil) end end remove_args.reverse_each do |idx| - args.delete_at idx + args.delete_at(idx) end args_matched = (frmt.count('%') <= args.size) frmt.gsub!('##', '%%') diff --git a/lib/review/idgxmlbuilder.rb b/lib/review/idgxmlbuilder.rb index a52cf1ab9..c1a5202cf 100644 --- a/lib/review/idgxmlbuilder.rb +++ b/lib/review/idgxmlbuilder.rb @@ -303,7 +303,7 @@ def list_body(_id, lines, _lang) end def emlist(lines, caption = nil, _lang = nil) - quotedlist lines, 'emlist', caption + quotedlist(lines, 'emlist', caption) end def emlistnum(lines, caption = nil, _lang = nil) @@ -312,7 +312,7 @@ def emlistnum(lines, caption = nil, _lang = nil) lines.each_with_index do |line, i| lines2 << detab(%Q() + (i + first_line_num).to_s.rjust(2) + ': ' + line) end - quotedlist lines2, 'emlistnum', caption + quotedlist(lines2, 'emlistnum', caption) end def listnum_body(lines, _lang) @@ -335,7 +335,7 @@ def listnum_body(lines, _lang) end def cmd(lines, caption = nil) - quotedlist lines, 'cmd', caption + quotedlist(lines, 'cmd', caption) end def quotedlist(lines, css_class, caption) @@ -400,7 +400,7 @@ def image_image(id, caption, metric = nil) metrics = parse_metric('idgxml', metric) puts '' puts %Q() - image_header id, caption + image_header(id, caption) puts '' end @@ -412,7 +412,7 @@ def image_dummy(id, caption, lines) print "\n" end print '' - image_header id, caption + image_header(id, caption) puts '' warn "image not bound: #{id}" end @@ -492,7 +492,7 @@ def table(lines, id = nil, caption = nil) end begin - table_header id, caption if caption.present? + table_header(id, caption) if caption.present? rescue KeyError error "no such table: #{id}" end @@ -575,19 +575,19 @@ def imgtable(lines, id, caption = nil, metric = nil) if @chapter.image(id).bound? metrics = parse_metric('idgxml', metric) puts '' - table_header id, caption if caption.present? + table_header(id, caption) if caption.present? puts %Q() puts '
' else warn "image not bound: #{id}" if @strict - image_dummy id, caption, lines + image_dummy(id, caption, lines) end end def comment(lines, comment = nil) return unless @book.config['draft'] lines ||= [] - lines.unshift escape(comment) unless comment.blank? + lines.unshift(escape(comment)) unless comment.blank? str = lines.join("\n") print "#{str}" end @@ -1137,8 +1137,8 @@ def source_body(lines, _lang) end def bibpaper(lines, id, caption) - bibpaper_header id, caption - bibpaper_bibpaper id, caption, lines unless lines.empty? + bibpaper_header(id, caption) + bibpaper_bibpaper(id, caption, lines) unless lines.empty? puts '' end diff --git a/lib/review/init.rb b/lib/review/init.rb index 91031f3ca..602a4e95d 100644 --- a/lib/review/init.rb +++ b/lib/review/init.rb @@ -98,7 +98,7 @@ def generate_dir(dir) @logger.error "#{dir} already exists." exit 1 end - FileUtils.mkdir_p dir + FileUtils.mkdir_p(dir) yield dir end @@ -110,7 +110,7 @@ def generate_sample(dir) def generate_catalog_file(dir) File.open(File.join(dir, 'catalog.yml'), 'w') do |file| - file.write <<-EOS + file.write(<<-EOS) PREDEF: CHAPS: @@ -157,26 +157,26 @@ def generate_config(dir) end def generate_style(dir) - FileUtils.cp File.join(@review_dir, 'samples/sample-book/src/style.css'), dir + FileUtils.cp(File.join(@review_dir, 'samples/sample-book/src/style.css'), dir) end def generate_texmacro(dir) texmacrodir = File.join(dir, 'sty') - FileUtils.mkdir_p texmacrodir + FileUtils.mkdir_p(texmacrodir) tdir = File.join(@review_dir, 'templates/latex', @template) @logger.error "#{tdir} not found." unless File.exist?(tdir) - FileUtils.cp Dir.glob(File.join(tdir, '*.*')), texmacrodir + FileUtils.cp(Dir.glob(File.join(tdir, '*.*')), texmacrodir) # provide jsbook from vendor/. current version is 2018/06/23 - FileUtils.cp File.join(@review_dir, 'vendor/jsclasses/jsbook.cls'), File.join(texmacrodir, 'jsbook.cls') + FileUtils.cp(File.join(@review_dir, 'vendor/jsclasses/jsbook.cls'), File.join(texmacrodir, 'jsbook.cls')) # provide gentombow from vendor/. current version is 2018/08/30 v0.9j - FileUtils.cp File.join(@review_dir, 'vendor/gentombow/gentombow.sty'), File.join(texmacrodir, 'gentombow.sty') + FileUtils.cp(File.join(@review_dir, 'vendor/gentombow/gentombow.sty'), File.join(texmacrodir, 'gentombow.sty')) end def generate_rakefile(dir) - FileUtils.mkdir_p File.join(dir, 'lib/tasks') + FileUtils.mkdir_p(File.join(dir, 'lib/tasks')) File.open(File.join(dir, 'Rakefile'), 'w') do |file| - file.write <<-EOS + file.write(<<-EOS) Dir.glob('lib/tasks/*.rake').sort.each do |file| load(file) end @@ -188,12 +188,12 @@ def generate_rakefile(dir) end def generate_locale(dir) - FileUtils.cp File.join(@review_dir, 'lib/review/i18n.yml'), File.join(dir, 'locale.yml') + FileUtils.cp(File.join(@review_dir, 'lib/review/i18n.yml'), File.join(dir, 'locale.yml')) end def generate_gemfile(dir) File.open(File.join(dir, 'Gemfile'), 'w') do |file| - file.write <<-EOS + file.write(<<-EOS) source 'https://rubygems.org' gem 'rake' @@ -204,9 +204,9 @@ def generate_gemfile(dir) def generate_doc(dir) docdir = File.join(dir, 'doc') - FileUtils.mkdir_p docdir + FileUtils.mkdir_p(docdir) md_files = Dir.glob(File.join(@review_dir, 'doc/*.md')).map.to_a - FileUtils.cp md_files, docdir + FileUtils.cp(md_files, docdir) end def download_and_extract_archive(dir, filename) @@ -228,7 +228,7 @@ def download_and_extract_archive(dir, filename) Tempfile.create('reviewinit') do |f| zipfilename = f.path - f.write zipdata + f.write(zipdata) extract_archive(dir, zipfilename, filename) end diff --git a/lib/review/latexbuilder.rb b/lib/review/latexbuilder.rb index d986d84d1..5e2e42318 100644 --- a/lib/review/latexbuilder.rb +++ b/lib/review/latexbuilder.rb @@ -319,7 +319,7 @@ def parasep end def read(lines) - latex_block 'quotation', lines + latex_block('quotation', lines) end alias_method :lead, :read @@ -782,7 +782,7 @@ def emtable(lines, caption = nil) def imgtable(lines, id, caption = nil, metric = nil) unless @chapter.image(id).bound? warn "image not bound: #{id}" - image_dummy id, caption, lines + image_dummy(id, caption, lines) return end @@ -824,17 +824,17 @@ def imgtable_image(id, _caption, metric) end def quote(lines) - latex_block 'quote', lines + latex_block('quote', lines) end def center(lines) - latex_block 'center', lines + latex_block('center', lines) end alias_method :centering, :center def flushright(lines) - latex_block 'flushright', lines + latex_block('flushright', lines) end def texequation(lines, id = nil, caption = '') @@ -883,7 +883,7 @@ def comment(lines, comment = nil) return true unless @book.config['draft'] lines ||= [] unless comment.blank? - lines.unshift escape(comment) + lines.unshift(escape(comment)) end str = lines.join('\par ') puts macro('pdfcomment', str) diff --git a/lib/review/lineinput.rb b/lib/review/lineinput.rb index b77bcc68b..3408331b5 100644 --- a/lib/review/lineinput.rb +++ b/lib/review/lineinput.rb @@ -6,7 +6,7 @@ def skip_comment_lines n = 0 while line = gets unless line.strip =~ /\A\#@/ - ungets line + ungets(line) return n end n += 1 diff --git a/lib/review/makerhelper.rb b/lib/review/makerhelper.rb index b5d823d62..293f68808 100644 --- a/lib/review/makerhelper.rb +++ b/lib/review/makerhelper.rb @@ -55,7 +55,7 @@ def copy_images_to_dir(from_dir, to_dir, options = {}) exts = options[:exts] || %w[png gif jpg jpeg svg pdf eps ai tif psd] exts_str = exts.join('|') if !is_converted && fname =~ /\.(#{exts_str})$/i - FileUtils.cp "#{from_dir}/#{fname}", to_dir + FileUtils.cp("#{from_dir}/#{fname}", to_dir) image_files << "#{from_dir}/#{fname}" end end diff --git a/lib/review/markdownbuilder.rb b/lib/review/markdownbuilder.rb index 9971195c5..df92698ab 100644 --- a/lib/review/markdownbuilder.rb +++ b/lib/review/markdownbuilder.rb @@ -260,16 +260,16 @@ def table(lines, id = nil, caption = nil) error 'no rows in the table' if rows.empty? begin - table_header id, caption unless caption.nil? + table_header(id, caption) unless caption.nil? rescue KeyError error "no such table: #{id}" end - table_begin rows.first.size + table_begin(rows.first.size) if sepidx sepidx.times do tr(rows.shift.map { |s| th(s) }) end - table_border rows.first.size + table_border(rows.first.size) rows.each do |cols| tr(cols.map { |s| td(s) }) end @@ -355,7 +355,7 @@ def comment(lines, comment = nil) return unless @book.config['draft'] lines ||= [] unless comment.blank? - lines.unshift comment + lines.unshift(comment) end str = lines.join('
') puts %Q(
#{escape(str)}
) diff --git a/lib/review/pdfmaker.rb b/lib/review/pdfmaker.rb index 71b8c8fde..8e7e7f841 100644 --- a/lib/review/pdfmaker.rb +++ b/lib/review/pdfmaker.rb @@ -281,7 +281,7 @@ def generate_pdf(yamlfile) FileUtils.cp(File.join(@path, "#{@mastertex}.pdf"), pdf_filepath) ensure - remove_entry_secure @path unless @config['debug'] + remove_entry_secure(@path) unless @config['debug'] end end @@ -454,7 +454,7 @@ def erb_config def erb_content(file) @texcompiler = File.basename(@config['texcommand'], '.*') erb = ReVIEW::Template.load(file, '-') - @logger.debug "erb processes #{File.basename(file)}" if @config['debug'] + @logger.debug("erb processes #{File.basename(file)}") if @config['debug'] erb.result(binding) end @@ -489,7 +489,7 @@ def copy_sty(dirname, copybase, extname = 'sty') f.print erb_content(File.join(dirname, fname)) end else - FileUtils.cp File.join(dirname, fname), copybase + FileUtils.cp(File.join(dirname, fname), copybase) end end end diff --git a/lib/review/plaintextbuilder.rb b/lib/review/plaintextbuilder.rb index 9c1555b1e..635c9342d 100644 --- a/lib/review/plaintextbuilder.rb +++ b/lib/review/plaintextbuilder.rb @@ -169,7 +169,7 @@ def base_parablock(_type, lines, caption = nil) end def emlist(lines, caption = nil, _lang = nil) - base_block 'emlist', lines, caption + base_block('emlist', lines, caption) end def emlistnum(lines, caption = nil, _lang = nil) @@ -189,11 +189,11 @@ def listnum_body(lines, _lang) end def cmd(lines, caption = nil) - base_block 'cmd', lines, caption + base_block('cmd', lines, caption) end def quote(lines) - base_parablock 'quote', lines, nil + base_parablock('quote', lines, nil) end def image(_lines, id, caption, _metric = nil) @@ -242,7 +242,7 @@ def table(lines, id = nil, caption = nil) rescue KeyError error "no such table: #{id}" end - table_begin rows.first.size + table_begin(rows.first.size) if sepidx sepidx.times do tr(rows.shift.map { |s| th(s) }) @@ -345,8 +345,8 @@ def inline_comment(_str) end def bibpaper(lines, id, caption) - bibpaper_header id, caption - bibpaper_bibpaper id, caption, lines unless lines.empty? + bibpaper_header(id, caption) + bibpaper_bibpaper(id, caption, lines) unless lines.empty? end def bibpaper_header(id, caption) @@ -472,87 +472,87 @@ def sup_end(_level) end def flushright(lines) - base_parablock 'flushright', lines, nil + base_parablock('flushright', lines, nil) end def centering(lines) - base_parablock 'centering', lines, nil + base_parablock('centering', lines, nil) end def note(lines, caption = nil) - base_parablock 'note', lines, caption + base_parablock('note', lines, caption) end def memo(lines, caption = nil) - base_parablock 'memo', lines, caption + base_parablock('memo', lines, caption) end def tip(lines, caption = nil) - base_parablock 'tip', lines, caption + base_parablock('tip', lines, caption) end def info(lines, caption = nil) - base_parablock 'info', lines, caption + base_parablock('info', lines, caption) end def planning(lines, caption = nil) - base_parablock 'planning', lines, caption + base_parablock('planning', lines, caption) end def best(lines, caption = nil) - base_parablock 'best', lines, caption + base_parablock('best', lines, caption) end def important(lines, caption = nil) - base_parablock 'important', lines, caption + base_parablock('important', lines, caption) end def security(lines, caption = nil) - base_parablock 'security', lines, caption + base_parablock('security', lines, caption) end def caution(lines, caption = nil) - base_parablock 'caution', lines, caption + base_parablock('caution', lines, caption) end def term(lines) - base_parablock 'term', lines, nil + base_parablock('term', lines, nil) end def link(lines, caption = nil) - base_parablock 'link', lines, caption + base_parablock('link', lines, caption) end def notice(lines, caption = nil) - base_parablock 'notice', lines, caption + base_parablock('notice', lines, caption) end def point(lines, caption = nil) - base_parablock 'point', lines, caption + base_parablock('point', lines, caption) end def shoot(lines, caption = nil) - base_parablock 'shoot', lines, caption + base_parablock('shoot', lines, caption) end def reference(lines) - base_parablock 'reference', lines, nil + base_parablock('reference', lines, nil) end def practice(lines) - base_parablock 'practice', lines, nil + base_parablock('practice', lines, nil) end def expert(lines) - base_parablock 'expert', lines, nil + base_parablock('expert', lines, nil) end def insn(lines, caption = nil) - base_block 'insn', lines, caption + base_block('insn', lines, caption) end def warning(lines, caption = nil) - base_parablock 'warning', lines, caption + base_parablock('warning', lines, caption) end alias_method :box, :insn @@ -573,7 +573,7 @@ def dtp(str) end def bpo(lines) - base_block 'bpo', lines, nil + base_block('bpo', lines, nil) end def inline_dtp(_str) @@ -623,7 +623,7 @@ def inline_chapref(id) end def source(lines, caption = nil, _lang = nil) - base_block 'source', lines, caption + base_block('source', lines, caption) end def inline_labelref(_idref) diff --git a/lib/review/preprocessor.rb b/lib/review/preprocessor.rb index bf2c3c9e3..9f05699cf 100644 --- a/lib/review/preprocessor.rb +++ b/lib/review/preprocessor.rb @@ -51,10 +51,10 @@ def initialize(repo, param) end def process(inf, outf) - init_errorutils inf + init_errorutils(inf) @f = outf begin - preproc inf + preproc(inf) rescue Errno::ENOENT => e error e.message end @@ -80,7 +80,7 @@ def preproc(f) direc = parse_directive(line, 1, 'stderr') @f.print line get_output(expand(direc.arg), direc['stderr']).each { |out| @f.print out.string } - skip_list f + skip_list(f) when /\A\#@mapfile/ direc = parse_directive(line, 1, 'eval') @@ -131,15 +131,15 @@ def replace_block(f, directive_line, newlines, with_lineno) @f.print directive_line newlines.each do |line| if with_lineno - print_number line.number + print_number(line.number) end @f.print line.string end - skip_list f + skip_list(f) end def print_number(num) - @f.printf '%4s ', (num ? num.to_s : '') + @f.printf('%4s ', (num ? num.to_s : '')) end def skip_list(f) @@ -279,7 +279,7 @@ def get_output(cmd, use_stderr) Open3.popen3(cmd) do |_stdin, stdout, stderr| out = stdout.readlines if use_stderr - out.concat stderr.readlines + out.concat(stderr.readlines) else err = stderr.readlines end @@ -403,14 +403,14 @@ def _parse_file(f) error "begin x2: #{key}" end (repo[type] ||= {})[spec] = curr[key] = [] - opened.push [type, spec] + opened.push([type, spec]) when %r{(?:\A\#@|\#@@)([a-z]+)/(\w+)\}} type = check_type($1) spec = check_spec($2) curr.delete("#{type}/#{spec}") or error "end before begin: #{type}/#{spec}" - opened.delete "#{type}/#{spec}" + opened.delete("#{type}/#{spec}") when /(?:\A\#@|\#@@)\}/ type, spec = opened.last @@ -423,17 +423,17 @@ def _parse_file(f) when /\A\#@-/ # does not increment line number. line = canonical($') - curr.each_value { |list| list.push Line.new(nil, line) } + curr.each_value { |list| list.push(Line.new(nil, line)) } else next if yacchack and line.strip == ';' line = canonical(line) - curr.each_value { |list| list.push Line.new(lineno, line) } + curr.each_value { |list| list.push(Line.new(lineno, line)) } lineno += 1 end end if curr.size > 1 - curr.delete 'WHOLE' + curr.delete('WHOLE') curr.each { |range, lines| @logger.warn "#{filename}: unclosed range: #{range} (begin @#{lines.first.number})" } raise ApplicationError, 'ERROR' end diff --git a/lib/review/rstbuilder.rb b/lib/review/rstbuilder.rb index e8c08590a..c2a88b7bd 100644 --- a/lib/review/rstbuilder.rb +++ b/lib/review/rstbuilder.rb @@ -575,87 +575,87 @@ def sup_end(_level) end def flushright(lines) - base_parablock 'flushright', lines, nil + base_parablock('flushright', lines, nil) end def centering(lines) - base_parablock 'centering', lines, nil + base_parablock('centering', lines, nil) end def note(lines, caption = nil) - base_parablock 'note', lines, caption + base_parablock('note', lines, caption) end def memo(lines, caption = nil) - base_parablock 'memo', lines, caption + base_parablock('memo', lines, caption) end def tip(lines, caption = nil) - base_parablock 'tip', lines, caption + base_parablock('tip', lines, caption) end def info(lines, caption = nil) - base_parablock 'info', lines, caption + base_parablock('info', lines, caption) end def planning(lines, caption = nil) - base_parablock 'planning', lines, caption + base_parablock('planning', lines, caption) end def best(lines, caption = nil) - base_parablock 'best', lines, caption + base_parablock('best', lines, caption) end def important(lines, caption = nil) - base_parablock 'important', lines, caption + base_parablock('important', lines, caption) end def security(lines, caption = nil) - base_parablock 'security', lines, caption + base_parablock('security', lines, caption) end def caution(lines, caption = nil) - base_parablock 'caution', lines, caption + base_parablock('caution', lines, caption) end def term(lines) - base_parablock 'term', lines, nil + base_parablock('term', lines, nil) end def link(lines, caption = nil) - base_parablock 'link', lines, caption + base_parablock('link', lines, caption) end def notice(lines, caption = nil) - base_parablock 'notice', lines, caption + base_parablock('notice', lines, caption) end def point(lines, caption = nil) - base_parablock 'point', lines, caption + base_parablock('point', lines, caption) end def shoot(lines, caption = nil) - base_parablock 'shoot', lines, caption + base_parablock('shoot', lines, caption) end def reference(lines) - base_parablock 'reference', lines, nil + base_parablock('reference', lines, nil) end def practice(lines) - base_parablock 'practice', lines, nil + base_parablock('practice', lines, nil) end def expert(lines) - base_parablock 'expert', lines, nil + base_parablock('expert', lines, nil) end def insn(lines, caption = nil) - base_block 'insn', lines, caption + base_block('insn', lines, caption) end def warning(lines, caption = nil) - base_parablock 'warning', lines, caption + base_parablock('warning', lines, caption) end alias_method :box, :insn @@ -682,7 +682,7 @@ def dtp(str) end def bpo(lines) - base_block 'bpo', lines, nil + base_block('bpo', lines, nil) end def inline_dtp(_str) @@ -714,7 +714,7 @@ def inline_chapref(id) end def source(lines, caption = nil, _lang = nil) - base_block 'source', lines, caption + base_block('source', lines, caption) end def inline_ttibold(str) diff --git a/lib/review/tocparser.rb b/lib/review/tocparser.rb index 2b3fbd9c3..305897089 100644 --- a/lib/review/tocparser.rb +++ b/lib/review/tocparser.rb @@ -43,40 +43,40 @@ def parse(f, chap) when /\A(={2,})[\[\s\{]/ lev = $1.size if lev > 5 - error! filename, f.lineno, "section level too deep: #{lev}" + error!(filename, f.lineno, "section level too deep: #{lev}") end label = get_label(line) if node_stack.empty? # missing chapter label dummy_chapter = Chapter.new(label, chap) - node_stack.push dummy_chapter - roots.push dummy_chapter + node_stack.push(dummy_chapter) + roots.push(dummy_chapter) end next if label =~ %r{\A\[/} # ex) "[/column]" sec = Section.new(lev, label.gsub(/\A\{.*?\}\s?/, '')) node_stack.pop until node_stack.last.level < sec.level - node_stack.last.add_child sec - node_stack.push sec + node_stack.last.add_child(sec) + node_stack.push(sec) when /\A=[^=]/ label = get_label(line) node_stack.clear new_chapter = Chapter.new(label, chap) - node_stack.push new_chapter - roots.push new_chapter + node_stack.push(new_chapter) + roots.push(new_chapter) when %r{\A//\w+(?:\[.*?\])*\{\s*\z} if node_stack.empty? - error! filename, f.lineno, 'list found before section label' + error!(filename, f.lineno, 'list found before section label') end node_stack.last.add_child(list = List.new) beg = f.lineno - list.add line + list.add(line) while line = f.gets break if %r{\A//\}} =~ line - list.add line + list.add(line) end - error! filename, beg, 'unterminated list' unless line + error!(filename, beg, 'unterminated list') unless line when %r{\A//\w} # do nothing @@ -87,10 +87,10 @@ def parse(f, chap) # end next if node_stack.empty? node_stack.last.add_child(par = Paragraph.new(chap)) - par.add line + par.add(line) while line = f.gets break if /\A\s*\z/ =~ line - par.add line + par.add(line) end end end @@ -124,7 +124,7 @@ def initialize(children = []) attr_reader :children def add_child(c) - @children.push c + @children.push(c) end def each_node(&block) @@ -196,7 +196,7 @@ def inspect class Chapter < Section def initialize(label, chap) - super 1, label, chap.path + super(1, label, chap.path) @chapter = chap @chapter_id = chap.id @path = chap.path diff --git a/lib/review/tocprinter.rb b/lib/review/tocprinter.rb index 22cd7a881..072aee17b 100644 --- a/lib/review/tocprinter.rb +++ b/lib/review/tocprinter.rb @@ -32,8 +32,8 @@ def print_part(part) def print_chapter(chap) chap_node = TOCParser.chapter_node(chap) - print_node 1, chap_node - print_children chap_node + print_node(1, chap_node) + print_children(chap_node) end def print?(level) @@ -48,8 +48,8 @@ def print_children(node) return unless print?(node.level + 1) node.each_section_with_index do |section, idx| unless section.blank? - print_node idx + 1, section - print_children section + print_node(idx + 1, section) + print_children(section) end end end @@ -57,14 +57,14 @@ def print_children(node) def print_node(number, node) if node.chapter? vol = node.volume - @out.printf "%3s %3dKB %6dC %5dL %s (%s)\n", + @out.printf("%3s %3dKB %6dC %5dL %s (%s)\n", chapnumstr(node.number), vol.kbytes, vol.chars, vol.lines, - node.label, node.chapter_id + node.label, node.chapter_id) else ## for section node - @out.printf "%17s %5dL %s\n", + @out.printf("%17s %5dL %s\n", '', node.estimated_lines, - " #{' ' * (node.level - 1)}#{number} #{node.label}" + " #{' ' * (node.level - 1)}#{number} #{node.label}") end end diff --git a/lib/review/topbuilder.rb b/lib/review/topbuilder.rb index b6489a45c..962d29a89 100644 --- a/lib/review/topbuilder.rb +++ b/lib/review/topbuilder.rb @@ -218,11 +218,11 @@ def table(lines, id = nil, caption = nil) puts "◆→開始:#{@titles['table']}←◆" begin - table_header id, caption if caption.present? + table_header(id, caption) if caption.present? rescue KeyError error "no such table: #{id}" end - table_begin rows.first.size + table_begin(rows.first.size) if sepidx sepidx.times do tr(rows.shift.map { |s| th(s) }) @@ -252,7 +252,7 @@ def comment(lines, comment = nil) return unless @book.config['draft'] lines ||= [] unless comment.blank? - lines.unshift comment + lines.unshift(comment) end str = lines.join("\n") puts "◆→#{str}←◆" diff --git a/lib/review/update.rb b/lib/review/update.rb index 5ac1ffc72..b62b2f790 100644 --- a/lib/review/update.rb +++ b/lib/review/update.rb @@ -126,7 +126,7 @@ def rewrite_yml(yml, key, val) content = File.read(yml) content.gsub!(/^(\s*)#{key}:.*$/, '\1' + "#{key}: #{val}") if @backup - FileUtils.mv yml, "#{yml}-old" + FileUtils.mv(yml, "#{yml}-old") end File.write(yml, content) end @@ -257,7 +257,7 @@ def update_version def update_rakefile(dir) taskdir = File.join(dir, 'lib/tasks') unless File.exist?(taskdir) - FileUtils.mkdir_p taskdir + FileUtils.mkdir_p(taskdir) end master_rakefile = File.join(@review_dir, 'samples/sample-book/src/Rakefile') @@ -266,13 +266,13 @@ def update_rakefile(dir) if File.exist?(target_rakefile) if Digest::SHA256.hexdigest(File.read(target_rakefile)) != Digest::SHA256.hexdigest(File.read(master_rakefile)) if confirm('%s will be overridden with Re:VIEW version (%s). Do you really proceed?', ['Rakefile', master_rakefile]) - FileUtils.mv target_rakefile, "#{target_rakefile}-old" - FileUtils.cp master_rakefile, target_rakefile + FileUtils.mv(target_rakefile, "#{target_rakefile}-old") + FileUtils.cp(master_rakefile, target_rakefile) end end else @logger.info t('new file %s is created.', [target_rakefile]) unless @force - FileUtils.cp master_rakefile, target_rakefile + FileUtils.cp(master_rakefile, target_rakefile) end master_rakefile = File.join(@review_dir, 'samples/sample-book/src/lib/tasks/review.rake') @@ -280,13 +280,13 @@ def update_rakefile(dir) if File.exist?(target_rakefile) if Digest::SHA256.hexdigest(File.read(target_rakefile)) != Digest::SHA256.hexdigest(File.read(master_rakefile)) if confirm('%s will be overridden with Re:VIEW version (%s). Do you really proceed?', ['lib/tasks/review.rake', master_rakefile]) - FileUtils.mv target_rakefile, "#{target_rakefile}-old" - FileUtils.cp master_rakefile, target_rakefile + FileUtils.mv(target_rakefile, "#{target_rakefile}-old") + FileUtils.cp(master_rakefile, target_rakefile) end end else @logger.info t('new file %s is created.', [target_rakefile]) unless @force - FileUtils.cp master_rakefile, target_rakefile + FileUtils.cp(master_rakefile, target_rakefile) end end @@ -469,7 +469,7 @@ def convert_documentclass_opts(yml, cls, prev_opts) def update_tex_stys(template, dir) texmacrodir = File.join(dir, 'sty') unless File.exist?(texmacrodir) - FileUtils.mkdir texmacrodir + FileUtils.mkdir(texmacrodir) end tdir = File.join(@review_dir, 'templates/latex', template) @@ -479,7 +479,7 @@ def update_tex_stys(template, dir) unless File.exist?(target_styfile) # just copy @logger.info t('new file %s is created.', [target_styfile]) unless @force - FileUtils.cp master_styfile, target_styfile + FileUtils.cp(master_styfile, target_styfile) next end if File.basename(target_styfile) == 'review-custom.sty' @@ -492,20 +492,20 @@ def update_tex_stys(template, dir) end if confirm('%s will be overridden with Re:VIEW version (%s). Do you really proceed?', [target_styfile, master_styfile]) - FileUtils.mv target_styfile, "#{target_styfile}-old" - FileUtils.cp master_styfile, target_styfile + FileUtils.mv(target_styfile, "#{target_styfile}-old") + FileUtils.cp(master_styfile, target_styfile) end end if template == 'review-jsbook' unless File.exist?(File.join(texmacrodir, 'jsbook.cls')) @logger.info t('new file %s is created.', [File.join(texmacrodir, 'jsbook.cls')]) unless @force - FileUtils.cp File.join(@review_dir, 'vendor/jsclasses/jsbook.cls'), File.join(texmacrodir, 'jsbook.cls') + FileUtils.cp(File.join(@review_dir, 'vendor/jsclasses/jsbook.cls'), File.join(texmacrodir, 'jsbook.cls')) end unless File.exist?(File.join(texmacrodir, 'gentombow.sty')) @logger.info t('new file %s is created.', [File.join(texmacrodir, 'gentombow.sty')]) unless @force - FileUtils.cp File.join(@review_dir, 'vendor/gentombow/gentombow.sty'), File.join(texmacrodir, 'gentombow.sty') + FileUtils.cp(File.join(@review_dir, 'vendor/gentombow/gentombow.sty'), File.join(texmacrodir, 'gentombow.sty')) end end end diff --git a/lib/review/webmaker.rb b/lib/review/webmaker.rb index ee7b6afad..d68c77567 100644 --- a/lib/review/webmaker.rb +++ b/lib/review/webmaker.rb @@ -164,7 +164,7 @@ def build_part(part, basetmpdir, htmlfile) @language = @config['language'] @stylesheets = @config['stylesheet'] tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR) - f.write ReVIEW::Template.load(tmplfile).result(binding) + f.write(ReVIEW::Template.load(tmplfile).result(binding)) end end @@ -269,7 +269,7 @@ def build_indexpage(basetmpdir) @next = @book.chapters[0] @next_title = @next ? @next.title : '' tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR) - f.write ReVIEW::Template.load(tmplfile).result(binding) + f.write(ReVIEW::Template.load(tmplfile).result(binding)) end end @@ -289,7 +289,7 @@ def build_titlepage(basetmpdir, htmlfile) @language = @config['language'] @stylesheets = @config['stylesheet'] tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR) - f.write ReVIEW::Template.load(tmplfile).result(binding) + f.write(ReVIEW::Template.load(tmplfile).result(binding)) end end diff --git a/review.gemspec b/review.gemspec index ae444a117..fcdbe569d 100644 --- a/review.gemspec +++ b/review.gemspec @@ -1,4 +1,4 @@ -$LOAD_PATH.push File.expand_path('lib', __dir__) +$LOAD_PATH.push(File.expand_path('lib', __dir__)) require 'review/version' Gem::Specification.new do |gem| @@ -11,7 +11,7 @@ Gem::Specification.new do |gem| gem.homepage = 'http://github.com/kmuto/review' gem.summary = 'Re:VIEW: a easy-to-use digital publishing system' gem.description = 'Re:VIEW is a digital publishing system for books and ebooks. It supports InDesign, EPUB and LaTeX.' - gem.required_rubygems_version = Gem::Requirement.new('>= 0') if gem.respond_to? :required_rubygems_version= + gem.required_rubygems_version = Gem::Requirement.new('>= 0') if gem.respond_to?(:required_rubygems_version=) gem.date = '2019-06-29' gem.files = `git ls-files`.split("\n") diff --git a/samples/sample-book/src/lib/tasks/review.rake b/samples/sample-book/src/lib/tasks/review.rake index 73394739c..c03fa258e 100644 --- a/samples/sample-book/src/lib/tasks/review.rake +++ b/samples/sample-book/src/lib/tasks/review.rake @@ -33,13 +33,13 @@ IDGXMLROOT = BOOK + '-idgxml' IDGXML_OPTIONS = ENV['REVIEW_IDGXML_OPTIONS'] || '' def build(mode, chapter) - sh "review-compile --target=#{mode} --footnotetext --stylesheet=style.css #{chapter} > tmp" + sh("review-compile --target=#{mode} --footnotetext --stylesheet=style.css #{chapter} > tmp") mode_ext = { 'html' => 'html', 'latex' => 'tex', 'idgxml' => 'xml', 'top' => 'txt', 'plaintext' => 'txt' } - FileUtils.mv 'tmp', chapter.gsub(/re\z/, mode_ext[mode]) + FileUtils.mv('tmp', chapter.gsub(/re\z/, mode_ext[mode])) end def build_all(mode) - sh "review-compile --target=#{mode} --footnotetext --stylesheet=style.css" + sh("review-compile --target=#{mode} --footnotetext --stylesheet=style.css") end task default: :html_all @@ -99,26 +99,26 @@ SRC_EPUB = FileList['*.css'] SRC_PDF = FileList['layouts/*.erb', 'sty/**/*.sty'] file BOOK_PDF => SRC + SRC_PDF do - FileUtils.rm_rf [BOOK_PDF, BOOK, BOOK + '-pdf'] + FileUtils.rm_rf([BOOK_PDF, BOOK, BOOK + '-pdf']) sh "review-pdfmaker #{CONFIG_FILE}" end file BOOK_EPUB => SRC + SRC_EPUB do - FileUtils.rm_rf [BOOK_EPUB, BOOK, BOOK + '-epub'] + FileUtils.rm_rf([BOOK_EPUB, BOOK, BOOK + '-epub']) sh "review-epubmaker #{CONFIG_FILE}" end file WEBROOT => SRC do - FileUtils.rm_rf [WEBROOT] + FileUtils.rm_rf([WEBROOT]) sh "review-webmaker #{CONFIG_FILE}" end file TEXTROOT => SRC do - FileUtils.rm_rf [TEXTROOT] + FileUtils.rm_rf([TEXTROOT]) end file IDGXMLROOT => SRC do - FileUtils.rm_rf [IDGXMLROOT] + FileUtils.rm_rf([IDGXMLROOT]) end CLEAN.include([BOOK, BOOK_PDF, BOOK_EPUB, BOOK + '-pdf', BOOK + '-epub', WEBROOT, 'images/_review_math', 'images/_review_math_text', TEXTROOT, IDGXMLROOT]) diff --git a/samples/sample-book/src/lib/tasks/z01_copy_sty.rake b/samples/sample-book/src/lib/tasks/z01_copy_sty.rake index de7026795..c6a5b94e4 100644 --- a/samples/sample-book/src/lib/tasks/z01_copy_sty.rake +++ b/samples/sample-book/src/lib/tasks/z01_copy_sty.rake @@ -4,12 +4,12 @@ task :copy_sty do jsbook_dir = File.join(review_rootdir, 'templates/latex/review-jsbook') gentombow_dir = File.join(review_rootdir, 'vendor/gentombow') Dir.glob(File.join(jsbook_dir, '*.cls')) do |file| - FileUtils.cp file, 'sty' + FileUtils.cp(file, 'sty') end Dir.glob(File.join(jsbook_dir, 'review-*.sty')) do |file| - FileUtils.cp file, 'sty' + FileUtils.cp(file, 'sty') end - FileUtils.cp File.join(gentombow_dir, 'gentombow.sty'), 'sty/gentombow.sty' + FileUtils.cp(File.join(gentombow_dir, 'gentombow.sty'), 'sty/gentombow.sty') end CLEAN.include([Dir.glob('sty/review-*.sty'), 'sty/review-jsbook.cls', 'sty/gentombow.sty']) diff --git a/samples/syntax-book/lib/tasks/review.rake b/samples/syntax-book/lib/tasks/review.rake index 4c3d362e9..579a32f79 100644 --- a/samples/syntax-book/lib/tasks/review.rake +++ b/samples/syntax-book/lib/tasks/review.rake @@ -31,13 +31,13 @@ TEXTROOT = BOOK + '-text' TOPROOT = BOOK + '-text' def build(mode, chapter) - sh "review-compile --target=#{mode} --footnotetext --stylesheet=style.css #{chapter} > tmp" + sh("review-compile --target=#{mode} --footnotetext --stylesheet=style.css #{chapter} > tmp") mode_ext = { 'html' => 'html', 'latex' => 'tex', 'idgxml' => 'xml', 'top' => 'txt', 'plaintext' => 'txt' } - FileUtils.mv 'tmp', chapter.gsub(/re\z/, mode_ext[mode]) + FileUtils.mv('tmp', chapter.gsub(/re\z/, mode_ext[mode])) end def build_all(mode) - sh "review-compile --target=#{mode} --footnotetext --stylesheet=style.css" + sh("review-compile --target=#{mode} --footnotetext --stylesheet=style.css") end task default: :html_all @@ -92,22 +92,22 @@ SRC_EPUB = FileList['*.css'] SRC_PDF = FileList['layouts/*.erb', 'sty/**/*.sty'] file BOOK_PDF => SRC + SRC_PDF do - FileUtils.rm_rf [BOOK_PDF, BOOK, BOOK + '-pdf'] + FileUtils.rm_rf([BOOK_PDF, BOOK, BOOK + '-pdf']) sh "review-pdfmaker #{CONFIG_FILE}" end file BOOK_EPUB => SRC + SRC_EPUB do - FileUtils.rm_rf [BOOK_EPUB, BOOK, BOOK + '-epub'] + FileUtils.rm_rf([BOOK_EPUB, BOOK, BOOK + '-epub']) sh "review-epubmaker #{CONFIG_FILE}" end file WEBROOT => SRC do - FileUtils.rm_rf [WEBROOT] + FileUtils.rm_rf([WEBROOT]) sh "review-webmaker #{CONFIG_FILE}" end file TEXTROOT => SRC do - FileUtils.rm_rf [TEXTROOT] + FileUtils.rm_rf([TEXTROOT]) end CLEAN.include([BOOK, BOOK_PDF, BOOK_EPUB, BOOK + '-pdf', BOOK + '-epub', WEBROOT, 'images/_review_math', TEXTROOT]) diff --git a/samples/syntax-book/lib/tasks/z01_copy_sty.rake b/samples/syntax-book/lib/tasks/z01_copy_sty.rake index 3f99e9964..eb739b076 100644 --- a/samples/syntax-book/lib/tasks/z01_copy_sty.rake +++ b/samples/syntax-book/lib/tasks/z01_copy_sty.rake @@ -4,12 +4,12 @@ task :copy_sty do jsbook_dir = File.join(review_rootdir, 'templates/latex/review-jsbook') gentombow_dir = File.join(review_rootdir, 'vendor/gentombow') Dir.glob(File.join(jsbook_dir, '*.cls')) do |file| - FileUtils.cp file, 'sty' + FileUtils.cp(file, 'sty') end Dir.glob(File.join(jsbook_dir, 'review-*.sty')) do |file| - FileUtils.cp file, 'sty' + FileUtils.cp(file, 'sty') end - FileUtils.cp File.join(gentombow_dir, 'gentombow.sty'), 'sty/gentombow.sty' + FileUtils.cp(File.join(gentombow_dir, 'gentombow.sty'), 'sty/gentombow.sty') end CLEAN.include([Dir.glob('sty/review-*.sty'), 'sty/review-jsbook.cls', 'sty/gentombow.sty']) diff --git a/test/test_catalog.rb b/test/test_catalog.rb index d10e5c78b..98e277cf8 100644 --- a/test/test_catalog.rb +++ b/test/test_catalog.rb @@ -154,7 +154,7 @@ def test_validate_contentdir private def yaml - StringIO.new <<-EOS + StringIO.new(<<-EOS) PREDEF: - pre01.re @@ -182,7 +182,7 @@ def yaml_hash end def yaml_with_parts - StringIO.new <<-EOS + StringIO.new(<<-EOS) CHAPS: - ch01.re - part1.re: diff --git a/test/test_catalog_converter_cmd.rb b/test/test_catalog_converter_cmd.rb index 6d5c9202b..b219d1e36 100644 --- a/test/test_catalog_converter_cmd.rb +++ b/test/test_catalog_converter_cmd.rb @@ -4,7 +4,7 @@ require 'yaml' require 'rbconfig' -load File.expand_path('../bin/review-catalog-converter', File.dirname(__FILE__)) +load(File.expand_path('../bin/review-catalog-converter', File.dirname(__FILE__))) class CatalogConverterCmdTest < Test::Unit::TestCase def test_parse_chaps diff --git a/test/test_epubmaker_cmd.rb b/test/test_epubmaker_cmd.rb index 3dc8e219c..8fb5634e2 100644 --- a/test/test_epubmaker_cmd.rb +++ b/test/test_epubmaker_cmd.rb @@ -16,8 +16,8 @@ def setup end def teardown - FileUtils.rm_rf @tmpdir1 - FileUtils.rm_rf @tmpdir2 + FileUtils.rm_rf(@tmpdir1) + FileUtils.rm_rf(@tmpdir2) ENV['RUBYLIB'] = @old_rubylib end diff --git a/test/test_htmlbuilder.rb b/test/test_htmlbuilder.rb index d77edca67..599754842 100644 --- a/test/test_htmlbuilder.rb +++ b/test/test_htmlbuilder.rb @@ -348,7 +348,7 @@ def @chapter.image(_id) item end - actual = compile_block "@{sampleimg}\n" + actual = compile_block("@{sampleimg}\n") expected = %Q(

図1.1

\n) assert_equal expected, actual end @@ -360,7 +360,7 @@ def @chapter.image(_id) item end - actual = compile_block "@{sampleimg}\n" + actual = compile_block("@{sampleimg}\n") expected = %Q(

図1.1「sample photo」

\n) assert_equal expected, actual end @@ -372,7 +372,7 @@ def @chapter.image(_id) item end - actual = compile_block "@{sampleimg}\n" + actual = compile_block("@{sampleimg}\n") expected = %Q(

図1.1

\n) assert_equal expected, actual end @@ -2158,7 +2158,7 @@ def test_inline_fence def test_inline_w Dir.mktmpdir do |dir| File.open(File.join(dir, 'words.csv'), 'w') do |f| - f.write <_@{BAZ}" EOB diff --git a/test/test_i18n.rb b/test/test_i18n.rb index 12ff7daee..32b159e46 100644 --- a/test/test_i18n.rb +++ b/test/test_i18n.rb @@ -157,23 +157,23 @@ def test_custom_format_numbers Dir.chdir(dir) do file = File.join(dir, 'locale.yml') - File.open(file, 'w') { |f| f.write %Q(locale: ja\nformat_number_header: "%s-%pA:") } + File.open(file, 'w') { |f| f.write(%Q(locale: ja\nformat_number_header: "%s-%pA:")) } I18n.setup('ja') assert_equal '1-B:', I18n.t('format_number_header', [1, 2]) - File.open(file, 'w') { |f| f.write %Q(locale: ja\nformat_number_header: "%s.%pa:") } + File.open(file, 'w') { |f| f.write(%Q(locale: ja\nformat_number_header: "%s.%pa:")) } I18n.setup('ja') assert_equal '2.c:', I18n.t('format_number_header', [2, 3]) - File.open(file, 'w') { |f| f.write %Q(locale: ja\nformat_number_header: "%pA,%pAW:") } + File.open(file, 'w') { |f| f.write(%Q(locale: ja\nformat_number_header: "%pA,%pAW:")) } I18n.setup('ja') assert_equal 'C,D:', I18n.t('format_number_header', [3, 4]) - File.open(file, 'w') { |f| f.write %Q(locale: ja\nformat_number_header: "%pJ・%pJ:") } + File.open(file, 'w') { |f| f.write(%Q(locale: ja\nformat_number_header: "%pJ・%pJ:")) } I18n.setup('ja') assert_equal '十二・二十六:', I18n.t('format_number_header', [12, 26]) - File.open(file, 'w') { |f| f.write %Q(locale: ja\nformat_number_header: "%pdW―%pdW:") } + File.open(file, 'w') { |f| f.write(%Q(locale: ja\nformat_number_header: "%pdW―%pdW:")) } I18n.setup('ja') assert_equal '3―12:', I18n.t('format_number_header', [3, 12]) end @@ -185,11 +185,11 @@ def test_format_with_mismatched_number_of_arguments Dir.chdir(dir) do file = File.join(dir, 'locale.yml') - File.open(file, 'w') { |f| f.write %Q(locale: ja\nformat_number_header: "%2$d") } + File.open(file, 'w') { |f| f.write(%Q(locale: ja\nformat_number_header: "%2$d")) } I18n.setup('ja') assert_equal '10', I18n.t('format_number_header', [1, 10]) - File.open(file, 'w') { |f| f.write %Q(locale: ja\nformat_number_header: "%2$d-%1$d") } + File.open(file, 'w') { |f| f.write(%Q(locale: ja\nformat_number_header: "%2$d-%1$d")) } I18n.setup('ja') # ERROR: returns raw format assert_equal '%2$d-%1$d', I18n.t('format_number_header', [1]) @@ -215,7 +215,7 @@ def test_ja_with_user_i18n end def test_en - I18n.setup 'en' + I18n.setup('en') assert_equal 'Figure ', I18n.t('image') assert_equal 'Table ', I18n.t('table') assert_equal 'Chapter 1', I18n.t('chapter', 1) @@ -223,7 +223,7 @@ def test_en end def test_nil - I18n.setup 'nil' + I18n.setup('nil') assert_equal 'image', I18n.t('image') assert_equal 'table', I18n.t('table') assert_equal 'etc', I18n.t('etc') @@ -236,7 +236,7 @@ def test_htmlbuilder end def _setup_htmlbuilder - I18n.setup 'en' + I18n.setup('en') @builder = HTMLBuilder.new @config = ReVIEW::Configure[ 'secnolevel' => 2, # for IDGXMLBuilder, HTMLBuilder @@ -295,6 +295,6 @@ def test_i18n_error end def teardown - I18n.setup 'ja' + I18n.setup('ja') end end diff --git a/test/test_idgxmlbuilder.rb b/test/test_idgxmlbuilder.rb index b959fad2d..e627ea872 100644 --- a/test/test_idgxmlbuilder.rb +++ b/test/test_idgxmlbuilder.rb @@ -782,7 +782,7 @@ def @chapter.image(_id) item end - actual = compile_block "@{sampleimg}\n" + actual = compile_block("@{sampleimg}\n") expected = %Q(

図1.1「sample photo」

) assert_equal expected, actual end @@ -794,7 +794,7 @@ def @chapter.image(_id) item end - actual = compile_block "@{sampleimg}\n" + actual = compile_block("@{sampleimg}\n") expected = %Q(

図1.1

) assert_equal expected, actual end diff --git a/test/test_image_finder.rb b/test/test_image_finder.rb index d60050490..cc428b6ba 100644 --- a/test/test_image_finder.rb +++ b/test/test_image_finder.rb @@ -19,7 +19,7 @@ def test_find_path_pattern1 finder = ReVIEW::Book::ImageFinder.new(dir, 'ch01', 'builder', ['.jpg']) assert_equal(path, finder.find_path('foo')) ensure - FileUtils.remove_entry_secure dir + FileUtils.remove_entry_secure(dir) end end @@ -33,7 +33,7 @@ def test_find_path_pattern2 finder = ReVIEW::Book::ImageFinder.new(dir, 'ch01', 'builder', ['.jpg']) assert_equal(path, finder.find_path('foo')) ensure - FileUtils.remove_entry_secure dir + FileUtils.remove_entry_secure(dir) end end @@ -47,7 +47,7 @@ def test_find_path_pattern3 finder = ReVIEW::Book::ImageFinder.new(dir, 'ch01', 'builder', ['.jpg']) assert_equal(path, finder.find_path('foo')) ensure - FileUtils.remove_entry_secure dir + FileUtils.remove_entry_secure(dir) end end @@ -61,7 +61,7 @@ def test_find_path_pattern4 finder = ReVIEW::Book::ImageFinder.new(dir, 'ch01', 'builder', ['.jpg']) assert_equal(path, finder.find_path('foo')) ensure - FileUtils.remove_entry_secure dir + FileUtils.remove_entry_secure(dir) end end @@ -75,7 +75,7 @@ def test_find_path_pattern5 finder = ReVIEW::Book::ImageFinder.new(dir, 'ch01', 'builder', ['.jpg']) assert_equal(path, finder.find_path('foo')) ensure - FileUtils.remove_entry_secure dir + FileUtils.remove_entry_secure(dir) end end @@ -93,7 +93,7 @@ def test_find_path_dir_symlink finder = ReVIEW::Book::ImageFinder.new(dir, 'ch01', 'builder', ['.jpg']) assert_equal(path_dstimg, finder.find_path('foo')) ensure - FileUtils.remove_entry_secure dir + FileUtils.remove_entry_secure(dir) end end end diff --git a/test/test_latexbuilder.rb b/test/test_latexbuilder.rb index 773c848ee..a7c6b409b 100644 --- a/test/test_latexbuilder.rb +++ b/test/test_latexbuilder.rb @@ -1535,7 +1535,7 @@ def @chapter.image(_id) item end - actual = compile_block "@{sampleimg}\n" + actual = compile_block("@{sampleimg}\n") expected = "\n\\reviewimageref{1.1}{image:chap1:sampleimg}「sample photo」\n" assert_equal expected, actual end @@ -1547,7 +1547,7 @@ def @chapter.image(_id) item end - actual = compile_block "@{sampleimg}\n" + actual = compile_block("@{sampleimg}\n") expected = "\n\\reviewimageref{1.1}{image:chap1:sampleimg}\n" assert_equal expected, actual end @@ -1616,7 +1616,7 @@ def test_inline_fence def test_inline_w Dir.mktmpdir do |dir| File.open(File.join(dir, 'words.csv'), 'w') do |f| - f.write <_@{BAZ}" EOB diff --git a/test/test_latexbuilder_v2.rb b/test/test_latexbuilder_v2.rb index ab45d9828..f515850ea 100644 --- a/test/test_latexbuilder_v2.rb +++ b/test/test_latexbuilder_v2.rb @@ -1429,7 +1429,7 @@ def @chapter.image(_id) item end - actual = compile_block "@{sampleimg}\n" + actual = compile_block("@{sampleimg}\n") expected = "\n\\reviewimageref{1.1}{image:chap1:sampleimg}「sample photo」\n" assert_equal expected, actual end @@ -1441,7 +1441,7 @@ def @chapter.image(_id) item end - actual = compile_block "@{sampleimg}\n" + actual = compile_block("@{sampleimg}\n") expected = "\n\\reviewimageref{1.1}{image:chap1:sampleimg}\n" assert_equal expected, actual end diff --git a/test/test_makerhelper.rb b/test/test_makerhelper.rb index ee7ae2d98..d92f1e3de 100644 --- a/test/test_makerhelper.rb +++ b/test/test_makerhelper.rb @@ -12,8 +12,8 @@ def setup end def teardown - FileUtils.rm_rf @tmpdir1 - FileUtils.rm_rf @tmpdir2 + FileUtils.rm_rf(@tmpdir1) + FileUtils.rm_rf(@tmpdir2) end def test_copy_images_to_dir @@ -34,7 +34,7 @@ def test_copy_images_to_dir def test_copy_images_to_dir_convert if /mswin|mingw|cygwin/ !~ RUBY_PLATFORM && (`convert -version` rescue nil) && (`gs --version` rescue nil) - FileUtils.cp File.join(assets_dir, 'black.eps'), File.join(@tmpdir1, 'foo.eps') + FileUtils.cp(File.join(assets_dir, 'black.eps'), File.join(@tmpdir1, 'foo.eps')) image_files = MakerHelper.copy_images_to_dir(@tmpdir1, @tmpdir2, convert: { eps: :png }) diff --git a/test/test_pdfmaker.rb b/test/test_pdfmaker.rb index a9efccc61..134ad495a 100644 --- a/test/test_pdfmaker.rb +++ b/test/test_pdfmaker.rb @@ -49,7 +49,7 @@ def test_buildpath_debug begin assert_equal(path, 'sample-pdf') ensure - FileUtils.remove_entry_secure path + FileUtils.remove_entry_secure(path) end end diff --git a/test/test_pdfmaker_cmd.rb b/test/test_pdfmaker_cmd.rb index e27fd051f..76b37ef21 100644 --- a/test/test_pdfmaker_cmd.rb +++ b/test/test_pdfmaker_cmd.rb @@ -15,7 +15,7 @@ def setup end def teardown - FileUtils.rm_rf @tmpdir1 + FileUtils.rm_rf(@tmpdir1) ENV['RUBYLIB'] = @old_rubylib end diff --git a/test/test_textutils.rb b/test/test_textutils.rb index 44bcbf788..d6521b236 100644 --- a/test/test_textutils.rb +++ b/test/test_textutils.rb @@ -6,7 +6,7 @@ class TextUtilsTest < Test::Unit::TestCase def setup @tu_nil = Object.new - @tu_nil.extend ReVIEW::TextUtils + @tu_nil.extend(ReVIEW::TextUtils) def @tu_nil.pre_paragraph nil end @@ -16,7 +16,7 @@ def @tu_nil.post_paragraph end @tu_p = Object.new - @tu_p.extend ReVIEW::TextUtils + @tu_p.extend(ReVIEW::TextUtils) def @tu_p.pre_paragraph '

' end diff --git a/test/test_topbuilder.rb b/test/test_topbuilder.rb index df3c39f3d..fb2a5296f 100644 --- a/test/test_topbuilder.rb +++ b/test/test_topbuilder.rb @@ -613,7 +613,7 @@ def test_texequation def test_inline_w Dir.mktmpdir do |dir| File.open(File.join(dir, 'words.csv'), 'w') do |f| - f.write <_@{BAZ}" EOB diff --git a/test/test_update.rb b/test/test_update.rb index 5b49a0363..816c20012 100644 --- a/test/test_update.rb +++ b/test/test_update.rb @@ -14,7 +14,7 @@ def setup end def teardown - FileUtils.rm_rf @tmpdir + FileUtils.rm_rf(@tmpdir) end def test_broken_yml @@ -143,7 +143,7 @@ def test_update_rakefile_same def test_update_rakefile_different File.write(File.join(@tmpdir, 'Rakefile'), '') - FileUtils.mkdir_p File.join(@tmpdir, 'lib/tasks') + FileUtils.mkdir_p(File.join(@tmpdir, 'lib/tasks')) File.write(File.join(@tmpdir, 'lib/tasks/review.rake'), '') io = StringIO.new @u.instance_eval{ @logger = ReVIEW::Logger.new(io) } diff --git a/test/test_yamlloader.rb b/test/test_yamlloader.rb index fa2591746..98e633cb1 100644 --- a/test/test_yamlloader.rb +++ b/test/test_yamlloader.rb @@ -15,7 +15,7 @@ def test_load_file Dir.mktmpdir do |dir| yaml_file = File.join(dir, 'test.yml') File.open(yaml_file, 'w') do |f| - f.write < Date: Mon, 12 Aug 2019 20:13:45 +0900 Subject: [PATCH 2/2] 'write' is allowed to omit parentheses. --- .rubocop.yml | 1 + bin/review-preproc | 2 +- bin/review-validate | 4 +-- lib/review/epubmaker.rb | 4 +-- lib/review/htmltoc.rb | 2 +- lib/review/init.rb | 10 +++---- lib/review/pdfmaker.rb | 2 +- lib/review/webmaker.rb | 6 ++--- test/test_htmlbuilder.rb | 20 +++++++------- test/test_i18n.rb | 56 +++++++++++++++++++-------------------- test/test_latexbuilder.rb | 2 +- test/test_topbuilder.rb | 2 +- test/test_yamlloader.rb | 26 +++++++++--------- 13 files changed, 69 insertions(+), 68 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 741096611..fafcf33ce 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -205,6 +205,7 @@ Style/MethodCallWithArgsParentheses: - 'exit' - 'print' - 'puts' + - 'write' - 'warn' - 'error' - 'raise' diff --git a/bin/review-preproc b/bin/review-preproc index e42f3423b..60fd9017d 100755 --- a/bin/review-preproc +++ b/bin/review-preproc @@ -104,7 +104,7 @@ def preproc(pp, path) end def File.write(path, str) - File.open(path, 'w') { |f| f.write(str) } + File.open(path, 'w') { |f| f.write str } end sigmain diff --git a/bin/review-validate b/bin/review-validate index 4277e71bf..7b57498d0 100755 --- a/bin/review-validate +++ b/bin/review-validate @@ -1,5 +1,5 @@ #!/usr/bin/env ruby -# Copyright (c) 2010-2017 Kenshi Muto +# Copyright (c) 2010-2019 Kenshi Muto # # This program is free software # You can distribute or modify this program under the terms of @@ -48,7 +48,7 @@ ARGF.each do |line| @logger.warn "#{ln}: found '*' without the head space. Is it correct?" end elsif line =~ /\A\s+(\d+\.)\s+/ && line =~ /\A\s+\*\s+/ - unless Tw[list(emlist(listnum(emlistnum(cmd(image(table))))))].include?(block) + unless %w[list emlist listnum emlistnum cmd image table].include?(block) @logger.warn "#{ln}: found itemized list or numbered list in #{block}. Is it correct?" end elsif block == 'table' diff --git a/lib/review/epubmaker.rb b/lib/review/epubmaker.rb index cb225d2f1..4f4433382 100644 --- a/lib/review/epubmaker.rb +++ b/lib/review/epubmaker.rb @@ -348,7 +348,7 @@ def build_part(part, basetmpdir, htmlfile) @stylesheets = @producer.config['stylesheet'] tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR) tmpl = ReVIEW::Template.load(tmplfile) - f.write(tmpl.result(binding)) + f.write tmpl.result(binding) end end @@ -567,7 +567,7 @@ def build_titlepage(basetmpdir, htmlfile) @stylesheets = @producer.config['stylesheet'] tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR) tmpl = ReVIEW::Template.load(tmplfile) - f.write(tmpl.result(binding)) + f.write tmpl.result(binding) end end diff --git a/lib/review/htmltoc.rb b/lib/review/htmltoc.rb index ad859520e..cad80e1f2 100644 --- a/lib/review/htmltoc.rb +++ b/lib/review/htmltoc.rb @@ -8,7 +8,7 @@ def initialize(basedir) def add_item(level, filename, title, args) args_str = encode_args(args) line = [level, filename, title, args_str].join("\t") - File.open(tocfilename, 'a') { |f| f.write("#{line}\n") } + File.open(tocfilename, 'a') { |f| f.write "#{line}\n" } end def each_item diff --git a/lib/review/init.rb b/lib/review/init.rb index 602a4e95d..9445bb325 100644 --- a/lib/review/init.rb +++ b/lib/review/init.rb @@ -110,7 +110,7 @@ def generate_sample(dir) def generate_catalog_file(dir) File.open(File.join(dir, 'catalog.yml'), 'w') do |file| - file.write(<<-EOS) + file.write <<-EOS PREDEF: CHAPS: @@ -153,7 +153,7 @@ def generate_config(dir) content.gsub!(/^#\s*texdocumentclass:.*$/, %Q(texdocumentclass: ["#{@template}", "#{TEX_DOCUMENTCLASS_OPTS[@template]}"])) end - File.open(File.join(dir, 'config.yml'), 'w') { |f| f.write(content) } + File.open(File.join(dir, 'config.yml'), 'w') { |f| f.write content } end def generate_style(dir) @@ -176,7 +176,7 @@ def generate_rakefile(dir) FileUtils.mkdir_p(File.join(dir, 'lib/tasks')) File.open(File.join(dir, 'Rakefile'), 'w') do |file| - file.write(<<-EOS) + file.write <<-EOS Dir.glob('lib/tasks/*.rake').sort.each do |file| load(file) end @@ -193,7 +193,7 @@ def generate_locale(dir) def generate_gemfile(dir) File.open(File.join(dir, 'Gemfile'), 'w') do |file| - file.write(<<-EOS) + file.write <<-EOS source 'https://rubygems.org' gem 'rake' @@ -228,7 +228,7 @@ def download_and_extract_archive(dir, filename) Tempfile.create('reviewinit') do |f| zipfilename = f.path - f.write(zipdata) + f.write zipdata extract_archive(dir, zipfilename, filename) end diff --git a/lib/review/pdfmaker.rb b/lib/review/pdfmaker.rb index 8e7e7f841..ff66d14e6 100644 --- a/lib/review/pdfmaker.rb +++ b/lib/review/pdfmaker.rb @@ -189,7 +189,7 @@ def make_input_files(book, yamlfile) def build_pdf template = template_content Dir.chdir(@path) do - File.open("./#{@mastertex}.tex", 'wb') { |f| f.write(template) } + File.open("./#{@mastertex}.tex", 'wb') { |f| f.write template } call_hook('hook_beforetexcompile') diff --git a/lib/review/webmaker.rb b/lib/review/webmaker.rb index d68c77567..ee7b6afad 100644 --- a/lib/review/webmaker.rb +++ b/lib/review/webmaker.rb @@ -164,7 +164,7 @@ def build_part(part, basetmpdir, htmlfile) @language = @config['language'] @stylesheets = @config['stylesheet'] tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR) - f.write(ReVIEW::Template.load(tmplfile).result(binding)) + f.write ReVIEW::Template.load(tmplfile).result(binding) end end @@ -269,7 +269,7 @@ def build_indexpage(basetmpdir) @next = @book.chapters[0] @next_title = @next ? @next.title : '' tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR) - f.write(ReVIEW::Template.load(tmplfile).result(binding)) + f.write ReVIEW::Template.load(tmplfile).result(binding) end end @@ -289,7 +289,7 @@ def build_titlepage(basetmpdir, htmlfile) @language = @config['language'] @stylesheets = @config['stylesheet'] tmplfile = File.expand_path(template_name, ReVIEW::Template::TEMPLATE_DIR) - f.write(ReVIEW::Template.load(tmplfile).result(binding)) + f.write ReVIEW::Template.load(tmplfile).result(binding) end end diff --git a/test/test_htmlbuilder.rb b/test/test_htmlbuilder.rb index 599754842..5adbb35ed 100644 --- a/test/test_htmlbuilder.rb +++ b/test/test_htmlbuilder.rb @@ -61,7 +61,7 @@ def test_headline_postdef_roman Dir.mktmpdir do |dir| Dir.chdir(dir) do file = File.join(dir, 'locale.yml') - File.open(file, 'w') { |f| f.write("locale: ja\nappendix: 付録%pR") } + File.open(file, 'w') { |f| f.write "locale: ja\nappendix: 付録%pR" } I18n.setup('ja') @chapter.instance_eval do def on_appendix? @@ -82,7 +82,7 @@ def test_headline_postdef_alpha Dir.mktmpdir do |dir| Dir.chdir(dir) do file = File.join(dir, 'locale.yml') - File.open(file, 'w') { |f| f.write("locale: ja\nappendix: 付録%pA") } + File.open(file, 'w') { |f| f.write "locale: ja\nappendix: 付録%pA" } I18n.setup('ja') @chapter.instance_eval do def on_appendix? @@ -261,7 +261,7 @@ def test_inline_hd_chap_postdef_roman Dir.mktmpdir do |dir| Dir.chdir(dir) do file = File.join(dir, 'locale.yml') - File.open(file, 'w') { |f| f.write("locale: ja\nappendix: 付録%pR") } + File.open(file, 'w') { |f| f.write "locale: ja\nappendix: 付録%pR" } I18n.setup('ja') @chapter.instance_eval do def on_appendix? @@ -284,7 +284,7 @@ def test_inline_hd_chap_postdef_alpha Dir.mktmpdir do |dir| Dir.chdir(dir) do file = File.join(dir, 'locale.yml') - File.open(file, 'w') { |f| f.write("locale: ja\nappendix: 付録%pA") } + File.open(file, 'w') { |f| f.write "locale: ja\nappendix: 付録%pA" } I18n.setup('ja') @chapter.instance_eval do def on_appendix? @@ -386,11 +386,11 @@ def test_inline_imgref3 re1 = File.join(dir, 'sample1.re') cat = File.join(dir, 'catalog.yml') FileUtils.mkdir_p(File.join(dir, 'images')) - File.open(file1, 'w') { |f| f.write('') } - File.open(filet1, 'w') { |f| f.write('') } - File.open(file2, 'w') { |f| f.write('') } - File.open(cat, 'w') { |f| f.write("CHAPS:\n - sample1.re\n") } - File.open(re1, 'w') { |f| f.write(<{tbl1}. @@ -2158,7 +2158,7 @@ def test_inline_fence def test_inline_w Dir.mktmpdir do |dir| File.open(File.join(dir, 'words.csv'), 'w') do |f| - f.write(<_@{BAZ}" EOB diff --git a/test/test_i18n.rb b/test/test_i18n.rb index 32b159e46..4ea00846e 100644 --- a/test/test_i18n.rb +++ b/test/test_i18n.rb @@ -9,7 +9,7 @@ def test_load_locale_yml Dir.mktmpdir do |dir| Dir.chdir(dir) do file = File.join(dir, 'locale.yml') - File.open(file, 'w') { |f| f.write(%Q(locale: ja\nfoo: "bar"\n)) } + File.open(file, 'w') { |f| f.write %Q(locale: ja\nfoo: "bar"\n) } I18n.setup assert_equal 'bar', I18n.t('foo') end @@ -20,7 +20,7 @@ def test_load_locale_yaml Dir.mktmpdir do |dir| Dir.chdir(dir) do file = File.join(dir, 'locale.yaml') - File.open(file, 'w') { |f| f.write(%Q(locale: ja\nfoo: "bar"\n)) } + File.open(file, 'w') { |f| f.write %Q(locale: ja\nfoo: "bar"\n) } assert_raise ReVIEW::ConfigError do I18n.setup end @@ -32,7 +32,7 @@ def test_load_foo_yaml Dir.mktmpdir do |dir| Dir.chdir(dir) do file = File.join(dir, 'foo.yml') - File.open(file, 'w') { |f| f.write(%Q(locale: ja\nfoo: "bar"\n)) } + File.open(file, 'w') { |f| f.write %Q(locale: ja\nfoo: "bar"\n) } I18n.setup('ja', 'foo.yml') assert_equal 'bar', I18n.t('foo') end @@ -43,7 +43,7 @@ def test_update_foo_yaml Dir.mktmpdir do |dir| Dir.chdir(dir) do file = File.join(dir, 'foo.yml') - File.open(file, 'w') { |f| f.write(%Q(locale: ja\nfoo: "bar"\n)) } + File.open(file, 'w') { |f| f.write %Q(locale: ja\nfoo: "bar"\n) } i18n = ReVIEW::I18n.new('ja') i18n.update_localefile(File.join(Dir.pwd, 'foo.yml')) assert_equal 'bar', i18n.t('foo') @@ -55,7 +55,7 @@ def test_update_foo_yaml_i18nclass Dir.mktmpdir do |dir| Dir.chdir(dir) do file = File.join(dir, 'foo.yml') - File.open(file, 'w') { |f| f.write(%Q(locale: ja\nfoo: "bar"\n)) } + File.open(file, 'w') { |f| f.write %Q(locale: ja\nfoo: "bar"\n) } I18n.setup('ja', 'foo.yml') assert_equal 'bar', I18n.t('foo') end @@ -66,7 +66,7 @@ def test_load_locale_yml_i18n Dir.mktmpdir do |dir| Dir.chdir(dir) do file = File.join(dir, 'locale.yml') - File.open(file, 'w') { |f| f.write(%Q(ja:\n foo: "bar"\nen:\n foo: "buz"\n)) } + File.open(file, 'w') { |f| f.write %Q(ja:\n foo: "bar"\nen:\n foo: "buz"\n) } I18n.setup assert_equal 'bar', I18n.t('foo') assert_equal '図', I18n.t('image') @@ -81,7 +81,7 @@ def test_load_locale_invalid_yml Dir.mktmpdir do |dir| Dir.chdir(dir) do file = File.join(dir, 'locale.yml') - File.open(file, 'w') { |f| f.write(%Q(local: ja\nfoo: "bar"\n)) } + File.open(file, 'w') { |f| f.write %Q(local: ja\nfoo: "bar"\n) } assert_raises(ReVIEW::KeyError) do I18n.setup end @@ -93,59 +93,59 @@ def test_custom_format Dir.mktmpdir do |dir| Dir.chdir(dir) do file = File.join(dir, 'locale.yml') - File.open(file, 'w') { |f| f.write("locale: ja\nchapter: 第%pa章") } + File.open(file, 'w') { |f| f.write "locale: ja\nchapter: 第%pa章" } I18n.setup('ja') assert_equal '第a章', I18n.t('chapter', 1) - File.open(file, 'w') { |f| f.write("locale: ja\nchapter: 第%pA章") } + File.open(file, 'w') { |f| f.write "locale: ja\nchapter: 第%pA章" } I18n.setup('ja') assert_equal '第B章', I18n.t('chapter', 2) - File.open(file, 'w') { |f| f.write("locale: ja\nchapter: 第%pAW章") } + File.open(file, 'w') { |f| f.write "locale: ja\nchapter: 第%pAW章" } I18n.setup('ja') assert_equal '第B章', I18n.t('chapter', 2) - File.open(file, 'w') { |f| f.write("locale: ja\nchapter: 第%paW章") } + File.open(file, 'w') { |f| f.write "locale: ja\nchapter: 第%paW章" } I18n.setup('ja') assert_equal '第b章', I18n.t('chapter', 2) - File.open(file, 'w') { |f| f.write("locale: ja\nchapter: 第%pR章") } + File.open(file, 'w') { |f| f.write "locale: ja\nchapter: 第%pR章" } I18n.setup('ja') assert_equal '第I章', I18n.t('chapter', 1) - File.open(file, 'w') { |f| f.write("locale: ja\nchapter: 第%pr章") } + File.open(file, 'w') { |f| f.write "locale: ja\nchapter: 第%pr章" } I18n.setup('ja') assert_equal '第ii章', I18n.t('chapter', 2) - File.open(file, 'w') { |f| f.write("locale: ja\nchapter: 第%pRW章") } + File.open(file, 'w') { |f| f.write "locale: ja\nchapter: 第%pRW章" } I18n.setup('ja') assert_equal '第Ⅻ章', I18n.t('chapter', 12) - File.open(file, 'w') { |f| f.write("locale: ja\nchapter: 第%pJ章") } + File.open(file, 'w') { |f| f.write "locale: ja\nchapter: 第%pJ章" } I18n.setup('ja') assert_equal '第二十七章', I18n.t('chapter', 27) - File.open(file, 'w') { |f| f.write("locale: ja\nchapter: 第%pdW章") } + File.open(file, 'w') { |f| f.write "locale: ja\nchapter: 第%pdW章" } I18n.setup('ja') assert_equal '第1章', I18n.t('chapter', 1) - File.open(file, 'w') { |f| f.write("locale: ja\nchapter: 第%pdW章") } + File.open(file, 'w') { |f| f.write "locale: ja\nchapter: 第%pdW章" } I18n.setup('ja') assert_equal '第27章', I18n.t('chapter', 27) - File.open(file, 'w') { |f| f.write("locale: ja\nchapter: 第%pDW章") } + File.open(file, 'w') { |f| f.write "locale: ja\nchapter: 第%pDW章" } I18n.setup('ja') assert_equal '第1章', I18n.t('chapter', 1) - File.open(file, 'w') { |f| f.write("locale: ja\nchapter: 第%pDW章") } + File.open(file, 'w') { |f| f.write "locale: ja\nchapter: 第%pDW章" } I18n.setup('ja') assert_equal '第27章', I18n.t('chapter', 27) - File.open(file, 'w') { |f| f.write("locale: ja\npart: Part %pRW") } + File.open(file, 'w') { |f| f.write "locale: ja\npart: Part %pRW" } I18n.setup('ja') assert_equal 'Part 0', I18n.t('part', 0) - File.open(file, 'w') { |f| f.write("locale: ja\npart: 第%pJ部") } + File.open(file, 'w') { |f| f.write "locale: ja\npart: 第%pJ部" } I18n.setup('ja') assert_equal '第一部', I18n.t('part', 1) end @@ -157,23 +157,23 @@ def test_custom_format_numbers Dir.chdir(dir) do file = File.join(dir, 'locale.yml') - File.open(file, 'w') { |f| f.write(%Q(locale: ja\nformat_number_header: "%s-%pA:")) } + File.open(file, 'w') { |f| f.write %Q(locale: ja\nformat_number_header: "%s-%pA:") } I18n.setup('ja') assert_equal '1-B:', I18n.t('format_number_header', [1, 2]) - File.open(file, 'w') { |f| f.write(%Q(locale: ja\nformat_number_header: "%s.%pa:")) } + File.open(file, 'w') { |f| f.write %Q(locale: ja\nformat_number_header: "%s.%pa:") } I18n.setup('ja') assert_equal '2.c:', I18n.t('format_number_header', [2, 3]) - File.open(file, 'w') { |f| f.write(%Q(locale: ja\nformat_number_header: "%pA,%pAW:")) } + File.open(file, 'w') { |f| f.write %Q(locale: ja\nformat_number_header: "%pA,%pAW:") } I18n.setup('ja') assert_equal 'C,D:', I18n.t('format_number_header', [3, 4]) - File.open(file, 'w') { |f| f.write(%Q(locale: ja\nformat_number_header: "%pJ・%pJ:")) } + File.open(file, 'w') { |f| f.write %Q(locale: ja\nformat_number_header: "%pJ・%pJ:") } I18n.setup('ja') assert_equal '十二・二十六:', I18n.t('format_number_header', [12, 26]) - File.open(file, 'w') { |f| f.write(%Q(locale: ja\nformat_number_header: "%pdW―%pdW:")) } + File.open(file, 'w') { |f| f.write %Q(locale: ja\nformat_number_header: "%pdW―%pdW:") } I18n.setup('ja') assert_equal '3―12:', I18n.t('format_number_header', [3, 12]) end @@ -185,11 +185,11 @@ def test_format_with_mismatched_number_of_arguments Dir.chdir(dir) do file = File.join(dir, 'locale.yml') - File.open(file, 'w') { |f| f.write(%Q(locale: ja\nformat_number_header: "%2$d")) } + File.open(file, 'w') { |f| f.write %Q(locale: ja\nformat_number_header: "%2$d") } I18n.setup('ja') assert_equal '10', I18n.t('format_number_header', [1, 10]) - File.open(file, 'w') { |f| f.write(%Q(locale: ja\nformat_number_header: "%2$d-%1$d")) } + File.open(file, 'w') { |f| f.write %Q(locale: ja\nformat_number_header: "%2$d-%1$d") } I18n.setup('ja') # ERROR: returns raw format assert_equal '%2$d-%1$d', I18n.t('format_number_header', [1]) diff --git a/test/test_latexbuilder.rb b/test/test_latexbuilder.rb index a7c6b409b..1b9ae8bcb 100644 --- a/test/test_latexbuilder.rb +++ b/test/test_latexbuilder.rb @@ -1616,7 +1616,7 @@ def test_inline_fence def test_inline_w Dir.mktmpdir do |dir| File.open(File.join(dir, 'words.csv'), 'w') do |f| - f.write(<_@{BAZ}" EOB diff --git a/test/test_topbuilder.rb b/test/test_topbuilder.rb index fb2a5296f..df3c39f3d 100644 --- a/test/test_topbuilder.rb +++ b/test/test_topbuilder.rb @@ -613,7 +613,7 @@ def test_texequation def test_inline_w Dir.mktmpdir do |dir| File.open(File.join(dir, 'words.csv'), 'w') do |f| - f.write(<_@{BAZ}" EOB diff --git a/test/test_yamlloader.rb b/test/test_yamlloader.rb index 98e633cb1..fa2591746 100644 --- a/test/test_yamlloader.rb +++ b/test/test_yamlloader.rb @@ -15,7 +15,7 @@ def test_load_file Dir.mktmpdir do |dir| yaml_file = File.join(dir, 'test.yml') File.open(yaml_file, 'w') do |f| - f.write(<