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

Update to Rubocop 1.45.1 #1878

Merged
merged 5 commits into from
Feb 19, 2023
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
31 changes: 31 additions & 0 deletions .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Lint by RuboCop

on:
push:
branches:
- master
pull_request:

jobs:
build:

runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
ruby: ['2.7', '3.0', '3.1', '3.2']
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- name: fix ImageMagick policy.xml on Linux
if: runner.os == 'Linux'
run: sudo sed -i 's/none/read|write/g' /etc/ImageMagick-6/policy.xml
- name: Build and test with Rake
run: |
gem install bundler --no-document
bundle install --retry 3
bundle exec rubocop -P
2 changes: 1 addition & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
run: |
gem install bundler --no-document
bundle install --retry 3
bundle exec rake
bundle exec rake test
15 changes: 13 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ AllCops:
- tmp/*
DisplayCopNames: true
NewCops: enable
TargetRubyVersion: 2.5
TargetRubyVersion: 2.7

require:
- rubocop-performance
Expand Down Expand Up @@ -38,6 +38,9 @@ Performance/StringInclude:
Performance/CollectionLiteralInLoop:
Enabled: false

Performance/MapCompact:
Enabled: false

#### Style

Style/AsciiComments:
Expand Down Expand Up @@ -109,7 +112,7 @@ Style/LineEndConcatenation:
Enabled: false

Style/MethodCallWithArgsParentheses:
IgnoredMethods:
AllowedMethods:
- 'require'
- 'include'
- 'file'
Expand Down Expand Up @@ -194,6 +197,9 @@ Style/OptionalBooleanParameter:
Style/CombinableLoops:
Enabled: false

Style/FetchEnvVar:
Enabled: false

### Layout

Layout/BlockAlignment:
Expand Down Expand Up @@ -296,3 +302,8 @@ Naming/VariableNumber:

Gemspec/RequiredRubyVersion:
Enabled: false

Gemspec/DevelopmentDependencies:
EnforcedStyle: gemspec
Exclude:
- samples/syntax-book/Gemfile
2 changes: 1 addition & 1 deletion lib/review/book/base.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2009-2022 Minero Aoki, Kenshi Muto, Masayoshi Takahashi
# Copyright (c) 2009-2023 Minero Aoki, Kenshi Muto, Masayoshi Takahashi
# 2002-2008 Minero Aoki
#
# This program is free software.
Expand Down
12 changes: 4 additions & 8 deletions lib/review/builder.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2002-2022 Minero Aoki, Kenshi Muto
# Copyright (c) 2002-2023 Minero Aoki, Kenshi Muto
#
# This program is free software.
# You can distribute or modify this program under the terms of
Expand Down Expand Up @@ -234,7 +234,8 @@ def parse_table_rows(lines)
sepidx = nil
rows = []
lines.each_with_index do |line, idx|
if /\A[=\-]{12}/ =~ line || /\A[={\-}]{12}/ =~ line
# {} is for LaTeX
if /\A[=-]{12}/ =~ line || /\A[={}-]{12}/ =~ line
sepidx ||= idx
next
end
Expand Down Expand Up @@ -512,12 +513,7 @@ def inline_w(s)
end

def inline_wb(s)
translated = @dictionary[s]
if translated
inline_b(translated)
else
inline_b("[missing word: #{s}]")
end
inline_b(@dictionary[s] || "[missing word: #{s}]")
end

def raw(str)
Expand Down
6 changes: 2 additions & 4 deletions lib/review/epubmaker.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2010-2022 Kenshi Muto and Masayoshi Takahashi
# Copyright (c) 2010-2023 Kenshi Muto and Masayoshi Takahashi
#
# This program is free software.
# You can distribute or modify this program under the terms of
Expand Down Expand Up @@ -106,9 +106,7 @@ def update_log_level
def build_path
if @config['debug']
path = File.expand_path("#{@config['bookname']}-epub", Dir.pwd)
if File.exist?(path)
FileUtils.rm_rf(path, secure: true)
end
FileUtils.rm_rf(path, secure: true)
Dir.mkdir(path)
path
else
Expand Down
5 changes: 0 additions & 5 deletions lib/review/epubmaker/epubv2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ class EPUBv2 < EPUBCommon
CREATOR_ATTRIBUTES = %w[aut a-adp a-ann a-arr a-art a-asn a-aqt a-aft a-aui a-ant a-bkp a-clb a-cmm a-dsr a-edt a-ill a-lyr a-mdc a-mus a-nrt a-oth a-pht a-prt a-red a-rev a-spn a-ths a-trc a-trl]
CONTRIBUTER_ATTRIBUTES = %w[adp ann arr art asn aqt aft aui ant bkp clb cmm dsr edt ill lyr mdc mus nrt oth pht prt red rev spn ths trc trl]

# Construct object with parameter hash +config+ and message resource hash +res+.
def initialize(producer) # rubocop:disable Lint/UselessMethodDefinition
super
end

# Return opf file content.
def opf
@opf_metainfo = opf_metainfo
Expand Down
5 changes: 2 additions & 3 deletions lib/review/epubmaker/producer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# = producer.rb -- EPUB producer.
#
# Copyright (c) 2010-2021 Kenshi Muto
# Copyright (c) 2010-2023 Kenshi Muto
#
# This program is free software.
# You can distribute or modify this program under the terms of
Expand Down Expand Up @@ -119,8 +119,7 @@ def produce(epubfile, work_dir, tmpdir = nil, base_dir: nil)
epubfile = "#{current}/#{epubfile}"
end

# FIXME: error check
File.unlink(epubfile) if File.exist?(epubfile)
FileUtils.rm_f(epubfile)

begin
@epub.produce(epubfile, work_dir, new_tmpdir, base_dir: base_dir)
Expand Down
7 changes: 4 additions & 3 deletions lib/review/idgxmlbuilder.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2008-2022 Minero Aoki, Kenshi Muto
# Copyright (c) 2008-2023 Minero Aoki, Kenshi Muto
# 2002-2007 Minero Aoki
#
# This program is free software.
Expand Down Expand Up @@ -136,7 +136,8 @@ def headline(level, label, caption)
when 5
@subsubsubsection += 1
print %Q(<sect4 id="sect:#{@chapter.number}.#{@section}.#{@subsection}.#{@subsubsection}.#{@subsubsubsection}">) if @secttags
when 6 # rubocop:disable Lint/EmptyWhen
when 6
# ignore
else
raise "caption level too deep or unsupported: #{level}"
end
Expand Down Expand Up @@ -526,7 +527,7 @@ def parse_table_rows(lines)
sepidx = nil
rows = []
lines.each_with_index do |line, idx|
if /\A[=\-]{12}/.match?(line)
if /\A[=-]{12}/.match?(line)
sepidx ||= idx
next
end
Expand Down
11 changes: 9 additions & 2 deletions lib/review/img_math.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#
# Copyright (c) 2021-2023 Masayoshi Takahashi, Kenshi Muto
#
# This program is free software.
# You can distribute/modify this program under the terms of
# the GNU LGPL, Lesser General Public License version 2.1.
#
require 'fileutils'
require 'shellwords'
require 'review/loggable'
Expand Down Expand Up @@ -29,7 +36,7 @@ def make_math_image(str, key, fontsize = 12)
# Re:VIEW 2 compatibility

img_path = File.join(@math_dir, "_gen_#{key}.#{@config['imgmath_options']['format']}")
Dir.mkdir(@math_dir) unless Dir.exist?(@math_dir)
FileUtils.mkdir_p(@math_dir)
fontsize2 = (fontsize * 1.2).round.to_i
texsrc = <<-EOB
\\documentclass[12pt]{article}
Expand Down Expand Up @@ -63,7 +70,7 @@ def make_math_image(str, key, fontsize = 12)
def make_math_images
return if @math_maps.empty?

Dir.mkdir(@math_dir) unless Dir.exist?(@math_dir)
FileUtils.mkdir_p(@math_dir)
fontsize = @config['imgmath_options']['fontsize'].to_f
lineheight = @config['imgmath_options']['lineheight'].to_f

Expand Down
4 changes: 2 additions & 2 deletions lib/review/lineinput.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2002-2020 Minero Aoki, Masayoshi Takahashi, Kenshi Muto
# Copyright (c) 2002-2023 Minero Aoki, Masayoshi Takahashi, Kenshi Muto
#
# This program is free software.
# You can distribute/modify this program under the terms of
Expand All @@ -21,7 +21,7 @@ def initialize(f)
end

def inspect
"\#<#{self.class} file=#{@input.inspect} line=#{lineno}>"
"#<#{self.class} file=#{@input.inspect} line=#{lineno}>"
end

def eof?
Expand Down
4 changes: 2 additions & 2 deletions lib/review/makerhelper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2012-2020 Yuto HAYAMIZU, Kenshi Muto
# Copyright (c) 2012-2023 Yuto HAYAMIZU, 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 @@ def copy_images_to_dir(from_dir, to_dir, options = {})
if FileTest.directory?("#{from_dir}/#{fname}")
image_files += copy_images_to_dir("#{from_dir}/#{fname}", "#{to_dir}/#{fname}", options)
else
FileUtils.mkdir_p(to_dir) unless File.exist?(to_dir)
FileUtils.mkdir_p(to_dir)

is_converted = false
(options[:convert] || {}).each do |orig_type, conv_type|
Expand Down
8 changes: 3 additions & 5 deletions lib/review/pdfmaker.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2010-2022 Kenshi Muto and Masayoshi Takahashi
# Copyright (c) 2010-2023 Kenshi Muto and Masayoshi Takahashi
#
# This program is free software.
# You can distribute or modify this program under the terms of
Expand Down Expand Up @@ -69,9 +69,7 @@ def remove_old_file
def build_path
if @config['debug']
path = "#{@config['bookname']}-pdf"
if File.exist?(path)
FileUtils.rm_rf(path, secure: true)
end
FileUtils.rm_rf(path, secure: true)
Dir.mkdir(path)
path
else
Expand Down Expand Up @@ -517,7 +515,7 @@ def copy_sty(dirname, copybase, extname = 'sty')
dir.sort.each do |fname|
next unless File.extname(fname).downcase == '.' + extname

FileUtils.mkdir_p(copybase) unless Dir.exist?(copybase)
FileUtils.mkdir_p(copybase)
if extname == 'erb'
File.open(File.join(copybase, fname.sub(/\.erb\Z/, '')), 'w') do |f|
f.print erb_content(File.join(dirname, fname))
Expand Down
10 changes: 3 additions & 7 deletions lib/review/update.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2018-2022 Kenshi Muto
# Copyright (c) 2018-2023 Kenshi Muto
#
# This program is free software.
# You can distribute or modify this program under the terms of
Expand Down Expand Up @@ -258,9 +258,7 @@ def update_version

def update_rakefile(dir)
taskdir = File.join(dir, 'lib/tasks')
unless File.exist?(taskdir)
FileUtils.mkdir_p(taskdir)
end
FileUtils.mkdir_p(taskdir)

master_rakefile = File.join(@review_dir, 'samples/sample-book/src/Rakefile')

Expand Down Expand Up @@ -474,9 +472,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)
end
FileUtils.mkdir_p(texmacrodir)

tdir = File.join(@review_dir, 'templates/latex', template)
Dir.glob(File.join(tdir, '*.*')).each do |master_styfile|
Expand Down
3 changes: 0 additions & 3 deletions lib/review/yamlloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ def self.safe_load(s)
end
end

def initialize
end

# load YAML files
#
# `inherit: [3.yml, 6.yml]` in 7.yml; `inherit: [1.yml, 2.yml]` in 3.yml; `inherit: [4.yml, 5.yml]` in 6.yml
Expand Down
5 changes: 2 additions & 3 deletions review.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ Gem::Specification.new do |gem|
gem.required_rubygems_version = Gem::Requirement.new('>= 0') if gem.respond_to?(:required_rubygems_version=)
gem.metadata = { 'rubygems_mfa_required' => 'true' }

gem.files = `git ls-files`.split("\n")
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
gem.files = `git ls-files`.split("\n").reject { |f| f.match(/^test/) }
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
gem.extra_rdoc_files = []
gem.require_paths = ['lib']
Expand All @@ -28,7 +27,7 @@ Gem::Specification.new do |gem|
gem.add_development_dependency('mini_magick')
gem.add_development_dependency('pygments.rb')
gem.add_development_dependency('rake')
gem.add_development_dependency('rubocop', '~> 1.12.0')
gem.add_development_dependency('rubocop', '~> 1.45.1')
gem.add_development_dependency('rubocop-performance')
gem.add_development_dependency('rubocop-rake')
gem.add_development_dependency('simplecov')
Expand Down
2 changes: 1 addition & 1 deletion samples/syntax-book/Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'

gem 'rake'
gem 'review', '4.2.0'
gem 'review', '~> 5.3.0'
Loading