Passing RuboCop for commands

This commit is contained in:
TheLucasMoore 2016-05-12 19:11:58 -05:00
parent 6f89fd5f3f
commit 26d0a8db77
8 changed files with 70 additions and 67 deletions

View File

@ -7,13 +7,6 @@ AllCops:
- lib/jekyll/cleaner.rb
- lib/jekyll/collection.rb
- lib/jekyll/command.rb
- lib/jekyll/commands/build.rb
- lib/jekyll/commands/doctor.rb
- lib/jekyll/commands/help.rb
- lib/jekyll/commands/new.rb
- lib/jekyll/commands/serve
- lib/jekyll/commands/serve/servlet.rb
- lib/jekyll/commands/serve.rb
- lib/jekyll/configuration.rb
- lib/jekyll/converter.rb
- lib/jekyll/converters/identity.rb

View File

@ -5,8 +5,8 @@ module Jekyll
# Create the Mercenary command for the Jekyll CLI for this Command
def init_with_program(prog)
prog.command(:build) do |c|
c.syntax 'build [options]'
c.description 'Build your site'
c.syntax "build [options]"
c.description "Build your site"
c.alias :b
add_build_options(c)
@ -27,15 +27,17 @@ module Jekyll
options = configuration_from_options(options)
site = Jekyll::Site.new(options)
if options.fetch('skip_initial_build', false)
Jekyll.logger.warn "Build Warning:", "Skipping the initial build. This may result in an out-of-date site."
if options.fetch("skip_initial_build", false)
Jekyll.logger.warn "Build Warning:", "Skipping the initial build." \
" This may result in an out-of-date site."
else
build(site, options)
end
if options.fetch('detach', false)
Jekyll.logger.info "Auto-regeneration:", "disabled when running server detached."
elsif options.fetch('watch', false)
if options.fetch("detach", false)
Jekyll.logger.info "Auto-regeneration:",
"disabled when running server detached."
elsif options.fetch("watch", false)
watch(site, options)
else
Jekyll.logger.info "Auto-regeneration:", "disabled. Use --watch to enable."
@ -50,12 +52,13 @@ module Jekyll
# Returns nothing.
def build(site, options)
t = Time.now
source = options['source']
destination = options['destination']
incremental = options['incremental']
source = options["source"]
destination = options["destination"]
incremental = options["incremental"]
Jekyll.logger.info "Source:", source
Jekyll.logger.info "Destination:", destination
Jekyll.logger.info "Incremental build:", (incremental ? "enabled" : "disabled. Enable with --incremental")
Jekyll.logger.info "Incremental build:",
(incremental ? "enabled" : "disabled. Enable with --incremental")
Jekyll.logger.info "Generating..."
process_site(site)
Jekyll.logger.info "", "done in #{(Time.now - t).round(3)} seconds."
@ -68,7 +71,7 @@ module Jekyll
#
# Returns nothing.
def watch(_site, options)
External.require_with_graceful_fail 'jekyll-watch'
External.require_with_graceful_fail "jekyll-watch"
Jekyll::Watcher.watch(options)
end
end # end of class << self

View File

@ -5,8 +5,8 @@ module Jekyll
def init_with_program(prog)
prog.command(:clean) do |c|
c.syntax "clean [subcommand]"
c.description "Clean the site
(removes site output and metadata file) without building."
c.description "Clean the site " \
"(removes site output and metadata file) without building."
add_build_options(c)

View File

@ -4,11 +4,12 @@ module Jekyll
class << self
def init_with_program(prog)
prog.command(:doctor) do |c|
c.syntax 'doctor'
c.description 'Search site and print specific deprecation warnings'
c.syntax "doctor"
c.description "Search site and print specific deprecation warnings"
c.alias(:hyde)
c.option 'config', '--config CONFIG_FILE[,CONFIG_FILE2,...]', Array, 'Custom configuration file'
c.option "config", "--config CONFIG_FILE[,CONFIG_FILE2,...]", Array,
"Custom configuration file"
c.action do |_, options|
Jekyll::Commands::Doctor.process(options)
@ -37,7 +38,7 @@ module Jekyll
end
def deprecated_relative_permalinks(site)
if site.config['relative_permalinks']
if site.config["relative_permalinks"]
Jekyll::Deprecator.deprecation_message "Your site still uses relative" \
" permalinks, which was removed in" \
" Jekyll v3.0.0."
@ -78,7 +79,7 @@ module Jekyll
def urls_only_differ_by_case(site)
urls_only_differ_by_case = false
urls = case_insensitive_urls(site.pages + site.docs_to_write, site.dest)
urls.each do |case_insensitive_url, real_urls|
urls.each do |_case_insensitive_url, real_urls|
next unless real_urls.uniq.size > 1
urls_only_differ_by_case = true
Jekyll.logger.warn "Warning:", "The following URLs only differ" \
@ -102,7 +103,7 @@ module Jekyll
end
def case_insensitive_urls(things, destination)
things.inject({}) do |memo, thing|
things.each_with_object({}) do |memo, thing|
dest = thing.destination(destination)
(memo[dest.downcase] ||= []) << dest
memo

View File

@ -4,8 +4,8 @@ module Jekyll
class << self
def init_with_program(prog)
prog.command(:help) do |c|
c.syntax 'help [subcommand]'
c.description 'Show the help message, optionally for a given subcommand.'
c.syntax "help [subcommand]"
c.description "Show the help message, optionally for a given subcommand."
c.action do |args, _|
cmd = (args.first || "").to_sym
@ -22,7 +22,8 @@ module Jekyll
end
def invalid_command(prog, cmd)
Jekyll.logger.error "Error:", "Hmm... we don't know what the '#{cmd}' command is."
Jekyll.logger.error "Error:",
"Hmm... we don't know what the '#{cmd}' command is."
Jekyll.logger.info "Valid commands:", prog.commands.keys.join(", ")
end
end

View File

@ -1,4 +1,4 @@
require 'erb'
require "erb"
module Jekyll
module Commands
@ -6,11 +6,11 @@ module Jekyll
class << self
def init_with_program(prog)
prog.command(:new) do |c|
c.syntax 'new PATH'
c.description 'Creates a new Jekyll site scaffold in PATH'
c.syntax "new PATH"
c.description "Creates a new Jekyll site scaffold in PATH"
c.option 'force', '--force', 'Force creation even if PATH already exists'
c.option 'blank', '--blank', 'Creates scaffolding but with empty files'
c.option "force", "--force", "Force creation even if PATH already exists"
c.option "blank", "--blank", "Creates scaffolding but with empty files"
c.action do |args, options|
Jekyll::Commands::New.process(args, options)
@ -19,27 +19,16 @@ module Jekyll
end
def process(args, options = {})
raise ArgumentError.new('You must specify a path.') if args.empty?
raise ArgumentError, "You must specify a path." if args.empty?
new_blog_path = File.expand_path(args.join(" "), Dir.pwd)
FileUtils.mkdir_p new_blog_path
if preserve_source_location?(new_blog_path, options)
Jekyll.logger.abort_with "Conflict:", "#{new_blog_path} exists and is not empty."
Jekyll.logger.abort_with "Conflict:",
"#{new_blog_path} exists and is not empty."
end
if options["blank"]
create_blank_site new_blog_path
else
create_sample_files new_blog_path
File.open(File.expand_path(initialized_post_name, new_blog_path), "w") do |f|
f.write(scaffold_post_content)
end
File.open(File.expand_path("Gemfile", new_blog_path), "w") do |f|
f.write(gemfile_contents)
end
end
if_blank_options
Jekyll.logger.info "New jekyll site installed in #{new_blog_path}."
end
@ -59,7 +48,7 @@ module Jekyll
#
# Returns the filename of the sample post, as a String
def initialized_post_name
"_posts/#{Time.now.strftime('%Y-%m-%d')}-welcome-to-jekyll.markdown"
"_posts/#{Time.now.strftime("%Y-%m-%d")}-welcome-to-jekyll.markdown"
end
private
@ -95,7 +84,7 @@ RUBY
end
def create_sample_files(path)
FileUtils.cp_r site_template + '/.', path
FileUtils.cp_r site_template + "/.", path
FileUtils.rm File.expand_path(scaffold_path, path)
end
@ -106,6 +95,22 @@ RUBY
def scaffold_path
"_posts/0000-00-00-welcome-to-jekyll.markdown.erb"
end
def if_blank_options
if options["blank"]
create_blank_site new_blog_path
else
create_sample_files new_blog_path
File.open(File.expand_path(initialized_post_name, new_blog_path), "w") do |f|
f.write(scaffold_post_content)
end
File.open(File.expand_path("Gemfile", new_blog_path), "w") do |f|
f.write(gemfile_contents)
end
end
end
end
end
end

View File

@ -14,7 +14,7 @@ module Jekyll
"Show a directory listing instead of loading your index file."],
"skip_initial_build" => ["skip_initial_build", "--skip-initial-build",
"Skips the initial site build which occurs before the server is started."]
}
}.freeze
#
@ -93,7 +93,7 @@ module Jekyll
)
}
opts[:DirectoryIndex] = [] if opts[:JekyllOptions]['show_dir_listing']
opts[:DirectoryIndex] = [] if opts[:JekyllOptions]["show_dir_listing"]
enable_ssl(opts)
enable_logging(opts)
@ -107,7 +107,7 @@ module Jekyll
WEBrick::Config::FileHandler.merge({
:FancyIndexing => true,
:NondisclosureName => [
'.ht*', '~*'
".ht*", "~*"
]
})
end
@ -116,12 +116,12 @@ module Jekyll
private
def server_address(server, opts)
"%{prefix}://%{address}:%{port}%{baseurl}" % {
format("%{prefix}://%{address}:%{port}%{baseurl}", {
:prefix => server.config[:SSLEnable] ? "https" : "http",
:baseurl => opts["baseurl"] ? "#{opts["baseurl"]}/" : "",
:address => server.config[:BindAddress],
:port => server.config[:Port]
}
})
end
#
@ -173,20 +173,20 @@ module Jekyll
private
def enable_ssl(opts)
return if !opts[:JekyllOptions]["ssl_cert"] && !opts[:JekyllOptions]["ssl_key"]
if !opts[:JekyllOptions]["ssl_cert"] || !opts[:JekyllOptions]["ssl_key"]
raise RuntimeError, "--ssl-cert or --ssl-key missing."
end
require "openssl"
require "webrick/https"
source_key = Jekyll.sanitized_path(opts[:JekyllOptions]["source"], opts[:JekyllOptions]["ssl_key" ])
source_certificate = Jekyll.sanitized_path(opts[:JekyllOptions]["source"], opts[:JekyllOptions]["ssl_cert"])
opts[:SSLCertificate] = OpenSSL::X509::Certificate.new(File.read(source_certificate))
source_key = Jekyll.sanitized_path(opts[:JekyllOptions]["source"], \
opts[:JekyllOptions]["ssl_key" ])
source_certificate = Jekyll.sanitized_path(opts[:JekyllOptions]["source"], \
opts[:JekyllOptions]["ssl_cert"])
opts[:SSLCertificate] =
OpenSSL::X509::Certificate.new(File.read(source_certificate))
opts[:SSLPrivateKey ] = OpenSSL::PKey::RSA.new(File.read(source_key))
opts[:SSLEnable] = true
end
private
def start_callback(detached)
unless detached
proc do
@ -197,7 +197,7 @@ module Jekyll
private
def mime_types
file = File.expand_path('../mime.types', File.dirname(__FILE__))
file = File.expand_path("../mime.types", File.dirname(__FILE__))
WEBrick::HTTPUtils.load_mime_types(file)
end
end

View File

@ -7,7 +7,7 @@ module Jekyll
DEFAULTS = {
"Cache-Control" => "private, max-age=0, proxy-revalidate, " \
"no-store, no-cache, must-revalidate"
}
}.freeze
def initialize(server, root, callbacks)
# So we can access them easily.
@ -27,7 +27,7 @@ module Jekyll
#
def do_GET(req, res)
def do_get(req, res)
rtn = super
validate_and_ensure_charset(req, res)
res.header.merge!(@headers)