From 00bad8bfe50379ee608fcc35719991af3240f7ab Mon Sep 17 00:00:00 2001 From: ashmaroli Date: Fri, 22 Sep 2017 18:36:32 +0530 Subject: [PATCH] Bump rubocop to use `v0.50.x` (#6368) Merge pull request 6368 --- .rubocop.yml | 14 +++++++++++--- Gemfile | 2 +- jekyll.gemspec | 1 - lib/jekyll.rb | 4 ++-- lib/jekyll/commands/doctor.rb | 2 +- lib/jekyll/commands/serve/servlet.rb | 2 +- lib/jekyll/configuration.rb | 1 - lib/jekyll/converters/markdown.rb | 4 ++-- lib/jekyll/converters/markdown/kramdown_parser.rb | 2 ++ lib/jekyll/convertible.rb | 1 - lib/jekyll/document.rb | 1 - lib/jekyll/drops/collection_drop.rb | 1 - lib/jekyll/drops/document_drop.rb | 1 - lib/jekyll/drops/drop.rb | 1 - lib/jekyll/drops/excerpt_drop.rb | 1 - lib/jekyll/drops/jekyll_drop.rb | 1 - lib/jekyll/drops/site_drop.rb | 1 - lib/jekyll/drops/unified_payload_drop.rb | 1 - lib/jekyll/drops/url_drop.rb | 1 - lib/jekyll/reader.rb | 3 +-- lib/jekyll/readers/collection_reader.rb | 2 +- lib/jekyll/renderer.rb | 1 - lib/jekyll/site.rb | 15 +++++++-------- lib/jekyll/tags/highlight.rb | 8 ++++---- lib/jekyll/tags/include.rb | 9 ++++----- lib/jekyll/tags/link.rb | 4 ++-- lib/jekyll/tags/post_url.rb | 8 ++++---- test/test_ansi.rb | 2 +- test/test_utils.rb | 1 + 29 files changed, 45 insertions(+), 50 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index ea3aa1062fc..8f961cf589f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -21,7 +21,7 @@ Layout/EmptyLinesAroundAccessModifier: Layout/EmptyLinesAroundModuleBody: Enabled: false Layout/EndOfLine: - EnforcedStyle: lf + EnforcedStyle: native Layout/ExtraSpacing: AllowForAlignment: true Layout/FirstParameterIndentation: @@ -44,10 +44,14 @@ Layout/SpaceInsideBrackets: Enabled: false Lint/EndAlignment: Severity: error +Lint/RescueWithoutErrorClass: + Enabled: false Lint/UnreachableCode: Severity: error Lint/UselessAccessModifier: Enabled: false +Lint/Void: + Enabled: false Metrics/AbcSize: Max: 21 Metrics/BlockLength: @@ -82,6 +86,10 @@ Metrics/ParameterLists: Max: 4 Metrics/PerceivedComplexity: Max: 8 +Naming/FileName: + Enabled: false +Naming/HeredocDelimiterNaming: + Enabled: false Security/MarshalLoad: Exclude: - !ruby/regexp /test\/.*.rb$/ @@ -109,8 +117,8 @@ Style/Documentation: - !ruby/regexp /features\/.*.rb$/ Style/DoubleNegation: Enabled: false -Style/FileName: - Enabled: false +Style/Encoding: + EnforcedStyle: when_needed Style/GuardClause: Enabled: false Style/HashSyntax: diff --git a/Gemfile b/Gemfile index 216c2626f19..c94d4ff3969 100644 --- a/Gemfile +++ b/Gemfile @@ -30,7 +30,7 @@ group :test do gem "nokogiri", RUBY_VERSION >= "2.2" ? "~> 1.7" : "~> 1.7.0" gem "rspec" gem "rspec-mocks" - gem "rubocop", "~> 0.49.1" + gem "rubocop", "~> 0.50.0" gem "test-dependency-theme", :path => File.expand_path("test/fixtures/test-dependency-theme", __dir__) gem "test-theme", :path => File.expand_path("test/fixtures/test-theme", __dir__) diff --git a/jekyll.gemspec b/jekyll.gemspec index 606d09daae4..ddbb36e8854 100644 --- a/jekyll.gemspec +++ b/jekyll.gemspec @@ -1,4 +1,3 @@ -# coding: utf-8 # frozen_string_literal: true lib = File.expand_path("lib", __dir__) diff --git a/lib/jekyll.rb b/lib/jekyll.rb index fb5db3d43e1..cdcab8bda5b 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -119,7 +119,7 @@ def configuration(override = {}) # timezone - the IANA Time Zone # # Returns nothing - # rubocop:disable Style/AccessorMethodName + # rubocop:disable Naming/AccessorMethodName def set_timezone(timezone) ENV["TZ"] = if Utils::Platforms.really_windows? Utils::WinTZ.calculate(timezone) @@ -127,7 +127,7 @@ def set_timezone(timezone) timezone end end - # rubocop:enable Style/AccessorMethodName + # rubocop:enable Naming/AccessorMethodName # Public: Fetch the logger instance for this Jekyll process. # diff --git a/lib/jekyll/commands/doctor.rb b/lib/jekyll/commands/doctor.rb index 1ef87e714d5..c10ee5963ca 100644 --- a/lib/jekyll/commands/doctor.rb +++ b/lib/jekyll/commands/doctor.rb @@ -86,7 +86,7 @@ def fsnotify_buggy?(_site) def urls_only_differ_by_case(site) urls_only_differ_by_case = false urls = case_insensitive_urls(site.pages + site.docs_to_write, site.dest) - urls.each do |_case_insensitive_url, real_urls| + urls.each_value do |real_urls| next unless real_urls.uniq.size > 1 urls_only_differ_by_case = true Jekyll.logger.warn "Warning:", "The following URLs only differ" \ diff --git a/lib/jekyll/commands/serve/servlet.rb b/lib/jekyll/commands/serve/servlet.rb index b661940c30a..2e41b697524 100644 --- a/lib/jekyll/commands/serve/servlet.rb +++ b/lib/jekyll/commands/serve/servlet.rb @@ -27,7 +27,7 @@ def search_file(req, res, basename) super || super(req, res, ".html") || super(req, res, "#{basename}.html") end - # rubocop:disable Style/MethodName + # rubocop:disable Naming/MethodName def do_GET(req, res) rtn = super validate_and_ensure_charset(req, res) diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index a9965d29f5b..7fbe15cf9df 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 # frozen_string_literal: true module Jekyll diff --git a/lib/jekyll/converters/markdown.rb b/lib/jekyll/converters/markdown.rb index 3e53992104d..857b6ecf73e 100644 --- a/lib/jekyll/converters/markdown.rb +++ b/lib/jekyll/converters/markdown.rb @@ -27,7 +27,7 @@ def setup # Rubocop does not allow reader methods to have names starting with `get_` # To ensure compatibility, this check has been disabled on this method # - # rubocop:disable Style/AccessorMethodName + # rubocop:disable Naming/AccessorMethodName def get_processor case @config["markdown"].downcase when "redcarpet" then return RedcarpetParser.new(@config) @@ -37,7 +37,7 @@ def get_processor custom_processor end end - # rubocop:enable Style/AccessorMethodName + # rubocop:enable Naming/AccessorMethodName # Public: Provides you with a list of processors, the ones we # support internally and the ones that you have provided to us (if you diff --git a/lib/jekyll/converters/markdown/kramdown_parser.rb b/lib/jekyll/converters/markdown/kramdown_parser.rb index d1f93c63f09..a9650cc7939 100644 --- a/lib/jekyll/converters/markdown/kramdown_parser.rb +++ b/lib/jekyll/converters/markdown/kramdown_parser.rb @@ -42,12 +42,14 @@ def convert(content) end private + # rubocop:disable Performance/HashEachMethods def make_accessible(hash = @config) hash.keys.each do |key| hash[key.to_sym] = hash[key] make_accessible(hash[key]) if hash[key].is_a?(Hash) end end + # rubocop:enable Performance/HashEachMethods # config[kramdown][syntax_higlighter] > # config[kramdown][enable_coderay] > diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb index aea33fdcb86..6b20548292e 100644 --- a/lib/jekyll/convertible.rb +++ b/lib/jekyll/convertible.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 # frozen_string_literal: true require "set" diff --git a/lib/jekyll/document.rb b/lib/jekyll/document.rb index d42e544c62f..0877ca12421 100644 --- a/lib/jekyll/document.rb +++ b/lib/jekyll/document.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 # frozen_string_literal: true module Jekyll diff --git a/lib/jekyll/drops/collection_drop.rb b/lib/jekyll/drops/collection_drop.rb index 2c9c01320ea..e1d7da95978 100644 --- a/lib/jekyll/drops/collection_drop.rb +++ b/lib/jekyll/drops/collection_drop.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 # frozen_string_literal: true module Jekyll diff --git a/lib/jekyll/drops/document_drop.rb b/lib/jekyll/drops/document_drop.rb index 7796980c7a4..727997810f3 100644 --- a/lib/jekyll/drops/document_drop.rb +++ b/lib/jekyll/drops/document_drop.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 # frozen_string_literal: true module Jekyll diff --git a/lib/jekyll/drops/drop.rb b/lib/jekyll/drops/drop.rb index 1cc9c465ac4..92978af1962 100644 --- a/lib/jekyll/drops/drop.rb +++ b/lib/jekyll/drops/drop.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 # frozen_string_literal: true module Jekyll diff --git a/lib/jekyll/drops/excerpt_drop.rb b/lib/jekyll/drops/excerpt_drop.rb index 06f8ae7d016..0362d9304ee 100644 --- a/lib/jekyll/drops/excerpt_drop.rb +++ b/lib/jekyll/drops/excerpt_drop.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 # frozen_string_literal: true module Jekyll diff --git a/lib/jekyll/drops/jekyll_drop.rb b/lib/jekyll/drops/jekyll_drop.rb index 1686da418f1..8a56b9ee76d 100644 --- a/lib/jekyll/drops/jekyll_drop.rb +++ b/lib/jekyll/drops/jekyll_drop.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 # frozen_string_literal: true module Jekyll diff --git a/lib/jekyll/drops/site_drop.rb b/lib/jekyll/drops/site_drop.rb index 20b0332a43c..632f81ce118 100644 --- a/lib/jekyll/drops/site_drop.rb +++ b/lib/jekyll/drops/site_drop.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 # frozen_string_literal: true module Jekyll diff --git a/lib/jekyll/drops/unified_payload_drop.rb b/lib/jekyll/drops/unified_payload_drop.rb index 833443a46f9..52647f98bf6 100644 --- a/lib/jekyll/drops/unified_payload_drop.rb +++ b/lib/jekyll/drops/unified_payload_drop.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 # frozen_string_literal: true module Jekyll diff --git a/lib/jekyll/drops/url_drop.rb b/lib/jekyll/drops/url_drop.rb index e67d24d47b8..0571558bf4e 100644 --- a/lib/jekyll/drops/url_drop.rb +++ b/lib/jekyll/drops/url_drop.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 # frozen_string_literal: true module Jekyll diff --git a/lib/jekyll/reader.rb b/lib/jekyll/reader.rb index 5804d1f963a..7b5c3b158ea 100644 --- a/lib/jekyll/reader.rb +++ b/lib/jekyll/reader.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 # frozen_string_literal: true require "csv" @@ -25,7 +24,7 @@ def read # Sorts posts, pages, and static files. def sort_files! - site.collections.values.each { |c| c.docs.sort! } + site.collections.each_value { |c| c.docs.sort! } site.pages.sort_by!(&:name) site.static_files.sort_by!(&:relative_path) end diff --git a/lib/jekyll/readers/collection_reader.rb b/lib/jekyll/readers/collection_reader.rb index 7d605f421c4..77c700976f7 100644 --- a/lib/jekyll/readers/collection_reader.rb +++ b/lib/jekyll/readers/collection_reader.rb @@ -14,7 +14,7 @@ def initialize(site) # # Returns nothing. def read - site.collections.each do |_, collection| + site.collections.each_value do |collection| collection.read unless SPECIAL_COLLECTIONS.include?(collection.label) end end diff --git a/lib/jekyll/renderer.rb b/lib/jekyll/renderer.rb index 5a2d32a8d27..3a6fdebd24d 100644 --- a/lib/jekyll/renderer.rb +++ b/lib/jekyll/renderer.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 # frozen_string_literal: true module Jekyll diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 54155d0c8e2..a771477d176 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 # frozen_string_literal: true require "csv" @@ -85,11 +84,11 @@ def print_stats # # Returns nothing def reset - if config["time"] - self.time = Utils.parse_date(config["time"].to_s, "Invalid time in _config.yml.") - else - self.time = Time.now - end + self.time = if config["time"] + Utils.parse_date(config["time"].to_s, "Invalid time in _config.yml.") + else + Time.now + end self.layouts = {} self.pages = [] self.static_files = [] @@ -238,7 +237,7 @@ def post_attr_hash(post_attr) posts.docs.each do |p| p.data[post_attr].each { |t| hash[t] << p } if p.data[post_attr] end - hash.values.each { |posts| posts.sort!.reverse! } + hash.each_value { |posts| posts.sort!.reverse! } hash end @@ -449,7 +448,7 @@ def configure_file_read_opts private def render_docs(payload) - collections.each do |_, collection| + collections.each_value do |collection| collection.docs.each do |document| if regenerator.regenerate?(document) document.output = Jekyll::Renderer.new(self, document, payload).run diff --git a/lib/jekyll/tags/highlight.rb b/lib/jekyll/tags/highlight.rb index 687f9b717b3..683e3b2b456 100644 --- a/lib/jekyll/tags/highlight.rb +++ b/lib/jekyll/tags/highlight.rb @@ -18,13 +18,13 @@ def initialize(tag_name, markup, tokens) @lang = Regexp.last_match(1).downcase @highlight_options = parse_options(Regexp.last_match(2)) else - raise SyntaxError, <<-eos + raise SyntaxError, <<-MSG Syntax Error in tag 'highlight' while parsing the following markup: #{markup} Valid syntax: highlight [linenos] -eos +MSG end end @@ -95,14 +95,14 @@ def render_pygments(code, is_safe) ) if highlighted_code.nil? - Jekyll.logger.error < e - raise Jekyll::Errors::PostURLError, <<-eos + raise Jekyll::Errors::PostURLError, <<-MSG Could not parse name of post "#{@orig_post}" in tag 'post_url'. Make sure the post exists and the name is correct. #{e.class}: #{e.message} -eos +MSG end end @@ -90,11 +90,11 @@ def render(context) return p.url end - raise Jekyll::Errors::PostURLError, <<-eos + raise Jekyll::Errors::PostURLError, <<-MSG Could not find post "#{@orig_post}" in tag 'post_url'. Make sure the post exists and the name is correct. -eos +MSG end end end diff --git a/test/test_ansi.rb b/test/test_ansi.rb index 9b4fd01668c..e780e0dd521 100644 --- a/test/test_ansi.rb +++ b/test/test_ansi.rb @@ -8,7 +8,7 @@ class TestAnsi < JekyllUnitTest @subject = Jekyll::Utils::Ansi end - Jekyll::Utils::Ansi::COLORS.each do |color, _val| + Jekyll::Utils::Ansi::COLORS.each_key do |color| should "respond_to? #{color}" do assert @subject.respond_to?(color) end diff --git a/test/test_utils.rb b/test/test_utils.rb index 1b4d4813b66..638aa16d275 100644 --- a/test/test_utils.rb +++ b/test/test_utils.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 # frozen_string_literal: true require "helper"