From 3f46f02108048f2151724220d0037cbce09f483e Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Fri, 23 Jul 2021 01:58:40 +0800 Subject: [PATCH] Update rubocop from 1.12 to 1.18 and min ruby from 2.4 to 2.5 (#8741) Merge pull request 8741 --- .github/workflows/ci.yml | 2 +- .rubocop.yml | 2 +- Gemfile | 2 +- docs/_data/ruby.yml | 2 +- jekyll.gemspec | 2 +- .../converters/markdown/kramdown_parser.rb | 2 +- lib/jekyll/external.rb | 38 +++++++++---------- lib/jekyll/page.rb | 2 +- lib/jekyll/renderer.rb | 16 ++++---- lib/jekyll/tags/include.rb | 2 +- test/test_utils.rb | 8 ++-- 11 files changed, 35 insertions(+), 43 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6769f529..f4313333 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,7 +38,7 @@ jobs: fail-fast: false matrix: ruby_version: - - 2.4 # Minimum required Ruby version in gemspec + - 2.5 # Minimum required Ruby version in gemspec steps: - uses: actions/checkout@v2 - name: Download released earth diff --git a/.rubocop.yml b/.rubocop.yml index 49c69dcc..6d5256a8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -13,7 +13,7 @@ Jekyll/NoPutsAllowed: - rake/*.rake AllCops: - TargetRubyVersion: 2.4 + TargetRubyVersion: 2.5 Include: - lib/**/*.rb - test/**/*.rb diff --git a/Gemfile b/Gemfile index 615fc9de..e521f771 100644 --- a/Gemfile +++ b/Gemfile @@ -23,7 +23,7 @@ group :test do gem "nokogiri", "~> 1.7" gem "rspec" gem "rspec-mocks" - gem "rubocop", "~> 1.12.0" + gem "rubocop", "~> 1.18.3" gem "rubocop-minitest" gem "rubocop-performance" gem "rubocop-rake" diff --git a/docs/_data/ruby.yml b/docs/_data/ruby.yml index 640c5e0b..10b6bfea 100644 --- a/docs/_data/ruby.yml +++ b/docs/_data/ruby.yml @@ -1,3 +1,3 @@ -min_version: 2.4.0 +min_version: 2.5.0 current_version: 3.0.0 current_version_output: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) diff --git a/jekyll.gemspec b/jekyll.gemspec index 9bb53766..f835fea1 100644 --- a/jekyll.gemspec +++ b/jekyll.gemspec @@ -29,7 +29,7 @@ Gem::Specification.new do |s| s.rdoc_options = ["--charset=UTF-8"] s.extra_rdoc_files = %w(README.markdown LICENSE) - s.required_ruby_version = ">= 2.4.0" + s.required_ruby_version = ">= 2.5.0" s.required_rubygems_version = ">= 2.7.0" s.add_runtime_dependency("addressable", "~> 2.4") diff --git a/lib/jekyll/converters/markdown/kramdown_parser.rb b/lib/jekyll/converters/markdown/kramdown_parser.rb index a93184b8..67514807 100644 --- a/lib/jekyll/converters/markdown/kramdown_parser.rb +++ b/lib/jekyll/converters/markdown/kramdown_parser.rb @@ -160,7 +160,7 @@ module Jekyll def strip_coderay_prefix(hash) hash.each_with_object({}) do |(key, val), hsh| - cleaned_key = key.to_s.gsub(%r!\Acoderay_!, "") + cleaned_key = key.to_s.delete_prefix("coderay_") if key != cleaned_key Jekyll::Deprecator.deprecation_message( diff --git a/lib/jekyll/external.rb b/lib/jekyll/external.rb index d42762ee..b484160c 100644 --- a/lib/jekyll/external.rb +++ b/lib/jekyll/external.rb @@ -22,13 +22,11 @@ module Jekyll # def require_if_present(names) Array(names).each do |name| - begin - require name - rescue LoadError - Jekyll.logger.debug "Couldn't load #{name}. Skipping." - yield(name, version_constraint(name)) if block_given? - false - end + require name + rescue LoadError + Jekyll.logger.debug "Couldn't load #{name}. Skipping." + yield(name, version_constraint(name)) if block_given? + false end end @@ -55,23 +53,21 @@ module Jekyll # def require_with_graceful_fail(names) Array(names).each do |name| - begin - Jekyll.logger.debug "Requiring:", name.to_s - require name - rescue LoadError => e - Jekyll.logger.error "Dependency Error:", <<~MSG - Yikes! It looks like you don't have #{name} or one of its dependencies installed. - In order to use Jekyll as currently configured, you'll need to install this gem. + Jekyll.logger.debug "Requiring:", name.to_s + require name + rescue LoadError => e + Jekyll.logger.error "Dependency Error:", <<~MSG + Yikes! It looks like you don't have #{name} or one of its dependencies installed. + In order to use Jekyll as currently configured, you'll need to install this gem. - If you've run Jekyll with `bundle exec`, ensure that you have included the #{name} - gem in your Gemfile as well. + If you've run Jekyll with `bundle exec`, ensure that you have included the #{name} + gem in your Gemfile as well. - The full error message from Ruby is: '#{e.message}' + The full error message from Ruby is: '#{e.message}' - If you run into trouble, you can find helpful resources at https://jekyllrb.com/help/! - MSG - raise Jekyll::Errors::MissingDependencyException, name - end + If you run into trouble, you can find helpful resources at https://jekyllrb.com/help/! + MSG + raise Jekyll::Errors::MissingDependencyException, name end end end diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index 8b3245fb..3797f880 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -144,7 +144,7 @@ module Jekyll # The path to the page source file, relative to the site source def relative_path - @relative_path ||= PathManager.join(@dir, @name).sub(%r!\A/!, "") + @relative_path ||= PathManager.join(@dir, @name).delete_prefix("/") end # Obtain destination path. diff --git a/lib/jekyll/renderer.rb b/lib/jekyll/renderer.rb index 6a08a12b..ddf078fd 100644 --- a/lib/jekyll/renderer.rb +++ b/lib/jekyll/renderer.rb @@ -102,15 +102,13 @@ module Jekyll # Returns String the converted content. def convert(content) converters.reduce(content) do |output, converter| - begin - converter.convert output - rescue StandardError => e - Jekyll.logger.error "Conversion error:", - "#{converter.class} encountered an error while "\ - "converting '#{document.relative_path}':" - Jekyll.logger.error("", e.to_s) - raise e - end + converter.convert output + rescue StandardError => e + Jekyll.logger.error "Conversion error:", + "#{converter.class} encountered an error while "\ + "converting '#{document.relative_path}':" + Jekyll.logger.error("", e.to_s) + raise e end end diff --git a/lib/jekyll/tags/include.rb b/lib/jekyll/tags/include.rb index e6fe059a..a3ea8ff6 100644 --- a/lib/jekyll/tags/include.rb +++ b/lib/jekyll/tags/include.rb @@ -260,7 +260,7 @@ module Jekyll def resource_path(page, site) path = page["path"] path = File.join(site.config["collections_dir"], path) if page["collection"] - path.sub(%r!/#excerpt\z!, "") + path.delete_suffix("/#excerpt") end end end diff --git a/test/test_utils.rb b/test/test_utils.rb index 1b3534e4..40549aa8 100644 --- a/test/test_utils.rb +++ b/test/test_utils.rb @@ -130,11 +130,9 @@ class TestUtils < JekyllUnitTest context "The \`Utils.slugify\` method" do should "return nil if passed nil" do - begin - assert Utils.slugify(nil).nil? - rescue NoMethodError - assert false, "Threw NoMethodError" - end + assert Utils.slugify(nil).nil? + rescue NoMethodError + assert false, "Threw NoMethodError" end should "replace whitespace with hyphens" do