Skip to content

Commit

Permalink
Enforce Style/FrozenStringLiteralComment.
Browse files Browse the repository at this point in the history
The frozen_string_literal: true magic comment in Ruby can help
dramatically decrease memory allocations for new strings and can thusly
speed up your program. The intent here is for Jekyll to use less memory
and make fewer memory allocations (which must later be GC'd).
  • Loading branch information
parkr committed Aug 3, 2017
1 parent 56436f4 commit e788ad5
Show file tree
Hide file tree
Showing 135 changed files with 287 additions and 19 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Expand Up @@ -9,6 +9,7 @@ AllCops:
- benchmark/**/*
- script/**/*
- vendor/**/*
- tmp/**/*
Layout/AlignArray:
Enabled: false
Layout/AlignHash:
Expand Down Expand Up @@ -99,6 +100,9 @@ Style/BracesAroundHashParameters:
Enabled: false
Style/ClassAndModuleChildren:
Enabled: false
Style/FrozenStringLiteralComment:
Enabled: true
EnforcedStyle: always
Style/Documentation:
Enabled: false
Exclude:
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"
gemspec :name => "jekyll"

Expand Down
2 changes: 2 additions & 0 deletions Rakefile
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "rubygems"
require "rake"
require "rdoc"
Expand Down
2 changes: 1 addition & 1 deletion docs/_docs/history.md
Expand Up @@ -27,7 +27,7 @@ note: This file is autogenerated. Edit /History.markdown instead.
- add plugins for multiple page pagination ([#6055]({{ site.repository }}/issues/6055))
- Update minimum Ruby version in installation.md ([#6164]({{ site.repository }}/issues/6164))
- [docs] Add information about finding a collection in `site.collections` ([#6165]({{ site.repository }}/issues/6165))
- Add {%raw%} to Liquid example on site ([#6179]({{ site.repository }}/issues/6179))
- Add {% raw %}`{% raw %}`{% endraw %} to Liquid example on site ([#6179]({{ site.repository }}/issues/6179))
- Added improved Pug plugin - removed 404 Jade plugin ([#6174]({{ site.repository }}/issues/6174))
- Linking the link ([#6210]({{ site.repository }}/issues/6210))
- Small correction in documentation for includes ([#6193]({{ site.repository }}/issues/6193))
Expand Down
2 changes: 2 additions & 0 deletions exe/jekyll
@@ -1,4 +1,6 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
#
STDOUT.sync = true

$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
Expand Down
2 changes: 2 additions & 0 deletions features/step_definitions.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Before do
FileUtils.rm_rf(Paths.test_dir) if Paths.test_dir.exist?
FileUtils.mkdir_p(Paths.test_dir) unless Paths.test_dir.directory?
Expand Down
2 changes: 2 additions & 0 deletions features/support/formatter.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "fileutils"
require "colorator"
require "cucumber/formatter/console"
Expand Down
5 changes: 4 additions & 1 deletion features/support/helpers.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "fileutils"
require "jekyll"
require "time"
Expand Down Expand Up @@ -107,7 +109,8 @@ def run_in_shell(*args)

File.write(Paths.status_file, p.exitstatus)
File.open(Paths.output_file, "wb") do |f|
f.puts "$ " << args.join(" ")
f.print "$ "
f.puts args.join(" ")
f.puts output
f.puts "EXIT STATUS: #{p.exitstatus}"
end
Expand Down
1 change: 1 addition & 0 deletions jekyll.gemspec
@@ -1,4 +1,5 @@
# coding: utf-8
# frozen_string_literal: true

lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
Expand Down
7 changes: 5 additions & 2 deletions lib/jekyll.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

$LOAD_PATH.unshift __dir__ # For use/testing when no gem is installed

# Require all of the Ruby files in the given directory.
Expand Down Expand Up @@ -162,8 +164,9 @@ def sites
def sanitized_path(base_directory, questionable_path)
return base_directory if base_directory.eql?(questionable_path)

questionable_path.insert(0, "/") if questionable_path.start_with?("~")
clean_path = File.expand_path(questionable_path, "/")
clean_path = questionable_path.dup
clean_path.insert(0, "/") if clean_path.start_with?("~")
clean_path = File.expand_path(clean_path, "/")

return clean_path if clean_path.eql?(base_directory)

Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/cleaner.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "set"

module Jekyll
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/collection.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Jekyll
class Collection
attr_reader :site, :label, :metadata
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/command.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Jekyll
class Command
class << self
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/commands/build.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Jekyll
module Commands
class Build < Command
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/commands/clean.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Jekyll
module Commands
class Clean < Command
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/commands/doctor.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "addressable/uri"

module Jekyll
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/commands/help.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Jekyll
module Commands
class Help < Command
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/commands/new.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "erb"

module Jekyll
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/commands/new_theme.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "erb"

class Jekyll::Commands::NewTheme < Jekyll::Command
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/commands/serve.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Jekyll
module Commands
class Serve < Command
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/commands/serve/servlet.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "webrick"

module Jekyll
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/configuration.rb
@@ -1,4 +1,5 @@
# encoding: UTF-8
# frozen_string_literal: true

module Jekyll
class Configuration < Hash
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/converter.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Jekyll
class Converter < Plugin
# Public: Get or set the highlighter prefix. When an argument is specified,
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/converters/identity.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Jekyll
module Converters
class Identity < Converter
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/converters/markdown.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Jekyll
module Converters
class Markdown < Converter
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/converters/markdown/rdiscount_parser.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Jekyll
module Converters
class Markdown
Expand Down
6 changes: 3 additions & 3 deletions lib/jekyll/converters/markdown/redcarpet_parser.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Jekyll::Converters::Markdown::RedcarpetParser
module CommonMethods
def add_code_tags(code, lang)
Expand Down Expand Up @@ -48,9 +50,7 @@ module WithRouge
def block_code(code, lang)
code = "<pre>#{super}</pre>"

output = "<div class=\"highlight\">"
output << add_code_tags(code, lang)
output << "</div>"
"<div class=\"highlight\">#{add_code_tags(code, lang)}</div>"
end

protected
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/converters/smartypants.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Kramdown::Parser::SmartyPants < Kramdown::Parser::Kramdown
def initialize(source, options)
super
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/convertible.rb
@@ -1,4 +1,5 @@
# encoding: UTF-8
# frozen_string_literal: true

require "set"

Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/deprecator.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Jekyll
module Deprecator
extend self
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/document.rb
@@ -1,4 +1,5 @@
# encoding: UTF-8
# frozen_string_literal: true

module Jekyll
class Document
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/drops/collection_drop.rb
@@ -1,4 +1,5 @@
# encoding: UTF-8
# frozen_string_literal: true

module Jekyll
module Drops
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/drops/document_drop.rb
@@ -1,4 +1,5 @@
# encoding: UTF-8
# frozen_string_literal: true

module Jekyll
module Drops
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/drops/drop.rb
@@ -1,4 +1,5 @@
# encoding: UTF-8
# frozen_string_literal: true

module Jekyll
module Drops
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/drops/excerpt_drop.rb
@@ -1,4 +1,5 @@
# encoding: UTF-8
# frozen_string_literal: true

module Jekyll
module Drops
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/drops/jekyll_drop.rb
@@ -1,4 +1,5 @@
# encoding: UTF-8
# frozen_string_literal: true

module Jekyll
module Drops
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/drops/site_drop.rb
@@ -1,4 +1,5 @@
# encoding: UTF-8
# frozen_string_literal: true

module Jekyll
module Drops
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/drops/static_file_drop.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Jekyll
module Drops
class StaticFileDrop < Drop
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/drops/unified_payload_drop.rb
@@ -1,4 +1,5 @@
# encoding: UTF-8
# frozen_string_literal: true

module Jekyll
module Drops
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/drops/url_drop.rb
@@ -1,4 +1,5 @@
# encoding: UTF-8
# frozen_string_literal: true

module Jekyll
module Drops
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/entry_filter.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Jekyll
class EntryFilter
attr_reader :site
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/errors.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Jekyll
module Errors
FatalException = Class.new(::RuntimeError)
Expand Down
4 changes: 3 additions & 1 deletion lib/jekyll/excerpt.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Jekyll
class Excerpt
extend Forwardable
Expand Down Expand Up @@ -117,7 +119,7 @@ def extract_excerpt(doc_content)
if tail.empty?
head
else
"" << head << "\n\n" << tail.scan(%r!^ {0,3}\[[^\]]+\]:.+$!).join("\n")
head.to_s.dup << "\n\n" << tail.scan(%r!^ {0,3}\[[^\]]+\]:.+$!).join("\n")
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/external.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Jekyll
module External
class << self
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/filters.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "addressable/uri"
require "json"
require "date"
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/filters/grouping_filters.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Jekyll
module Filters
module GroupingFilters
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/filters/url_filters.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "addressable/uri"

module Jekyll
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/frontmatter_defaults.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Jekyll
# This class handles custom defaults for YAML frontmatter settings.
# These are set in _config.yml and apply both to internal use (e.g. layout)
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/generator.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Jekyll
Generator = Class.new(Plugin)
end
2 changes: 2 additions & 0 deletions lib/jekyll/hooks.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Jekyll
module Hooks
DEFAULT_PRIORITY = 20
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/layout.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Jekyll
class Layout
include Convertible
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/liquid_extensions.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Jekyll
module LiquidExtensions

Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/liquid_renderer.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "jekyll/liquid_renderer/file"
require "jekyll/liquid_renderer/table"

Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/liquid_renderer/file.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Jekyll
class LiquidRenderer
class File
Expand Down

0 comments on commit e788ad5

Please sign in to comment.