From d213981a24c72f1b441f91906bce5c0da0336180 Mon Sep 17 00:00:00 2001 From: Florian Thomas Date: Wed, 17 Feb 2016 22:27:38 +0100 Subject: [PATCH] Fix warnings This removes the following warnings: - /lib/jekyll/configuration.rb:151: warning: instance variable @default_config_file not initialized - /lib/jekyll/converter.rb:12: warning: instance variable @highlighter_prefix not initialized - /lib/jekyll/converter.rb:24: warning: instance variable @highlighter_suffix not initialized - /lib/jekyll/converters/markdown.rb:9: warning: instance variable @setup not initialized - /lib/jekyll/converters/markdown/kramdown_parser.rb:60: warning: instance variable @highlighter not initialized - /lib/jekyll/frontmatter_defaults.rb:97: warning: shadowing outer local variable - path - /lib/jekyll/plugin.rb:66: warning: instance variable @safe not initialized - /lib/jekyll/regenerator.rb:147: warning: instance variable @disabled not initialized - /test/test_convertible.rb:40: warning: ambiguous first argument; put parentheses or a space even after `/' operator - /test/test_filters.rb:154: warning: ambiguous first argument; put parentheses or a space even after `/' operator - /test/test_new_command.rb:84: warning: ambiguous first argument; put parentheses or a space even after `/' operator - /test/test_site.rb:234: warning: assigned but unused variable - site - /test/test_site.rb:240: warning: assigned but unused variable - site - /test/test_site.rb:522: warning: assigned but unused variable - source - /test/test_tags.rb:153: warning: ambiguous first argument; put parentheses or a space even after `/' operator - /test/test_tags.rb:425: warning: ambiguous first argument; put parentheses or a space even after `/' operator - /test/test_tags.rb:449: warning: ambiguous first argument; put parentheses or a space even after `/' operator - /test/test_tags.rb:496: warning: ambiguous first argument; put parentheses or a space even after `/' operator - /test/test_tags.rb:496: warning: instance variable @result not initialized - /test/test_tags.rb:511: warning: ambiguous first argument; put parentheses or a space even after `/' operator - /test/test_tags.rb:773: warning: ambiguous first argument; put parentheses or a space even after `/' operator - /test/test_tags.rb:773: warning: instance variable @result not initialized - /test/test_tags.rb:788: warning: ambiguous first argument; put parentheses or a space even after `/' operator - /test/test_url.rb:66: warning: shadowing outer local variable - doc - /lib/jekyll/url.rb:119:in `escape_path': warning: URI.escape is obsolete --- lib/jekyll/configuration.rb | 2 +- lib/jekyll/converter.rb | 8 ++++++-- lib/jekyll/converters/markdown.rb | 2 +- .../converters/markdown/kramdown_parser.rb | 1 + lib/jekyll/frontmatter_defaults.rb | 4 ++-- lib/jekyll/plugin.rb | 2 +- lib/jekyll/regenerator.rb | 8 +++++--- test/test_convertible.rb | 2 +- test/test_filters.rb | 2 +- test/test_new_command.rb | 2 +- test/test_site.rb | 5 ++--- test/test_tags.rb | 16 +++++++++------- test/test_url.rb | 4 ++-- 13 files changed, 33 insertions(+), 25 deletions(-) diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index 0f8618a1..1ef67ae6 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -148,7 +148,7 @@ module Jekyll Jekyll.logger.info "Configuration file:", file next_config rescue SystemCallError - if @default_config_file + if @default_config_file ||= nil Jekyll.logger.warn "Configuration file:", "none" {} else diff --git a/lib/jekyll/converter.rb b/lib/jekyll/converter.rb index c30f4944..f9d2ce16 100644 --- a/lib/jekyll/converter.rb +++ b/lib/jekyll/converter.rb @@ -8,7 +8,9 @@ module Jekyll # # Returns the String prefix. def self.highlighter_prefix(highlighter_prefix = nil) - @highlighter_prefix = highlighter_prefix if highlighter_prefix + if !defined?(@highlighter_prefix) || !highlighter_prefix.nil? + @highlighter_prefix = highlighter_prefix + end @highlighter_prefix end @@ -20,7 +22,9 @@ module Jekyll # # Returns the String suffix. def self.highlighter_suffix(highlighter_suffix = nil) - @highlighter_suffix = highlighter_suffix if highlighter_suffix + if !defined?(@highlighter_suffix) || !highlighter_suffix.nil? + @highlighter_suffix = highlighter_suffix + end @highlighter_suffix end diff --git a/lib/jekyll/converters/markdown.rb b/lib/jekyll/converters/markdown.rb index aed906d7..6e44b3b2 100644 --- a/lib/jekyll/converters/markdown.rb +++ b/lib/jekyll/converters/markdown.rb @@ -6,7 +6,7 @@ module Jekyll safe true def setup - return if @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"] diff --git a/lib/jekyll/converters/markdown/kramdown_parser.rb b/lib/jekyll/converters/markdown/kramdown_parser.rb index 93605cdd..4d84a5bc 100644 --- a/lib/jekyll/converters/markdown/kramdown_parser.rb +++ b/lib/jekyll/converters/markdown/kramdown_parser.rb @@ -18,6 +18,7 @@ module Jekyll Jekyll::External.require_with_graceful_fail "kramdown" @main_fallback_highlighter = config["highlighter"] || "rouge" @config = config["kramdown"] || {} + @highlighter = nil setup end diff --git a/lib/jekyll/frontmatter_defaults.rb b/lib/jekyll/frontmatter_defaults.rb index 877f517e..22df50f2 100644 --- a/lib/jekyll/frontmatter_defaults.rb +++ b/lib/jekyll/frontmatter_defaults.rb @@ -94,8 +94,8 @@ module Jekyll return true if !scope.key?('path') || scope['path'].empty? scope_path = Pathname.new(scope['path']) - Pathname.new(sanitize_path(path)).ascend do |path| - if path.to_s == scope_path.to_s + Pathname.new(sanitize_path(path)).ascend do |ascended_path| + if ascended_path.to_s == scope_path.to_s return true end end diff --git a/lib/jekyll/plugin.rb b/lib/jekyll/plugin.rb index e2a95168..1fb91058 100644 --- a/lib/jekyll/plugin.rb +++ b/lib/jekyll/plugin.rb @@ -60,7 +60,7 @@ module Jekyll # # Returns the safety Boolean. def self.safe(safe = nil) - if safe + if !defined?(@safe) || !safe.nil? @safe = safe end @safe || false diff --git a/lib/jekyll/regenerator.rb b/lib/jekyll/regenerator.rb index 20522350..830ea914 100644 --- a/lib/jekyll/regenerator.rb +++ b/lib/jekyll/regenerator.rb @@ -1,6 +1,8 @@ module Jekyll class Regenerator attr_reader :site, :metadata, :cache + attr_accessor :disabled + private :disabled, :disabled= def initialize(site) @site = site @@ -115,7 +117,7 @@ module Jekyll # # Returns nothing. def add_dependency(path, dependency) - return if metadata[path].nil? || @disabled + return if metadata[path].nil? || disabled unless metadata[path]["deps"].include? dependency metadata[path]["deps"] << dependency @@ -144,8 +146,8 @@ module Jekyll # # Returns a Boolean (true for disabled, false for enabled). def disabled? - @disabled = !site.incremental? if @disabled.nil? - @disabled + self.disabled = !site.incremental? if disabled.nil? + disabled end private diff --git a/test/test_convertible.rb b/test/test_convertible.rb index 524ecdf4..517f5c3b 100644 --- a/test/test_convertible.rb +++ b/test/test_convertible.rb @@ -37,7 +37,7 @@ class TestConvertible < JekyllUnitTest out = capture_stderr do @convertible.read_yaml(@base, 'exploit_front_matter.erb') end - refute_match /undefined class\/module DoesNotExist/, out + refute_match(/undefined class\/module DoesNotExist/, out) end should "not parse if there is encoding error in file" do diff --git a/test/test_filters.rb b/test/test_filters.rb index ca7cd49d..8fd24c55 100644 --- a/test/test_filters.rb +++ b/test/test_filters.rb @@ -151,7 +151,7 @@ class TestFilters < JekyllUnitTest end should "format a time with xmlschema" do - assert_match /2014-05-10T00:10:07/, @filter.date_to_xmlschema(@time_as_numeric) + assert_match(/2014-05-10T00:10:07/, @filter.date_to_xmlschema(@time_as_numeric)) end should "format a time according to RFC-822" do diff --git a/test/test_new_command.rb b/test/test_new_command.rb index f0d2a389..90462904 100644 --- a/test/test_new_command.rb +++ b/test/test_new_command.rb @@ -81,7 +81,7 @@ class TestNewCommand < JekyllUnitTest should 'force created folder' do capture_stdout { Jekyll::Commands::New.process(@args) } output = capture_stdout { Jekyll::Commands::New.process(@args, '--force') } - assert_match /New jekyll site installed in/, output + assert_match(/New jekyll site installed in/, output) end end diff --git a/test/test_site.rb b/test/test_site.rb index c06c218e..ddd54655 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -231,13 +231,13 @@ class TestSite < JekyllUnitTest context 'error handling' do should "raise if destination is included in source" do assert_raises Jekyll::Errors::FatalException do - site = Site.new(site_configuration('destination' => source_dir)) + Site.new(site_configuration('destination' => source_dir)) end end should "raise if destination is source" do assert_raises Jekyll::Errors::FatalException do - site = Site.new(site_configuration('destination' => File.join(source_dir, ".."))) + Site.new(site_configuration('destination' => File.join(source_dir, ".."))) end end end @@ -519,7 +519,6 @@ class TestSite < JekyllUnitTest contacts_html = @site.pages.find { |p| p.name == "contacts.html" } @site.process - source = @site.in_source_dir(contacts_html.path) dest = File.expand_path(contacts_html.destination(@site.dest)) mtime1 = File.stat(dest).mtime.to_i # first run must generate dest file diff --git a/test/test_tags.rb b/test/test_tags.rb index f263e9d8..0dd8cac8 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -150,7 +150,7 @@ CONTENT end should "not cause a markdown error" do - refute_match /markdown\-html\-error/, @result + refute_match(/markdown\-html\-error/, @result) end should "render markdown with pygments" do @@ -422,7 +422,7 @@ CONTENT end should "not cause an error" do - refute_match /markdown\-html\-error/, @result + refute_match(/markdown\-html\-error/, @result) end should "have the url to the \"complex\" post from 2008-11-21" do @@ -446,7 +446,7 @@ CONTENT end should "not cause an error" do - refute_match /markdown\-html\-error/, @result + refute_match(/markdown\-html\-error/, @result) end should "have the url to the \"complex\" post from 2008-11-21" do @@ -493,7 +493,8 @@ title: Include symlink CONTENT create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true, 'safe' => true }) end - refute_match /SYMLINK TEST/, @result + @result ||= '' + refute_match(/SYMLINK TEST/, @result) end should "not expose the existence of symlinked files" do @@ -508,7 +509,7 @@ title: Include symlink CONTENT create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true, 'safe' => true }) end - assert_match /should exist and should not be a symlink/, ex.message + assert_match(/should exist and should not be a symlink/, ex.message) end end @@ -770,7 +771,8 @@ title: Include symlink CONTENT create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true, 'safe' => true }) end - refute_match /SYMLINK TEST/, @result + @result ||= '' + refute_match(/SYMLINK TEST/, @result) end should "not expose the existence of symlinked files" do @@ -785,7 +787,7 @@ title: Include symlink CONTENT create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true, 'safe' => true }) end - assert_match /should exist and should not be a symlink/, ex.message + assert_match(/should exist and should not be a symlink/, ex.message) end end end diff --git a/test/test_url.rb b/test/test_url.rb index 578e8962..99ee5e61 100644 --- a/test/test_url.rb +++ b/test/test_url.rb @@ -63,12 +63,12 @@ class TestURL < JekyllUnitTest }, }) site.read - doc = site.collections["methods"].docs.find do |doc| + matching_doc = site.collections["methods"].docs.find do |doc| doc.relative_path == "_methods/escape-+ #%20[].md" end assert_equal '/methods/escape-+-20/escape-20.html', URL.new( :template => '/methods/:title/:name:output_ext', - :placeholders => doc.url_placeholders + :placeholders => matching_doc.url_placeholders ).to_s end