Skip to content

Commit

Permalink
style: Target Ruby 2.4 (#432)
Browse files Browse the repository at this point in the history
Merge pull request 432
  • Loading branch information
DirtyF authored Apr 13, 2020
1 parent aff3f12 commit 45cae26
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ inherit_gem:
rubocop-jekyll: .rubocop.yml

AllCops:
TargetRubyVersion: 2.3
TargetRubyVersion: 2.4
Exclude:
- docs/**/*
- script/**/*
Expand Down
94 changes: 72 additions & 22 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-03-09 13:55:02 +0100 using RuboCop version 0.71.0.
# `rubocop --auto-gen-config --auto-gen-only-exclude`
# on 2020-04-13 14:53:09 +0200 using RuboCop version 0.80.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 106
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 284

# Offense count: 1
Lint/Loop:
Exclude:
Expand All @@ -32,73 +39,116 @@ Metrics/AbcSize:
Max: 140

# Offense count: 6
# Configuration parameters: CountComments, ExcludedMethods.
# Configuration parameters: CountComments, Max, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 47
Exclude:
- !ruby/regexp /^spec/
- 'jekyll-import.gemspec'
- 'lib/jekyll-import/importers/dotclear.rb'
- 'lib/jekyll-import/importers/drupal_common.rb'
- 'lib/jekyll-import/importers/pluxml.rb'
- 'lib/jekyll-import/importers/posterous.rb'
- 'lib/jekyll-import/importers/wordpressdotcom.rb'

# Offense count: 4
# Configuration parameters: CountBlocks.
# Configuration parameters: CountBlocks, Max.
Metrics/BlockNesting:
Max: 4
Exclude:
- 'lib/jekyll-import/importers/blogger.rb'

# Offense count: 3
# Configuration parameters: CountComments.
# Configuration parameters: CountComments, Max.
Metrics/ClassLength:
Max: 266
Exclude:
- 'lib/jekyll-import/importers/s9y_database.rb'
- 'lib/jekyll-import/importers/tumblr.rb'
- 'lib/jekyll-import/importers/wordpress.rb'

# Offense count: 17
# Configuration parameters: Max.
Metrics/CyclomaticComplexity:
Max: 31

# Offense count: 106
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 284
Exclude:
- 'lib/jekyll-import/importers/blogger.rb'
- 'lib/jekyll-import/importers/dotclear.rb'
- 'lib/jekyll-import/importers/drupal_common.rb'
- 'lib/jekyll-import/importers/ghost.rb'
- 'lib/jekyll-import/importers/mt.rb'
- 'lib/jekyll-import/importers/roller.rb'
- 'lib/jekyll-import/importers/s9y_database.rb'
- 'lib/jekyll-import/importers/tumblr.rb'
- 'lib/jekyll-import/importers/typo.rb'
- 'lib/jekyll-import/importers/wordpress.rb'

# Offense count: 39
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/MethodLength:
Max: 124

# Offense count: 1
# Configuration parameters: CountKeywordArgs.
# Configuration parameters: Max, CountKeywordArgs.
Metrics/ParameterLists:
Max: 5
Exclude:
- 'lib/jekyll-import/importers/roller.rb'

# Offense count: 12
# Configuration parameters: Max.
Metrics/PerceivedComplexity:
Max: 35
Exclude:
- 'lib/jekyll-import/importers/blogger.rb'
- 'lib/jekyll-import/importers/dotclear.rb'
- 'lib/jekyll-import/importers/drupal_common.rb'
- 'lib/jekyll-import/importers/ghost.rb'
- 'lib/jekyll-import/importers/mt.rb'
- 'lib/jekyll-import/importers/roller.rb'
- 'lib/jekyll-import/importers/s9y_database.rb'
- 'lib/jekyll-import/importers/tumblr.rb'
- 'lib/jekyll-import/importers/wordpress.rb'

# Offense count: 29
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: io, id, to, by, on, in, at, ip, db
Naming/UncommunicativeMethodParamName:
# AllowedNames: io, id, to, by, on, in, at, ip, db, os, pp
Naming/MethodParameterName:
Enabled: false

# Offense count: 1
Security/Open:
Exclude:
- 'lib/jekyll-import/importers/rss.rb'

# Offense count: 21
# Offense count: 52
# Configuration parameters: EnforcedStyle.
# SupportedStyles: annotated, template, unannotated
Style/FormatStringToken:
Exclude:
- 'lib/jekyll-import/importers/blogger.rb'
- 'lib/jekyll-import/importers/easyblog.rb'
- 'lib/jekyll-import/importers/enki.rb'
- 'lib/jekyll-import/importers/joomla.rb'
- 'lib/jekyll-import/importers/joomla3.rb'
- 'lib/jekyll-import/importers/posterous.rb'
- 'lib/jekyll-import/importers/roller.rb'
- 'lib/jekyll-import/importers/s9y.rb'
- 'lib/jekyll-import/importers/s9y_database.rb'
- 'lib/jekyll-import/importers/typo.rb'
- 'lib/jekyll-import/importers/wordpress.rb'
- 'lib/jekyll-import/importers/wordpressdotcom.rb'

# Offense count: 18
# Cop supports --auto-correct.
Style/IfUnlessModifier:
Exclude:
- 'lib/jekyll-import/importers/blogger.rb'
- 'lib/jekyll-import/importers/ghost.rb'
- 'lib/jekyll-import/importers/google_reader.rb'
- 'lib/jekyll-import/importers/jrnl.rb'
- 'lib/jekyll-import/importers/marley.rb'
- 'lib/jekyll-import/importers/pluxml.rb'
- 'lib/jekyll-import/importers/posterous.rb'
- 'lib/jekyll-import/importers/rss.rb'
- 'lib/jekyll-import/importers/s9y.rb'
- 'lib/jekyll-import/importers/s9y_database.rb'

# Offense count: 1
Style/MultilineBlockChain:
Exclude:
Expand Down
4 changes: 2 additions & 2 deletions jekyll-import.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require_relative "lib/jekyll-import/version"

Gem::Specification.new do |s|
s.required_ruby_version = ">= 2.3.0"
s.required_ruby_version = ">= 2.4.0"

s.name = "jekyll-import"
s.version = JekyllImport::VERSION
Expand Down Expand Up @@ -36,7 +36,7 @@ Gem::Specification.new do |s|
# test dependencies:
s.add_development_dependency("redgreen", "~> 1.2")
s.add_development_dependency("rr", "~> 1.0")
s.add_development_dependency("rubocop-jekyll", "~> 0.10.0")
s.add_development_dependency("rubocop-jekyll", "~> 0.11.0")
s.add_development_dependency("shoulda", "~> 3.5")
s.add_development_dependency("simplecov", "~> 0.7")
s.add_development_dependency("simplecov-gem-adapter", "~> 1.0")
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll-import/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def self.subclasses

def self.stringify_keys(hash)
the_hash = hash.clone
the_hash.keys.each do |key|
the_hash.each_key do |key|
the_hash[(key.to_s rescue key) || key] = the_hash.delete(key)
end
the_hash
Expand Down
8 changes: 4 additions & 4 deletions lib/jekyll-import/importers/blogger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ def post_data_from_in_entry_elem_info
body = @in_entry_elem[:body]

# body escaping associated with liquid
body.gsub!(%r!{{!, '{{ "{{" }}') if body =~ %r!{{!
body.gsub!(%r!{%!, '{{ "{%" }}') if body =~ %r!{%!
body.gsub!(%r!{{!, '{{ "{{" }}') if %r!{{!.match?(body)
body.gsub!(%r!{%!, '{{ "{%" }}') if %r!{%!.match?(body)

{ :filename => filename, :header => header, :body => body }
elsif @in_entry_elem[:meta][:kind] == "comment"
Expand Down Expand Up @@ -291,8 +291,8 @@ def post_data_from_in_entry_elem_info
body = @in_entry_elem[:body]

# body escaping associated with liquid
body.gsub!(%r!{{!, '{{ "{{" }}') if body =~ %r!{{!
body.gsub!(%r!{%!, '{{ "{%" }}') if body =~ %r!{%!
body.gsub!(%r!{{!, '{{ "{{" }}') if %r!{{!.match?(body)
body.gsub!(%r!{%!, '{{ "{%" }}') if %r!{%!.match?(body)

{ :filename => filename, :header => header, :body => body }
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll-import/importers/marley.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def self.process(options)
title = file_content.scan(regexp[:title]).first.to_s.strip
prerex = file_content.scan(regexp[:perex]).first.to_s.strip
published_on = DateTime.parse(post[:published_on]) rescue File.mtime(File.dirname(f))
meta = meta_content ? YAML.safe_load(meta_content.scan(regexp[:meta]).to_s) : {}
meta = meta_content ? YAML.safe_load(meta_content.scan(regexp[:meta]).to_s) : {}
meta["title"] = title
meta["layout"] = "post"

Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll-import/importers/mt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def self.specify_options(c)
# comments:: If true, output comments in _comments directory, like the one
# mentioned at https://github.com/mpalmer/jekyll-static-comments/
def self.process(options)
options = default_options.merge(options)
options = default_options.merge(options)

comments = options.fetch("comments")
posts_name_by_id = {} if comments
Expand Down
4 changes: 2 additions & 2 deletions lib/jekyll-import/importers/tumblr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def add_syntax_highlights(content, redirect_dir)
lang = "python"
start = i
elsif block
lang = "javascript" if line =~ %r!;$!
lang = "javascript" if %r!;$!.match?(line)
block = line =~ indent && i < lines.size - 1 # Also handle EOF
unless block
lines[start] = "{% highlight #{lang} %}"
Expand All @@ -283,7 +283,7 @@ def save_photo(url, ext)
return url unless @grab_images

path = "tumblr_files/#{url.split("/").last}"
path += ext unless path =~ %r!#{ext}$!
path += ext unless %r!#{ext}$!.match?(path)
FileUtils.mkdir_p "tumblr_files"

# Don't fetch if we've already cached this file
Expand Down
6 changes: 3 additions & 3 deletions lib/jekyll-import/importers/typo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def self.process(options)
raise "Unknown database server '#{server}'"
end
db[SQL].each do |post|
next unless post[:state] =~ %r!published!i
next unless %r!published!i.match?(post[:state])

post[:slug] = "no slug" if post[:slug].nil?

Expand All @@ -77,8 +77,8 @@ def self.process(options)

File.open("_posts/#{name}", "w") do |f|
f.puts({ "layout" => "post",
"title" => (post[:title]&.to_s&.force_encoding("UTF-8")),
"tags" => (post[:keywords]&.to_s&.force_encoding("UTF-8")),
"title" => post[:title]&.to_s&.force_encoding("UTF-8"),
"tags" => post[:keywords]&.to_s&.force_encoding("UTF-8"),
"typo_id" => post[:id], }.delete_if { |_k, v| v.nil? || v == "" }.to_yaml)
f.puts "---"
f.puts post[:body].delete("\r")
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/commands/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def process(migrator, options)

def abort_on_invalid_migrator(migrator)
warn "Sorry, '#{migrator}' isn't a valid migrator. Valid choices:"
IMPORTERS.keys.each { |k| warn "* #{k}" }
IMPORTERS.each_key { |k| warn "* #{k}" }
raise "'#{migrator}' is not a valid migrator."
end
end
Expand Down

0 comments on commit 45cae26

Please sign in to comment.