Bump Rubocop to 0.54.x (#6915)

Merge pull request 6915
This commit is contained in:
David Zhang 2018-04-09 16:26:49 +08:00 committed by jekyllbot
parent 7c12ebb28a
commit 2a032a38ec
16 changed files with 82 additions and 60 deletions

View File

@ -46,8 +46,13 @@ Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented EnforcedStyle: indented
Layout/MultilineOperationIndentation: Layout/MultilineOperationIndentation:
EnforcedStyle: indented EnforcedStyle: indented
Lint/NestedPercentLiteral:
Exclude:
- test/test_site.rb
Layout/SpaceInsideBrackets: Layout/SpaceInsideBrackets:
Enabled: false Enabled: false
Layout/EmptyComment:
Enabled: false
Lint/EndAlignment: Lint/EndAlignment:
Severity: error Severity: error
Lint/UnreachableCode: Lint/UnreachableCode:
@ -94,6 +99,14 @@ Naming/FileName:
Enabled: false Enabled: false
Naming/HeredocDelimiterNaming: Naming/HeredocDelimiterNaming:
Enabled: false Enabled: false
Naming/MemoizedInstanceVariableName:
Exclude:
- lib/jekyll/page_without_a_file.rb
- lib/jekyll/drops/unified_payload_drop.rb
- lib/jekyll/drops/site_drop.rb
Naming/UncommunicativeMethodParamName:
AllowedNames:
- _
Security/MarshalLoad: Security/MarshalLoad:
Exclude: Exclude:
- !ruby/regexp /test\/.*.rb$/ - !ruby/regexp /test\/.*.rb$/
@ -118,6 +131,9 @@ Style/Documentation:
- !ruby/regexp /features\/.*.rb$/ - !ruby/regexp /features\/.*.rb$/
Style/DoubleNegation: Style/DoubleNegation:
Enabled: false Enabled: false
Style/FormatStringToken:
Exclude:
- lib/jekyll/utils/ansi.rb
Style/GuardClause: Style/GuardClause:
Enabled: false Enabled: false
Style/HashSyntax: Style/HashSyntax:
@ -127,6 +143,9 @@ Style/IfUnlessModifier:
Enabled: false Enabled: false
Style/InverseMethods: Style/InverseMethods:
Enabled: false Enabled: false
Style/MixinUsage:
Exclude:
- test/helper.rb
Style/ModuleFunction: Style/ModuleFunction:
Enabled: false Enabled: false
Style/MultilineTernaryOperator: Style/MultilineTernaryOperator:
@ -158,5 +177,7 @@ Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes EnforcedStyle: double_quotes
Style/SymbolArray: Style/SymbolArray:
Enabled: false Enabled: false
Style/TrailingCommaInLiteral: Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: consistent_comma
Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: consistent_comma EnforcedStyleForMultiline: consistent_comma

View File

@ -31,7 +31,7 @@ group :test do
gem "nokogiri", RUBY_VERSION >= "2.2" ? "~> 1.7" : "~> 1.7.0" gem "nokogiri", RUBY_VERSION >= "2.2" ? "~> 1.7" : "~> 1.7.0"
gem "rspec" gem "rspec"
gem "rspec-mocks" gem "rspec-mocks"
gem "rubocop", "~> 0.51.0" gem "rubocop", "~> 0.54.0"
gem "test-dependency-theme", :path => File.expand_path("test/fixtures/test-dependency-theme", __dir__) 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__) gem "test-theme", :path => File.expand_path("test/fixtures/test-theme", __dir__)

View File

@ -45,31 +45,31 @@ module Jekyll
# Add common options to a command for building configuration # Add common options to a command for building configuration
# #
# c - the Jekyll::Command to add these options to # cmd - the Jekyll::Command to add these options to
# #
# Returns nothing # Returns nothing
# rubocop:disable Metrics/MethodLength # rubocop:disable Metrics/MethodLength
def add_build_options(c) def add_build_options(cmd)
c.option "config", "--config CONFIG_FILE[,CONFIG_FILE2,...]", cmd.option "config", "--config CONFIG_FILE[,CONFIG_FILE2,...]",
Array, "Custom configuration file" Array, "Custom configuration file"
c.option "destination", "-d", "--destination DESTINATION", cmd.option "destination", "-d", "--destination DESTINATION",
"The current folder will be generated into DESTINATION" "The current folder will be generated into DESTINATION"
c.option "source", "-s", "--source SOURCE", "Custom source directory" cmd.option "source", "-s", "--source SOURCE", "Custom source directory"
c.option "future", "--future", "Publishes posts with a future date" cmd.option "future", "--future", "Publishes posts with a future date"
c.option "limit_posts", "--limit_posts MAX_POSTS", Integer, cmd.option "limit_posts", "--limit_posts MAX_POSTS", Integer,
"Limits the number of posts to parse and publish" "Limits the number of posts to parse and publish"
c.option "watch", "-w", "--[no-]watch", "Watch for changes and rebuild" cmd.option "watch", "-w", "--[no-]watch", "Watch for changes and rebuild"
c.option "baseurl", "-b", "--baseurl URL", cmd.option "baseurl", "-b", "--baseurl URL",
"Serve the website from the given base URL" "Serve the website from the given base URL"
c.option "force_polling", "--force_polling", "Force watch to use polling" cmd.option "force_polling", "--force_polling", "Force watch to use polling"
c.option "lsi", "--lsi", "Use LSI for improved related posts" cmd.option "lsi", "--lsi", "Use LSI for improved related posts"
c.option "show_drafts", "-D", "--drafts", "Render posts in the _drafts folder" cmd.option "show_drafts", "-D", "--drafts", "Render posts in the _drafts folder"
c.option "unpublished", "--unpublished", cmd.option "unpublished", "--unpublished",
"Render posts that were marked as unpublished" "Render posts that were marked as unpublished"
c.option "quiet", "-q", "--quiet", "Silence output." cmd.option "quiet", "-q", "--quiet", "Silence output."
c.option "verbose", "-V", "--verbose", "Print verbose output." cmd.option "verbose", "-V", "--verbose", "Print verbose output."
c.option "incremental", "-I", "--incremental", "Enable incremental rebuild." cmd.option "incremental", "-I", "--incremental", "Enable incremental rebuild."
c.option "strict_front_matter", "--strict_front_matter", cmd.option "strict_front_matter", "--strict_front_matter",
"Fail if errors are present in front matter" "Fail if errors are present in front matter"
end end
# rubocop:enable Metrics/MethodLength # rubocop:enable Metrics/MethodLength

View File

@ -70,7 +70,7 @@ module Jekyll
cmd.action do |_, opts| cmd.action do |_, opts|
opts["livereload_port"] ||= LIVERELOAD_PORT opts["livereload_port"] ||= LIVERELOAD_PORT
opts["serving"] = true opts["serving"] = true
opts["watch" ] = true unless opts.key?("watch") opts["watch"] = true unless opts.key?("watch")
start(opts) start(opts)
end end
@ -173,6 +173,7 @@ module Jekyll
@changed_pages = nil @changed_pages = nil
end end
end end
# rubocop:enable Metrics/AbcSize
# Do a base pre-setup of WEBRick so that everything is in place # Do a base pre-setup of WEBRick so that everything is in place
# when we get ready to party, checking for an setting up an error page # when we get ready to party, checking for an setting up an error page
@ -336,7 +337,7 @@ module Jekyll
require "webrick/https" require "webrick/https"
opts[:SSLCertificate] = OpenSSL::X509::Certificate.new(read_file(src, cert)) opts[:SSLCertificate] = OpenSSL::X509::Certificate.new(read_file(src, cert))
opts[:SSLPrivateKey ] = OpenSSL::PKey::RSA.new(read_file(src, key)) opts[:SSLPrivateKey] = OpenSSL::PKey::RSA.new(read_file(src, key))
opts[:SSLEnable] = true opts[:SSLEnable] = true
end end

View File

@ -31,11 +31,11 @@ module Jekyll
EM.reactor_running? EM.reactor_running?
end end
def handle_websockets_event(ws) def handle_websockets_event(websocket)
ws.onopen { |handshake| connect(ws, handshake) } websocket.onopen { |handshake| connect(websocket, handshake) }
ws.onclose { disconnect(ws) } websocket.onclose { disconnect(websocket) }
ws.onmessage { |msg| print_message(msg) } websocket.onmessage { |msg| print_message(msg) }
ws.onerror { |error| log_error(error) } websocket.onerror { |error| log_error(error) }
end end
def start(opts) def start(opts)
@ -82,14 +82,14 @@ module Jekyll
end end
private private
def connect(ws, handshake) def connect(websocket, handshake)
@connections_count += 1 @connections_count += 1
if @connections_count == 1 if @connections_count == 1
message = "Browser connected" message = "Browser connected"
message += " over SSL/TLS" if handshake.secure? message += " over SSL/TLS" if handshake.secure?
Jekyll.logger.info "LiveReload:", message Jekyll.logger.info "LiveReload:", message
end end
ws.send( websocket.send(
JSON.dump( JSON.dump(
:command => "hello", :command => "hello",
:protocols => ["http://livereload.com/protocols/official-7"], :protocols => ["http://livereload.com/protocols/official-7"],
@ -97,12 +97,12 @@ module Jekyll
) )
) )
@websockets << ws @websockets << websocket
end end
private private
def disconnect(ws) def disconnect(websocket)
@websockets.delete(ws) @websockets.delete(websocket)
end end
private private
@ -116,10 +116,10 @@ module Jekyll
end end
private private
def log_error(e) def log_error(error)
Jekyll.logger.error "LiveReload experienced an error. " \ Jekyll.logger.error "LiveReload experienced an error. " \
"Run with --trace for more information." "Run with --trace for more information."
raise e raise error
end end
end end
end end

View File

@ -88,6 +88,7 @@ module Jekyll
end end
@new_body = @new_body.join @new_body = @new_body.join
end end
# rubocop:enable Metrics/MethodLength
def template def template
# Unclear what "snipver" does. Doc at # Unclear what "snipver" does. Doc at
@ -175,6 +176,7 @@ module Jekyll
res.header.merge!(@headers) res.header.merge!(@headers)
rtn rtn
end end
# rubocop:enable Naming/MethodName
# #

View File

@ -74,6 +74,7 @@ module Jekyll
close_connection_after_writing close_connection_after_writing
end end
end end
# rubocop:enable Metrics/MethodLength
end end
end end
end end

View File

@ -50,14 +50,12 @@ module Jekyll
end end
private private
# rubocop:disable Performance/HashEachMethods
def make_accessible(hash = @config) def make_accessible(hash = @config)
hash.keys.each do |key| hash.keys.each do |key|
hash[key.to_sym] = hash[key] hash[key.to_sym] = hash[key]
make_accessible(hash[key]) if hash[key].is_a?(Hash) make_accessible(hash[key]) if hash[key].is_a?(Hash)
end end
end end
# rubocop:enable Performance/HashEachMethods
# config[kramdown][syntax_higlighter] > # config[kramdown][syntax_higlighter] >
# config[kramdown][enable_coderay] > # config[kramdown][enable_coderay] >

View File

@ -22,9 +22,9 @@ module Jekyll
end end
private private
def replace_generated_toc(rd, html, toc_token) def replace_generated_toc(rd_instance, html, toc_token)
if rd.generate_toc && html.include?(toc_token) if rd_instance.generate_toc && html.include?(toc_token)
utf8_toc = rd.toc_content utf8_toc = rd_instance.toc_content
utf8_toc.force_encoding("utf-8") if utf8_toc.respond_to?(:force_encoding) utf8_toc.force_encoding("utf-8") if utf8_toc.respond_to?(:force_encoding)
html.gsub(toc_token, utf8_toc) html.gsub(toc_token, utf8_toc)
else else

View File

@ -109,7 +109,6 @@ module Jekyll
def render_liquid(content, payload, info, path) def render_liquid(content, payload, info, path)
_renderer.render_liquid(content, payload, info, path) _renderer.render_liquid(content, payload, info, path)
end end
# rubocop: enable RescueException
# Convert this Convertible's data to a Hash suitable for use by Liquid. # Convert this Convertible's data to a Hash suitable for use by Liquid.
# #

View File

@ -86,8 +86,8 @@ module Jekyll
# Check if an entry matches a specific pattern and return true,false. # Check if an entry matches a specific pattern and return true,false.
# Returns true if path matches against any glob pattern. # Returns true if path matches against any glob pattern.
# -- # --
def glob_include?(enum, e) def glob_include?(enum, entry)
entry = Pathutil.new(site.in_source_dir).join(e) entry_path = Pathutil.new(site.in_source_dir).join(entry)
enum.any? do |exp| enum.any? do |exp|
# Users who send a Regexp knows what they want to # Users who send a Regexp knows what they want to
# exclude, so let them send a Regexp to exclude files, # exclude, so let them send a Regexp to exclude files,
@ -95,7 +95,7 @@ module Jekyll
# on them at this point. # on them at this point.
if exp.is_a?(Regexp) if exp.is_a?(Regexp)
entry =~ exp entry_path =~ exp
else else
item = Pathutil.new(site.in_source_dir).join(exp) item = Pathutil.new(site.in_source_dir).join(exp)
@ -105,14 +105,14 @@ module Jekyll
# see if the entry falls within that path and # see if the entry falls within that path and
# exclude it if that's the case. # exclude it if that's the case.
if e.end_with?("/") if entry.end_with?("/")
entry.in_path?( entry_path.in_path?(
item item
) )
else else
File.fnmatch?(item, entry) || File.fnmatch?(item, entry_path) ||
entry.to_path.start_with?( entry_path.to_path.start_with?(
item item
) )
end end

View File

@ -42,12 +42,12 @@ module Jekyll
@stats[filename][:time] += time @stats[filename][:time] += time
end end
def stats_table(n = 50) def stats_table(num_of_rows = 50)
LiquidRenderer::Table.new(@stats).to_s(n) LiquidRenderer::Table.new(@stats).to_s(num_of_rows)
end end
def self.format_error(e, path) def self.format_error(error, path)
"#{e.message} in #{path}" "#{error.message} in #{path}"
end end
private private

View File

@ -6,8 +6,8 @@ module Jekyll
@stats = stats @stats = stats
end end
def to_s(n = 50) def to_s(num_of_rows = 50)
data = data_for_table(n) data = data_for_table(num_of_rows)
widths = table_widths(data) widths = table_widths(data)
generate_table(data, widths) generate_table(data, widths)
end end
@ -63,16 +63,16 @@ module Jekyll
data.each do |row| data.each do |row|
row.each_with_index do |cell, index| row.each_with_index do |cell, index|
widths[index] = [ cell.length, widths[index] ].compact.max widths[index] = [cell.length, widths[index]].compact.max
end end
end end
widths widths
end end
def data_for_table(n) def data_for_table(num_of_rows)
sorted = @stats.sort_by { |_, file_stats| -file_stats[:time] } sorted = @stats.sort_by { |_, file_stats| -file_stats[:time] }
sorted = sorted.slice(0, n) sorted = sorted.slice(0, num_of_rows)
table = [%w(Filename Count Bytes Time)] table = [%w(Filename Count Bytes Time)]

View File

@ -69,7 +69,7 @@ module Jekyll
private private
def proc_version def proc_version
@cached_proc_version ||= begin @proc_version ||= begin
Pathutil.new( Pathutil.new(
"/proc/version" "/proc/version"
).read ).read

View File

@ -307,7 +307,7 @@ class TestCommandsServe < JekyllUnitTest
}) })
assert result[:SSLEnable] assert result[:SSLEnable]
assert_equal result[:SSLPrivateKey ], "c2" assert_equal result[:SSLPrivateKey], "c2"
assert_equal result[:SSLCertificate], "c1" assert_equal result[:SSLCertificate], "c1"
end end
end end

View File

@ -931,7 +931,7 @@ class TestFilters < JekyllUnitTest
end end
should "filter with other operators" do should "filter with other operators" do
assert_equal [3, 4, 5], @filter.where_exp([ 1, 2, 3, 4, 5 ], "n", "n >= 3") assert_equal [3, 4, 5], @filter.where_exp([1, 2, 3, 4, 5], "n", "n >= 3")
end end
objects = [ objects = [
@ -1101,9 +1101,9 @@ class TestFilters < JekyllUnitTest
end end
should "return sorted by subproperty array" do should "return sorted by subproperty array" do
assert_equal [{ "a" => { "b" => 1 } }, { "a" => { "b" => 2 } }, assert_equal [{ "a" => { "b" => 1 } }, { "a" => { "b" => 2 } },
{ "a" => { "b" => 3 } }, ], { "a" => { "b" => 3 } },],
@filter.sort([{ "a" => { "b" => 2 } }, { "a" => { "b" => 1 } }, @filter.sort([{ "a" => { "b" => 2 } }, { "a" => { "b" => 1 } },
{ "a" => { "b" => 3 } }, ], "a.b") { "a" => { "b" => 3 } },], "a.b")
end end
end end