diff --git a/.rubocop.yml b/.rubocop.yml index 223d3aae..652f08fb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -31,7 +31,7 @@ HashSyntax: EnforcedStyle: ruby19 SpaceAroundEqualsInParameterDefault: EnforcedStyle: no_space -Blocks: +BlockDelimiters: Enabled: false PerlBackrefs: Enabled: false diff --git a/middleman-core/lib/middleman-core/extensions/asset_hash.rb b/middleman-core/lib/middleman-core/extensions/asset_hash.rb index 531b4442..39f1a069 100644 --- a/middleman-core/lib/middleman-core/extensions/asset_hash.rb +++ b/middleman-core/lib/middleman-core/extensions/asset_hash.rb @@ -75,7 +75,7 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension # Render through the Rack interface so middleware and mounted apps get a shot response = @rack_client.get(URI.escape(resource.destination_path), 'bypass_inline_url_rewriter_asset_hash' => 'true' - ) + ) raise "#{resource.path} should be in the sitemap!" unless response.status == 200 diff --git a/middleman-core/lib/middleman-core/extensions/lorem.rb b/middleman-core/lib/middleman-core/extensions/lorem.rb index 32f1c6c1..91a0612d 100644 --- a/middleman-core/lib/middleman-core/extensions/lorem.rb +++ b/middleman-core/lib/middleman-core/extensions/lorem.rb @@ -152,8 +152,8 @@ class Middleman::Extensions::Lorem < ::Middleman::Extension color = options[:color] if options[:random_color] - background_color = hex.shuffle[0...6].join - color = hex.shuffle[0...6].join + background_color = hex.sample(6).join + color = hex.sample(6).join end src << "/#{background_color.sub(/^#/, '')}" if background_color diff --git a/middleman-core/lib/middleman-core/middleware/inline_url_rewriter.rb b/middleman-core/lib/middleman-core/middleware/inline_url_rewriter.rb index 1151800c..b1eddd11 100644 --- a/middleman-core/lib/middleman-core/middleware/inline_url_rewriter.rb +++ b/middleman-core/lib/middleman-core/middleware/inline_url_rewriter.rb @@ -89,6 +89,7 @@ module Middleman File.fnmatch(value, validator) else # If some unknown thing, don't ignore + false end end end diff --git a/middleman-core/lib/middleman-core/sitemap/extensions/proxies.rb b/middleman-core/lib/middleman-core/sitemap/extensions/proxies.rb index 536200db..da23c9e9 100644 --- a/middleman-core/lib/middleman-core/sitemap/extensions/proxies.rb +++ b/middleman-core/lib/middleman-core/sitemap/extensions/proxies.rb @@ -74,7 +74,7 @@ module Middleman locals: md.delete(:locals) || {}, page: md.delete(:data) || {}, options: md - ) + ) end end end diff --git a/middleman-core/lib/middleman-core/sitemap/extensions/redirects.rb b/middleman-core/lib/middleman-core/sitemap/extensions/redirects.rb index 84f96749..418f5d73 100644 --- a/middleman-core/lib/middleman-core/sitemap/extensions/redirects.rb +++ b/middleman-core/lib/middleman-core/sitemap/extensions/redirects.rb @@ -63,7 +63,7 @@ module Middleman url = ::Middleman::Util.url_for(@store.app, @request_path, relative: false, find_resource: true - ) + ) if output output.call(path, url) diff --git a/middleman-core/lib/middleman-core/sources.rb b/middleman-core/lib/middleman-core/sources.rb index 005bdde1..87b0d957 100644 --- a/middleman-core/lib/middleman-core/sources.rb +++ b/middleman-core/lib/middleman-core/sources.rb @@ -14,6 +14,8 @@ module Middleman extend Forwardable include Contracts + Matcher = Or[Regexp, RespondTo[:call]] + # A reference to the current app. Contract IsA['Middleman::Application'] attr_reader :app @@ -246,28 +248,24 @@ module Middleman # Backwards compatible change handler. # # @param [nil,Regexp] matcher A Regexp to match the change path against - # Contract Maybe[Regexp] => Any + Contract Maybe[Matcher] => Any def changed(matcher=nil, &block) on_change :source do |updated, _removed| - updated.select { |f| - matcher.nil? ? true : matches?(matcher, f) - }.each do |f| - block.call(f[:relative_path]) - end + updated + .select { |f| matcher.nil? ? true : matches?(matcher, f) } + .each { |f| block.call(f[:relative_path]) } end end # Backwards compatible delete handler. # # @param [nil,Regexp] matcher A Regexp to match the change path against - # Contract Maybe[Regexp] => Any + Contract Maybe[Matcher] => Any def deleted(matcher=nil, &block) on_change :source do |_updated, removed| - removed.select { |f| - matcher.nil? ? true : matches?(matcher, f) - }.each do |f| - block.call(f[:relative_path]) - end + removed + .select { |f| matcher.nil? ? true : matches?(matcher, f) } + .each { |f| block.call(f[:relative_path]) } end end @@ -287,7 +285,7 @@ module Middleman # @param [Regexp, #call] validator The match validator. # @param [Middleman::SourceFile] file The file to check. # @return [Boolean] - Contract Or[Regexp, RespondTo[:call]], SourceFile => Bool + Contract Matcher, SourceFile => Bool def matches?(validator, file) path = file[:relative_path] if validator.is_a? Regexp diff --git a/middleman-core/lib/middleman-core/sources/source_watcher.rb b/middleman-core/lib/middleman-core/sources/source_watcher.rb index e09a8aba..6722727f 100644 --- a/middleman-core/lib/middleman-core/sources/source_watcher.rb +++ b/middleman-core/lib/middleman-core/sources/source_watcher.rb @@ -252,7 +252,7 @@ module Middleman Contract Pathname => Pathname def strip_extensions(p) - p = p.sub_ext('') while ::Tilt[p.to_s] || p.extname === '.html' + p = p.sub_ext('') while ::Tilt[p.to_s] || p.extname == '.html' Pathname(p.to_s + '.*') end @@ -262,9 +262,9 @@ module Middleman # @return [Boolean] Contract IsA['Middleman::SourceFile'] => Bool def valid?(file) - globally_valid = @validator.call(file) && !globally_ignored?(file) + return false unless @validator.call(file) && !globally_ignored?(file) - globally_valid && if @only.empty? + if @only.empty? !@ignored.call(file) else @only.any? { |reg| reg.match(file[:relative_path].to_s) } diff --git a/middleman-core/lib/middleman-core/util.rb b/middleman-core/lib/middleman-core/util.rb index 44f7b3f7..945c4f96 100644 --- a/middleman-core/lib/middleman-core/util.rb +++ b/middleman-core/lib/middleman-core/util.rb @@ -87,13 +87,11 @@ module Middleman end end - def method_missing(key, *args) + def method_missing(key, *_args) if key?(key.to_sym) self[key.to_sym] elsif key?(key.to_s) self[key.to_s] - else - super end end end @@ -131,7 +129,6 @@ module Middleman end end - # Normalize a path to not include a leading slash # @param [String] path # @return [String]