Rubocop: Low hanging fruit
This commit is contained in:
		
							parent
							
								
									e02049727b
								
							
						
					
					
						commit
						a8d27e5788
					
				
							
								
								
									
										23
									
								
								.rubocop.yml
								
								
								
								
							
							
						
						
									
										23
									
								
								.rubocop.yml
								
								
								
								
							|  | @ -7,51 +7,28 @@ AllCops: | ||||||
|   - lib/jekyll/collection.rb |   - lib/jekyll/collection.rb | ||||||
|   - lib/jekyll/command.rb |   - lib/jekyll/command.rb | ||||||
|   - lib/jekyll/configuration.rb |   - lib/jekyll/configuration.rb | ||||||
|   - lib/jekyll/converter.rb |  | ||||||
|   - lib/jekyll/converters/identity.rb |   - lib/jekyll/converters/identity.rb | ||||||
|   - lib/jekyll/converters/markdown |  | ||||||
|   - lib/jekyll/converters/markdown/kramdown_parser.rb |   - lib/jekyll/converters/markdown/kramdown_parser.rb | ||||||
|   - lib/jekyll/converters/markdown/rdiscount_parser.rb |  | ||||||
|   - lib/jekyll/converters/markdown/redcarpet_parser.rb |   - lib/jekyll/converters/markdown/redcarpet_parser.rb | ||||||
|   - lib/jekyll/converters/markdown.rb |   - lib/jekyll/converters/markdown.rb | ||||||
|   - lib/jekyll/converters/smartypants.rb |  | ||||||
|   - lib/jekyll/convertible.rb |   - lib/jekyll/convertible.rb | ||||||
|   - lib/jekyll/deprecator.rb |   - lib/jekyll/deprecator.rb | ||||||
|   - lib/jekyll/document.rb |   - lib/jekyll/document.rb | ||||||
|   - lib/jekyll/drops/collection_drop.rb |  | ||||||
|   - lib/jekyll/drops/document_drop.rb |  | ||||||
|   - lib/jekyll/drops/drop.rb |  | ||||||
|   - lib/jekyll/drops/jekyll_drop.rb |  | ||||||
|   - lib/jekyll/drops/site_drop.rb |   - lib/jekyll/drops/site_drop.rb | ||||||
|   - lib/jekyll/drops/unified_payload_drop.rb |  | ||||||
|   - lib/jekyll/drops/url_drop.rb |  | ||||||
|   - lib/jekyll/entry_filter.rb |   - lib/jekyll/entry_filter.rb | ||||||
|   - lib/jekyll/errors.rb |  | ||||||
|   - lib/jekyll/excerpt.rb |  | ||||||
|   - lib/jekyll/external.rb |  | ||||||
|   - lib/jekyll/filters.rb |   - lib/jekyll/filters.rb | ||||||
|   - lib/jekyll/frontmatter_defaults.rb |   - lib/jekyll/frontmatter_defaults.rb | ||||||
|   - lib/jekyll/generator.rb |  | ||||||
|   - lib/jekyll/hooks.rb |  | ||||||
|   - lib/jekyll/layout.rb |   - lib/jekyll/layout.rb | ||||||
|   - lib/jekyll/liquid_extensions.rb |  | ||||||
|   - lib/jekyll/liquid_renderer/file.rb |  | ||||||
|   - lib/jekyll/liquid_renderer/table.rb |   - lib/jekyll/liquid_renderer/table.rb | ||||||
|   - lib/jekyll/liquid_renderer.rb |   - lib/jekyll/liquid_renderer.rb | ||||||
|   - lib/jekyll/log_adapter.rb |  | ||||||
|   - lib/jekyll/page.rb |   - lib/jekyll/page.rb | ||||||
|   - lib/jekyll/plugin.rb |  | ||||||
|   - lib/jekyll/plugin_manager.rb |   - lib/jekyll/plugin_manager.rb | ||||||
|   - lib/jekyll/publisher.rb |  | ||||||
|   - lib/jekyll/reader.rb |   - lib/jekyll/reader.rb | ||||||
|   - lib/jekyll/readers/collection_reader.rb |  | ||||||
|   - lib/jekyll/readers/data_reader.rb |  | ||||||
|   - lib/jekyll/readers/layout_reader.rb |   - lib/jekyll/readers/layout_reader.rb | ||||||
|   - lib/jekyll/readers/page_reader.rb |   - lib/jekyll/readers/page_reader.rb | ||||||
|   - lib/jekyll/readers/post_reader.rb |   - lib/jekyll/readers/post_reader.rb | ||||||
|   - lib/jekyll/readers/static_file_reader.rb |   - lib/jekyll/readers/static_file_reader.rb | ||||||
|   - lib/jekyll/regenerator.rb |   - lib/jekyll/regenerator.rb | ||||||
|   - lib/jekyll/related_posts.rb |  | ||||||
|   - lib/jekyll/renderer.rb |   - lib/jekyll/renderer.rb | ||||||
|   - lib/jekyll/site.rb |   - lib/jekyll/site.rb | ||||||
|   - lib/jekyll/static_file.rb |   - lib/jekyll/static_file.rb | ||||||
|  |  | ||||||
|  | @ -5,14 +5,14 @@ module Jekyll | ||||||
|         def initialize(config) |         def initialize(config) | ||||||
|           Jekyll::External.require_with_graceful_fail "rdiscount" |           Jekyll::External.require_with_graceful_fail "rdiscount" | ||||||
|           @config = config |           @config = config | ||||||
|           @rdiscount_extensions = @config['rdiscount']['extensions'].map(&:to_sym) |           @rdiscount_extensions = @config["rdiscount"]["extensions"].map(&:to_sym) | ||||||
|         end |         end | ||||||
| 
 | 
 | ||||||
|         def convert(content) |         def convert(content) | ||||||
|           rd = RDiscount.new(content, *@rdiscount_extensions) |           rd = RDiscount.new(content, *@rdiscount_extensions) | ||||||
|           html = rd.to_html |           html = rd.to_html | ||||||
|           if @config['rdiscount']['toc_token'] |           if @config["rdiscount"]["toc_token"] | ||||||
|             html = replace_generated_toc(rd, html, @config['rdiscount']['toc_token']) |             html = replace_generated_toc(rd, html, @config["rdiscount"]["toc_token"]) | ||||||
|           end |           end | ||||||
|           html |           html | ||||||
|         end |         end | ||||||
|  | @ -21,7 +21,7 @@ module Jekyll | ||||||
|         def replace_generated_toc(rd, html, toc_token) |         def replace_generated_toc(rd, html, toc_token) | ||||||
|           if rd.generate_toc && html.include?(toc_token) |           if rd.generate_toc && html.include?(toc_token) | ||||||
|             utf8_toc = rd.toc_content |             utf8_toc = rd.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 | ||||||
|             html |             html | ||||||
|  |  | ||||||
|  | @ -17,13 +17,13 @@ module Jekyll | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|       def excerpt |       def excerpt | ||||||
|         fallback_data['excerpt'].to_s |         fallback_data["excerpt"].to_s | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|       def <=>(other) |       def <=>(other) | ||||||
|         return nil unless other.is_a? DocumentDrop |         return nil unless other.is_a? DocumentDrop | ||||||
|         cmp = self['date'] <=> other['date'] |         cmp = self["date"] <=> other["date"] | ||||||
|         cmp = self['path'] <=> other['path'] if cmp.nil? || cmp == 0 |         cmp = self["path"] <=> other["path"] if cmp.nil? || cmp == 0 | ||||||
|         cmp |         cmp | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -13,10 +13,10 @@ module Jekyll | ||||||
|       # |       # | ||||||
|       # Returns the mutability of the class |       # Returns the mutability of the class | ||||||
|       def self.mutable(is_mutable = nil) |       def self.mutable(is_mutable = nil) | ||||||
|         if is_mutable |         @is_mutable = if is_mutable | ||||||
|           @is_mutable = is_mutable |                         is_mutable | ||||||
|                       else |                       else | ||||||
|           @is_mutable = false |                         false | ||||||
|                       end |                       end | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|  | @ -134,7 +134,7 @@ module Jekyll | ||||||
|       # |       # | ||||||
|       # Returns a pretty generation of the hash representation of the Drop. |       # Returns a pretty generation of the hash representation of the Drop. | ||||||
|       def inspect |       def inspect | ||||||
|         require 'json' |         require "json" | ||||||
|         JSON.pretty_generate to_h |         JSON.pretty_generate to_h | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -19,20 +19,20 @@ module Jekyll | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|       def title |       def title | ||||||
|         Utils.slugify(@obj.data['slug'], :mode => "pretty", :cased => true) || |         Utils.slugify(@obj.data["slug"], :mode => "pretty", :cased => true) || | ||||||
|           Utils.slugify(@obj.basename_without_ext, :mode => "pretty", :cased => true) |           Utils.slugify(@obj.basename_without_ext, :mode => "pretty", :cased => true) | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|       def slug |       def slug | ||||||
|         Utils.slugify(@obj.data['slug']) || Utils.slugify(@obj.basename_without_ext) |         Utils.slugify(@obj.data["slug"]) || Utils.slugify(@obj.basename_without_ext) | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|       def categories |       def categories | ||||||
|         category_set = Set.new |         category_set = Set.new | ||||||
|         Array(@obj.data['categories']).each do |category| |         Array(@obj.data["categories"]).each do |category| | ||||||
|           category_set << category.to_s.downcase |           category_set << category.to_s.downcase | ||||||
|         end |         end | ||||||
|         category_set.to_a.join('/') |         category_set.to_a.join("/") | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|       def year |       def year | ||||||
|  |  | ||||||
|  | @ -59,9 +59,9 @@ module Jekyll | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|     def to_liquid |     def to_liquid | ||||||
|       doc.data['excerpt'] = nil |       doc.data["excerpt"] = nil | ||||||
|       @to_liquid ||= doc.to_liquid |       @to_liquid ||= doc.to_liquid | ||||||
|       doc.data['excerpt'] = self |       doc.data["excerpt"] = self | ||||||
|       @to_liquid |       @to_liquid | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -23,7 +23,7 @@ module Jekyll | ||||||
|             require name |             require name | ||||||
|           rescue LoadError |           rescue LoadError | ||||||
|             Jekyll.logger.debug "Couldn't load #{name}. Skipping." |             Jekyll.logger.debug "Couldn't load #{name}. Skipping." | ||||||
|             block.call(name) if block |             yield(name) if block | ||||||
|             false |             false | ||||||
|           end |           end | ||||||
|         end |         end | ||||||
|  | @ -39,7 +39,7 @@ module Jekyll | ||||||
|       def require_with_graceful_fail(names) |       def require_with_graceful_fail(names) | ||||||
|         Array(names).each do |name| |         Array(names).each do |name| | ||||||
|           begin |           begin | ||||||
|             Jekyll.logger.debug "Requiring:", "#{name}" |             Jekyll.logger.debug "Requiring:", name.to_s | ||||||
|             require name |             require name | ||||||
|           rescue LoadError => e |           rescue LoadError => e | ||||||
|             Jekyll.logger.error "Dependency Error:", <<-MSG |             Jekyll.logger.error "Dependency Error:", <<-MSG | ||||||
|  | @ -50,7 +50,7 @@ The full error message from Ruby is: '#{e.message}' | ||||||
| 
 | 
 | ||||||
| If you run into trouble, you can find helpful resources at http://jekyllrb.com/help/! | If you run into trouble, you can find helpful resources at http://jekyllrb.com/help/! | ||||||
|             MSG |             MSG | ||||||
|             raise Jekyll::Errors::MissingDependencyException.new(name) |             raise Jekyll::Errors::MissingDependencyException, name | ||||||
|           end |           end | ||||||
|         end |         end | ||||||
|       end |       end | ||||||
|  |  | ||||||
|  | @ -8,7 +8,7 @@ module Jekyll | ||||||
| 
 | 
 | ||||||
|       def parse(content) |       def parse(content) | ||||||
|         measure_time do |         measure_time do | ||||||
|           @template = Liquid::Template.parse(content, line_numbers: true) |           @template = Liquid::Template.parse(content, :line_numbers => true) | ||||||
|         end |         end | ||||||
| 
 | 
 | ||||||
|         self |         self | ||||||
|  |  | ||||||
|  | @ -7,7 +7,7 @@ module Jekyll | ||||||
|       :info  => ::Logger::INFO, |       :info  => ::Logger::INFO, | ||||||
|       :warn  => ::Logger::WARN, |       :warn  => ::Logger::WARN, | ||||||
|       :error => ::Logger::ERROR |       :error => ::Logger::ERROR | ||||||
|     } |     }.freeze | ||||||
| 
 | 
 | ||||||
|     # Public: Create a new instance of a log writer |     # Public: Create a new instance of a log writer | ||||||
|     # |     # | ||||||
|  | @ -98,7 +98,7 @@ module Jekyll | ||||||
|     # |     # | ||||||
|     # Returns the formatted message |     # Returns the formatted message | ||||||
|     def message(topic, message) |     def message(topic, message) | ||||||
|       msg = formatted_topic(topic) + message.to_s.gsub(/\s+/, ' ') |       msg = formatted_topic(topic) + message.to_s.gsub(/\s+/, " ") | ||||||
|       messages << msg |       messages << msg | ||||||
|       msg |       msg | ||||||
|     end |     end | ||||||
|  |  | ||||||
|  | @ -6,7 +6,7 @@ module Jekyll | ||||||
|       :lowest  => -100, |       :lowest  => -100, | ||||||
|       :normal  => 0, |       :normal  => 0, | ||||||
|       :high    => 10 |       :high    => 10 | ||||||
|     } |     }.freeze | ||||||
| 
 | 
 | ||||||
|     # |     # | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -15,7 +15,7 @@ module Jekyll | ||||||
|     private |     private | ||||||
| 
 | 
 | ||||||
|     def can_be_published?(thing) |     def can_be_published?(thing) | ||||||
|       thing.data.fetch('published', true) || @site.unpublished |       thing.data.fetch("published", true) || @site.unpublished | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
| end | end | ||||||
|  |  | ||||||
|  | @ -30,14 +30,14 @@ module Jekyll | ||||||
|       return unless File.directory?(dir) && !@entry_filter.symlink?(dir) |       return unless File.directory?(dir) && !@entry_filter.symlink?(dir) | ||||||
| 
 | 
 | ||||||
|       entries = Dir.chdir(dir) do |       entries = Dir.chdir(dir) do | ||||||
|         Dir['*.{yaml,yml,json,csv}'] + Dir['*'].select { |fn| File.directory?(fn) } |         Dir["*.{yaml,yml,json,csv}"] + Dir["*"].select { |fn| File.directory?(fn) } | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|       entries.each do |entry| |       entries.each do |entry| | ||||||
|         path = @site.in_source_dir(dir, entry) |         path = @site.in_source_dir(dir, entry) | ||||||
|         next if @entry_filter.symlink?(path) |         next if @entry_filter.symlink?(path) | ||||||
| 
 | 
 | ||||||
|         key = sanitize_filename(File.basename(entry, '.*')) |         key = sanitize_filename(File.basename(entry, ".*")) | ||||||
|         if File.directory?(path) |         if File.directory?(path) | ||||||
|           read_data_to(path, data[key] = {}) |           read_data_to(path, data[key] = {}) | ||||||
|         else |         else | ||||||
|  | @ -51,10 +51,10 @@ module Jekyll | ||||||
|     # Returns the contents of the data file. |     # Returns the contents of the data file. | ||||||
|     def read_data_file(path) |     def read_data_file(path) | ||||||
|       case File.extname(path).downcase |       case File.extname(path).downcase | ||||||
|       when '.csv' |       when ".csv" | ||||||
|         CSV.read(path, { |         CSV.read(path, { | ||||||
|           :headers  => true, |           :headers  => true, | ||||||
|                          :encoding => site.config['encoding'] |           :encoding => site.config["encoding"] | ||||||
|         }).map(&:to_hash) |         }).map(&:to_hash) | ||||||
|       else |       else | ||||||
|         SafeYAML.load_file(path) |         SafeYAML.load_file(path) | ||||||
|  | @ -62,9 +62,9 @@ module Jekyll | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|     def sanitize_filename(name) |     def sanitize_filename(name) | ||||||
|       name.gsub!(/[^\w\s-]+/, '') |       name.gsub!(/[^\w\s-]+/, "") | ||||||
|       name.gsub!(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2') |       name.gsub!(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2') | ||||||
|       name.gsub(/\s+/, '_') |       name.gsub(/\s+/, "_") | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
| end | end | ||||||
|  |  | ||||||
|  | @ -9,7 +9,7 @@ module Jekyll | ||||||
|     def initialize(post) |     def initialize(post) | ||||||
|       @post = post |       @post = post | ||||||
|       @site = post.site |       @site = post.site | ||||||
|       Jekyll::External.require_with_graceful_fail('classifier-reborn') if site.lsi |       Jekyll::External.require_with_graceful_fail("classifier-reborn") if site.lsi | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|     def build |     def build | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue