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

Bump Rubocop to 0.54.x #6915

Merged
merged 20 commits into from
Apr 9, 2018
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
23 changes: 22 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented
Layout/MultilineOperationIndentation:
EnforcedStyle: indented
Lint/NestedPercentLiteral:
Exclude:
- test/test_site.rb
Layout/SpaceInsideBrackets:
Enabled: false
Layout/EmptyComment:
Enabled: false
Lint/EndAlignment:
Severity: error
Lint/UnreachableCode:
Expand Down Expand Up @@ -94,6 +99,14 @@ Naming/FileName:
Enabled: false
Naming/HeredocDelimiterNaming:
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:
Exclude:
- !ruby/regexp /test\/.*.rb$/
Expand All @@ -118,6 +131,9 @@ Style/Documentation:
- !ruby/regexp /features\/.*.rb$/
Style/DoubleNegation:
Enabled: false
Style/FormatStringToken:
Exclude:
- lib/jekyll/utils/ansi.rb
Style/GuardClause:
Enabled: false
Style/HashSyntax:
Expand All @@ -127,6 +143,9 @@ Style/IfUnlessModifier:
Enabled: false
Style/InverseMethods:
Enabled: false
Style/MixinUsage:
Exclude:
- test/helper.rb
Style/ModuleFunction:
Enabled: false
Style/MultilineTernaryOperator:
Expand Down Expand Up @@ -158,5 +177,7 @@ Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes
Style/SymbolArray:
Enabled: false
Style/TrailingCommaInLiteral:
Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: consistent_comma
Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: consistent_comma
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ group :test do
gem "nokogiri", RUBY_VERSION >= "2.2" ? "~> 1.7" : "~> 1.7.0"
gem "rspec"
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-theme", :path => File.expand_path("test/fixtures/test-theme", __dir__)

Expand Down
34 changes: 17 additions & 17 deletions lib/jekyll/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,31 @@ def configuration_from_options(options)

# 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
# rubocop:disable Metrics/MethodLength
def add_build_options(c)
c.option "config", "--config CONFIG_FILE[,CONFIG_FILE2,...]",
def add_build_options(cmd)
cmd.option "config", "--config CONFIG_FILE[,CONFIG_FILE2,...]",
Array, "Custom configuration file"
c.option "destination", "-d", "--destination DESTINATION",
cmd.option "destination", "-d", "--destination DESTINATION",
"The current folder will be generated into DESTINATION"
c.option "source", "-s", "--source SOURCE", "Custom source directory"
c.option "future", "--future", "Publishes posts with a future date"
c.option "limit_posts", "--limit_posts MAX_POSTS", Integer,
cmd.option "source", "-s", "--source SOURCE", "Custom source directory"
cmd.option "future", "--future", "Publishes posts with a future date"
cmd.option "limit_posts", "--limit_posts MAX_POSTS", Integer,
"Limits the number of posts to parse and publish"
c.option "watch", "-w", "--[no-]watch", "Watch for changes and rebuild"
c.option "baseurl", "-b", "--baseurl URL",
cmd.option "watch", "-w", "--[no-]watch", "Watch for changes and rebuild"
cmd.option "baseurl", "-b", "--baseurl URL",
"Serve the website from the given base URL"
c.option "force_polling", "--force_polling", "Force watch to use polling"
c.option "lsi", "--lsi", "Use LSI for improved related posts"
c.option "show_drafts", "-D", "--drafts", "Render posts in the _drafts folder"
c.option "unpublished", "--unpublished",
cmd.option "force_polling", "--force_polling", "Force watch to use polling"
cmd.option "lsi", "--lsi", "Use LSI for improved related posts"
cmd.option "show_drafts", "-D", "--drafts", "Render posts in the _drafts folder"
cmd.option "unpublished", "--unpublished",
"Render posts that were marked as unpublished"
c.option "quiet", "-q", "--quiet", "Silence output."
c.option "verbose", "-V", "--verbose", "Print verbose output."
c.option "incremental", "-I", "--incremental", "Enable incremental rebuild."
c.option "strict_front_matter", "--strict_front_matter",
cmd.option "quiet", "-q", "--quiet", "Silence output."
cmd.option "verbose", "-V", "--verbose", "Print verbose output."
cmd.option "incremental", "-I", "--incremental", "Enable incremental rebuild."
cmd.option "strict_front_matter", "--strict_front_matter",
"Fail if errors are present in front matter"
end
# rubocop:enable Metrics/MethodLength
Expand Down
5 changes: 3 additions & 2 deletions lib/jekyll/commands/serve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def init_with_program(prog)
cmd.action do |_, opts|
opts["livereload_port"] ||= LIVERELOAD_PORT
opts["serving"] = true
opts["watch" ] = true unless opts.key?("watch")
opts["watch"] = true unless opts.key?("watch")

start(opts)
end
Expand Down Expand Up @@ -173,6 +173,7 @@ def register_reload_hooks(opts)
@changed_pages = nil
end
end
# rubocop:enable Metrics/AbcSize

# 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
Expand Down Expand Up @@ -336,7 +337,7 @@ def enable_ssl(opts)
require "webrick/https"

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
end

Expand Down
24 changes: 12 additions & 12 deletions lib/jekyll/commands/serve/live_reload_reactor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ def running?
EM.reactor_running?
end

def handle_websockets_event(ws)
ws.onopen { |handshake| connect(ws, handshake) }
ws.onclose { disconnect(ws) }
ws.onmessage { |msg| print_message(msg) }
ws.onerror { |error| log_error(error) }
def handle_websockets_event(websocket)
websocket.onopen { |handshake| connect(websocket, handshake) }
websocket.onclose { disconnect(websocket) }
websocket.onmessage { |msg| print_message(msg) }
websocket.onerror { |error| log_error(error) }
end

def start(opts)
Expand Down Expand Up @@ -82,27 +82,27 @@ def reload(pages)
end

private
def connect(ws, handshake)
def connect(websocket, handshake)
@connections_count += 1
if @connections_count == 1
message = "Browser connected"
message += " over SSL/TLS" if handshake.secure?
Jekyll.logger.info "LiveReload:", message
end
ws.send(
websocket.send(
JSON.dump(
:command => "hello",
:protocols => ["http://livereload.com/protocols/official-7"],
:serverName => "jekyll"
)
)

@websockets << ws
@websockets << websocket
end

private
def disconnect(ws)
@websockets.delete(ws)
def disconnect(websocket)
@websockets.delete(websocket)
end

private
Expand All @@ -116,10 +116,10 @@ def print_message(json_message)
end

private
def log_error(e)
def log_error(error)
Jekyll.logger.error "LiveReload experienced an error. " \
"Run with --trace for more information."
raise e
raise error
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/commands/serve/servlet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def process!
end
@new_body = @new_body.join
end
# rubocop:enable Metrics/MethodLength

def template
# Unclear what "snipver" does. Doc at
Expand Down Expand Up @@ -175,6 +176,7 @@ def do_GET(req, res)
res.header.merge!(@headers)
rtn
end
# rubocop:enable Naming/MethodName

#

Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/commands/serve/websockets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def dispatch(data)
close_connection_after_writing
end
end
# rubocop:enable Metrics/MethodLength
end
end
end
Expand Down
2 changes: 0 additions & 2 deletions lib/jekyll/converters/markdown/kramdown_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,12 @@ 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] >
Expand Down
6 changes: 3 additions & 3 deletions lib/jekyll/converters/markdown/rdiscount_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def convert(content)
end

private
def replace_generated_toc(rd, html, toc_token)
if rd.generate_toc && html.include?(toc_token)
utf8_toc = rd.toc_content
def replace_generated_toc(rd_instance, html, toc_token)
if rd_instance.generate_toc && html.include?(toc_token)
utf8_toc = rd_instance.toc_content
utf8_toc.force_encoding("utf-8") if utf8_toc.respond_to?(:force_encoding)
html.gsub(toc_token, utf8_toc)
else
Expand Down
1 change: 0 additions & 1 deletion lib/jekyll/convertible.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def converters
def render_liquid(content, payload, info, path)
_renderer.render_liquid(content, payload, info, path)
end
# rubocop: enable RescueException

# Convert this Convertible's data to a Hash suitable for use by Liquid.
#
Expand Down
14 changes: 7 additions & 7 deletions lib/jekyll/entry_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ def symlink_outside_site_source?(entry)
# Check if an entry matches a specific pattern and return true,false.
# Returns true if path matches against any glob pattern.
# --
def glob_include?(enum, e)
entry = Pathutil.new(site.in_source_dir).join(e)
def glob_include?(enum, entry)
entry_path = Pathutil.new(site.in_source_dir).join(entry)
enum.any? do |exp|
# Users who send a Regexp knows what they want to
# exclude, so let them send a Regexp to exclude files,
# we will not bother caring if it works or not, it's
# on them at this point.

if exp.is_a?(Regexp)
entry =~ exp
entry_path =~ exp

else
item = Pathutil.new(site.in_source_dir).join(exp)
Expand All @@ -105,14 +105,14 @@ def glob_include?(enum, e)
# see if the entry falls within that path and
# exclude it if that's the case.

if e.end_with?("/")
entry.in_path?(
if entry.end_with?("/")
entry_path.in_path?(
item
)

else
File.fnmatch?(item, entry) ||
entry.to_path.start_with?(
File.fnmatch?(item, entry_path) ||
entry_path.to_path.start_with?(
item
)
end
Expand Down
8 changes: 4 additions & 4 deletions lib/jekyll/liquid_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ def increment_time(filename, time)
@stats[filename][:time] += time
end

def stats_table(n = 50)
LiquidRenderer::Table.new(@stats).to_s(n)
def stats_table(num_of_rows = 50)
LiquidRenderer::Table.new(@stats).to_s(num_of_rows)
end

def self.format_error(e, path)
"#{e.message} in #{path}"
def self.format_error(error, path)
"#{error.message} in #{path}"
end

private
Expand Down
10 changes: 5 additions & 5 deletions lib/jekyll/liquid_renderer/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ def initialize(stats)
@stats = stats
end

def to_s(n = 50)
data = data_for_table(n)
def to_s(num_of_rows = 50)
data = data_for_table(num_of_rows)
widths = table_widths(data)
generate_table(data, widths)
end
Expand Down Expand Up @@ -63,16 +63,16 @@ def table_widths(data)

data.each do |row|
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

widths
end

def data_for_table(n)
def data_for_table(num_of_rows)
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)]

Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/utils/platforms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def linux?

private
def proc_version
@cached_proc_version ||= begin
@proc_version ||= begin
Pathutil.new(
"/proc/version"
).read
Expand Down
2 changes: 1 addition & 1 deletion test/test_commands_serve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def serve(opts)
})

assert result[:SSLEnable]
assert_equal result[:SSLPrivateKey ], "c2"
assert_equal result[:SSLPrivateKey], "c2"
assert_equal result[:SSLCertificate], "c1"
end
end
Expand Down
6 changes: 3 additions & 3 deletions test/test_filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ def to_liquid
end

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

objects = [
Expand Down Expand Up @@ -1101,9 +1101,9 @@ def to_liquid
end
should "return sorted by subproperty array" do
assert_equal [{ "a" => { "b" => 1 } }, { "a" => { "b" => 2 } },
{ "a" => { "b" => 3 } }, ],
{ "a" => { "b" => 3 } },],
@filter.sort([{ "a" => { "b" => 2 } }, { "a" => { "b" => 1 } },
{ "a" => { "b" => 3 } }, ], "a.b")
{ "a" => { "b" => 3 } },], "a.b")
end
end

Expand Down