Skip to content
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

rubocop: make Style/MethodCallWithArgsParentheses enable #1360

Merged
merged 2 commits into from
Aug 12, 2019
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
22 changes: 22 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,28 @@ Style/LineEndConcatenation:
Style/MethodCallWithoutArgsParentheses:
Enabled: true

Style/MethodCallWithArgsParentheses:
IgnoredMethods:
- 'require'
- 'include'
- 'file'
- 'task'
- 'desc'
- 'info'
- 'gem'
- 'exit'
- 'print'
- 'puts'
- 'write'
- 'warn'
- 'error'
- 'raise'
- 'yield'
- 'source'
- 'assert'
- 'assert_equal'
Enabled: true

Style/MixinUsage:
Enabled: false

Expand Down
2 changes: 1 addition & 1 deletion bin/review-catalog-converter
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions bin/review-check
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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('|'))
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bin/review-checkdep
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def main
@unprovided[kw] = location
end
when /\A\#@provide\((.*)\)/
provide $1
provide($1)
else
line.scan(/@<kw>\{(.*?)[,\}]/) { provide $1 }
end
Expand Down
6 changes: 3 additions & 3 deletions bin/review-compile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}"
Expand Down
12 changes: 6 additions & 6 deletions bin/review-index
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
18 changes: 9 additions & 9 deletions bin/review-preproc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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}"
Expand All @@ -99,7 +99,7 @@ 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

Expand Down
4 changes: 2 additions & 2 deletions bin/review-validate
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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'
Expand Down
8 changes: 4 additions & 4 deletions bin/review-vol
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/review/book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
module ReVIEW
module Book
def self.load(dir)
Base.load dir
Base.load(dir)
end
end
end
8 changes: 4 additions & 4 deletions lib/review/book/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions lib/review/book/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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
Expand All @@ -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] == ''
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -237,7 +237,7 @@ def self.parse(src, *args)
seq = 1
src.grep(/@<icon>/) do |line|
line.gsub(/@<icon>\{(.+?)\}/) do
items.push item_class.new($1, seq)
items.push(item_class.new($1, seq))
seq += 1
end
end
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading