Skip to content

Commit

Permalink
Bump Rubocop to v0.59.0 (#7237)
Browse files Browse the repository at this point in the history
Merge pull request 7237
  • Loading branch information
jekyllbot authored Sep 9, 2018
1 parent 6d777a2 commit a28f54a
Show file tree
Hide file tree
Showing 40 changed files with 91 additions and 14 deletions.
5 changes: 3 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ Naming/HeredocDelimiterNaming:
- test/**/*.rb
Naming/MemoizedInstanceVariableName:
Exclude:
- lib/jekyll/page_without_a_file.rb
- lib/jekyll/drops/unified_payload_drop.rb
- lib/jekyll/convertible.rb
- lib/jekyll/drops/site_drop.rb
- lib/jekyll/drops/unified_payload_drop.rb
- lib/jekyll/page_without_a_file.rb
Naming/UncommunicativeMethodParamName:
AllowedNames:
- _
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ group :test do
gem "nokogiri", "~> 1.7"
gem "rspec"
gem "rspec-mocks"
gem "rubocop", "~> 0.57.2"
gem "rubocop", "~> 0.59.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
8 changes: 8 additions & 0 deletions lib/jekyll/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def clear
# Returns cached value
def [](key)
return @cache[key] if @cache.key?(key)

path = path_to(hash(key))
if @@disk_cache_enabled && File.file?(path) && File.readable?(path)
@cache[key] = load(path)
Expand All @@ -57,6 +58,7 @@ def [](key)
def []=(key, value)
@cache[key] = value
return unless @@disk_cache_enabled

path = path_to(hash(key))
dump(path, value)
end
Expand All @@ -78,6 +80,7 @@ def getset(key)
def delete(key)
@cache.delete(key)
return unless @@disk_cache_enabled

path = path_to(hash(key))
File.delete(path)
end
Expand All @@ -91,6 +94,7 @@ def key?(key)
# Otherwise, it might be cached on disk
# but we should not consider the disk cache if it is disabled
return false unless @@disk_cache_enabled

path = path_to(hash(key))
File.file?(path) && File.readable?(path)
end
Expand All @@ -103,6 +107,7 @@ def self.clear_if_config_changed(config)
config = config.inspect
cache = Jekyll::Cache.new "Jekyll::Cache"
return if cache.key?("config") && cache["config"] == config

clear
cache = Jekyll::Cache.new "Jekyll::Cache"
cache["config"] = config
Expand All @@ -116,6 +121,7 @@ def self.clear_if_config_changed(config)
def path_to(hash = nil)
@base_dir ||= File.join(@@base_dir, @name)
return @base_dir if hash.nil?

File.join(@base_dir, hash[0..1], hash[2..-1]).freeze
end

Expand Down Expand Up @@ -145,6 +151,7 @@ def self.delete_cache_files
# rubocop:disable Security/MarshalLoad
def load(path)
raise unless @@disk_cache_enabled

cached_file = File.open(path, "rb")
value = Marshal.load(cached_file)
cached_file.close
Expand All @@ -158,6 +165,7 @@ def load(path)
# Returns nothing.
def dump(path, value)
return unless @@disk_cache_enabled

dir = File.dirname(path)
FileUtils.mkdir_p(dir)
File.open(path, "wb") do |cached_file|
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def existing_files

Utils.safe_glob(site.in_dest_dir, ["**", "*"], File::FNM_DOTMATCH).each do |file|
next if file =~ HIDDEN_FILE_REGEX || file =~ regex || dirs.include?(file)

files << file
end

Expand Down
4 changes: 4 additions & 0 deletions lib/jekyll/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def read
filtered_entries.each do |file_path|
full_path = collection_dir(file_path)
next if File.directory?(full_path)

if Utils.has_yaml_header? full_path
read_document(full_path)
else
Expand All @@ -73,6 +74,7 @@ def read
# relative to the collection's directory
def entries
return [] unless exists?

@entries ||=
Utils.safe_glob(collection_dir, ["**", "*"], File::FNM_DOTMATCH).map do |entry|
entry["#{collection_dir}/"] = ""
Expand All @@ -86,6 +88,7 @@ def entries
# Returns a list of filtered entry paths.
def filtered_entries
return [] unless exists?

@filtered_entries ||=
Dir.chdir(directory) do
entry_filter.filter(entries).reject do |f|
Expand Down Expand Up @@ -124,6 +127,7 @@ def directory
# is stored on the filesystem.
def collection_dir(*files)
return directory if files.empty?

site.in_source_dir(container, relative_directory, *files)
end

Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def process_site(site)
# Returns a full Jekyll configuration
def configuration_from_options(options)
return options if options.is_a?(Jekyll::Configuration)

Jekyll.configuration(options)
end

Expand Down
7 changes: 7 additions & 0 deletions lib/jekyll/commands/doctor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ def healthy?(site)

def properly_gathered_posts?(site)
return true if site.config["collections_dir"].empty?

posts_at_root = site.in_source_dir("_posts")
return true unless File.directory?(posts_at_root)

Jekyll.logger.warn "Warning:",
"Detected '_posts' directory outside custom `collections_dir`!"
Jekyll.logger.warn "",
Expand All @@ -70,6 +72,7 @@ def conflicting_urls(site)
urls = collect_urls(urls, site.posts.docs, site.dest)
urls.each do |url, paths|
next unless paths.size > 1

conflicting_urls = true
Jekyll.logger.warn "Conflict:", "The URL '#{url}' is the destination" \
" for the following pages: #{paths.join(", ")}"
Expand All @@ -79,6 +82,7 @@ def conflicting_urls(site)

def fsnotify_buggy?(_site)
return true unless Utils::Platforms.osx?

if Dir.pwd != `pwd`.strip
Jekyll.logger.error " " + <<-STR.strip.gsub(%r!\n\s+!, "\n ")
We have detected that there might be trouble using fsevent on your
Expand All @@ -98,6 +102,7 @@ def urls_only_differ_by_case(site)
urls = case_insensitive_urls(site.pages + site.docs_to_write, site.dest)
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" \
" by case. On a case-insensitive file system one of the URLs" \
Expand Down Expand Up @@ -138,6 +143,7 @@ def case_insensitive_urls(things, destination)

def url_exists?(url)
return true unless url.nil? || url.empty?

Jekyll.logger.warn "Warning:", "You didn't set an URL in the config file, "\
"you may encounter problems with some plugins."
false
Expand All @@ -156,6 +162,7 @@ def url_valid?(url)

def url_absolute(url)
return true if Addressable::URI.parse(url).absolute?

Jekyll.logger.warn "Warning:", "Your site URL does not seem to be absolute, "\
"check the value of `url` in your config file."
false
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/commands/serve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ def launch_browser(server, opts)
return system "start", address if Utils::Platforms.windows?
return system "xdg-open", address if Utils::Platforms.linux?
return system "open", address if Utils::Platforms.osx?

Jekyll.logger.error "Refusing to launch browser; " \
"Platform launcher unknown."
end
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def read_config_files(files)
begin
files.each do |config_file|
next if config_file.nil? || config_file.empty?

new_config = read_config_file(config_file)
configuration = Utils.deep_merge_hashes(configuration, new_config)
end
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/converters/markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Markdown < Converter

def setup
return if @setup ||= false

unless (@parser = get_processor)
Jekyll.logger.error "Invalid Markdown processor given:", @config["markdown"]
Jekyll.logger.info "", "Custom processors are not loaded in safe mode" if @config["safe"]
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/convertible.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def coffeescript_file?
# Returns true if the file has Liquid Tags or Variables, false otherwise.
def render_with_liquid?
return false if data["render_with_liquid"] == false

Jekyll::Utils.has_liquid_construct?(content)
end

Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def coffeescript_file?
# true otherwise.
def render_with_liquid?
return false if data["render_with_liquid"] == false

!(coffeescript_file? || yaml_file? || !Utils.has_liquid_construct?(content))
end

Expand Down Expand Up @@ -304,6 +305,7 @@ def to_s
# equal or greater than the other doc's path. See String#<=> for more details.
def <=>(other)
return nil unless other.respond_to?(:data)

cmp = data["date"] <=> other.data["date"]
cmp = path <=> other.path if cmp.nil? || cmp.zero?
cmp
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/drops/document_drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def excerpt

def <=>(other)
return nil unless other.is_a? DocumentDrop

cmp = self["date"] <=> other["date"]
cmp = self["path"] <=> other["path"] if cmp.nil? || cmp.zero?
cmp
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/drops/drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def content_methods
def key?(key)
return false if key.nil?
return true if self.class.mutable? && @mutations.key?(key)

respond_to?(key) || fallback_data.key?(key)
end

Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/drops/site_drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def collections
# We should remove this in 4.0 and switch to `{{ post.related_posts }}`.
def related_posts
return nil unless @current_document.is_a?(Jekyll::Document)

@current_document.related_posts
end
attr_writer :current_document
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/entry_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def filter(entries)
next true if symlink?(e)
# Do not reject this entry if it is included.
next false if included?(e)

# Reject this entry if it is special, a backup file, or excluded.
special?(e) || backup?(e) || excluded?(e)
end
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/excerpt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def place_in_layout?

def render_with_liquid?
return false if data["render_with_liquid"] == false

!(coffeescript_file? || yaml_file? || !Utils.has_liquid_construct?(content))
end

Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/external.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def require_if_present(names)
# RubyGems.
def version_constraint(gem_name)
return "= #{Jekyll::VERSION}" if gem_name.to_s.eql?("jekyll-docs")

"> 0"
end

Expand Down
10 changes: 10 additions & 0 deletions lib/jekyll/filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def jsonify(input)
def where(input, property, value)
return input if property.nil? || value.nil?
return input unless input.respond_to?(:select)

input = input.values if input.is_a?(Hash)
input_id = input.hash

Expand All @@ -195,6 +196,7 @@ def where(input, property, value)
# Returns the filtered array of objects
def where_exp(input, variable, expression)
return input unless input.respond_to?(:select)

input = input.values if input.is_a?(Hash) # FIXME

condition = parse_condition(expression)
Expand All @@ -214,6 +216,7 @@ def where_exp(input, variable, expression)
def to_integer(input)
return 1 if input == true
return 0 if input == false

input.to_i
end

Expand All @@ -226,6 +229,7 @@ def to_integer(input)
# Returns the filtered array of objects
def sort(input, property = nil, nils = "first")
raise ArgumentError, "Cannot sort a null object." if input.nil?

if property.nil?
input.sort
else
Expand All @@ -244,6 +248,7 @@ def sort(input, property = nil, nils = "first")

def pop(array, num = 1)
return array unless array.is_a?(Array)

num = Liquid::Utils.to_integer(num)
new_ary = array.dup
new_ary.pop(num)
Expand All @@ -252,13 +257,15 @@ def pop(array, num = 1)

def push(array, input)
return array unless array.is_a?(Array)

new_ary = array.dup
new_ary.push(input)
new_ary
end

def shift(array, num = 1)
return array unless array.is_a?(Array)

num = Liquid::Utils.to_integer(num)
new_ary = array.dup
new_ary.shift(num)
Expand All @@ -267,13 +274,15 @@ def shift(array, num = 1)

def unshift(array, input)
return array unless array.is_a?(Array)

new_ary = array.dup
new_ary.unshift(input)
new_ary
end

def sample(input, num = 1)
return input unless input.respond_to?(:sample)

num = Liquid::Utils.to_integer(num) rescue 1
if num == 1
input.sample
Expand Down Expand Up @@ -330,6 +339,7 @@ def item_property(item, property)
def parse_sort_input(property)
number_like = %r!\A\s*-?(?:\d+\.?\d*|\.\d+)\s*\Z!
return property.to_f if property =~ number_like

property
end

Expand Down
4 changes: 4 additions & 0 deletions lib/jekyll/filters/date_filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def date_to_long_string(date, type = nil, style = nil)
# Returns the formatted String.
def date_to_xmlschema(date)
return date if date.to_s.empty?

time(date).xmlschema
end

Expand All @@ -60,6 +61,7 @@ def date_to_xmlschema(date)
# Returns the formatted String.
def date_to_rfc822(date)
return date if date.to_s.empty?

time(date).rfc822
end

Expand All @@ -72,11 +74,13 @@ def date_to_rfc822(date)
# Returns a stringified date or the empty input.
def stringify_date(date, month_type, type = nil, style = nil)
return date if date.to_s.empty?

time = time(date)
if type == "ordinal"
day = time.day
ordinal_day = "#{day}#{ordinal(day)}"
return time.strftime("#{month_type} #{ordinal_day}, %Y") if style == "US"

return time.strftime("#{ordinal_day} #{month_type} %Y")
end
time.strftime("%d #{month_type} %Y")
Expand Down
Loading

0 comments on commit a28f54a

Please sign in to comment.