Skip to content

Commit

Permalink
Rubocop pass
Browse files Browse the repository at this point in the history
  • Loading branch information
markets committed Feb 4, 2024
1 parent 2aad59a commit fc35db8
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 45 deletions.
41 changes: 37 additions & 4 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ require:
AllCops:
TargetRubyVersion: 2.5
Include:
- '**/Rakefile'
- '**/Gemfile'
- '**/*.rb'
- Rakefile
- Gemfile
Exclude:
- fixtures/**/*
NewCops: disable
SuggestExtensions: false

Expand All @@ -16,13 +18,21 @@ Layout/EndAlignment:
EnforcedStyleAlignWith: variable
Layout/LineLength:
Enabled: false
Layout/SpaceAroundEqualsInParameterDefault:
EnforcedStyle: no_space

Lint/AssignmentInCondition:
Enabled: false
Lint/SuppressedException:
Enabled: false
Lint/MissingSuper:
Enabled: false
Lint/AmbiguousRegexpLiteral:
Enabled: false
Lint/AmbiguousBlockAssociation:
Enabled: false
Lint/UriEscapeUnescape:
Enabled: false
Lint/ShadowedException:
Enabled: false

Metrics/AbcSize:
Enabled: false
Expand All @@ -34,6 +44,10 @@ Metrics/MethodLength:
Enabled: false
Metrics/PerceivedComplexity:
Enabled: false
Metrics/BlockLength:
Enabled: false
Metrics/ModuleLength:
Enabled: false

Style/BlockDelimiters:
Enabled: false
Expand Down Expand Up @@ -65,6 +79,25 @@ Style/SpecialGlobalVars:
Enabled: false
Style/TrivialAccessors:
Enabled: false
Style/EvalWithLocation:
Enabled: false
Style/ClassVars:
Enabled: false
Style/GlobalVars:
Enabled: false
Style/ClassAndModuleChildren:
Enabled: false
Style/MissingRespondToMissing:
Enabled: false

Naming/FileName:
Enabled: false
Naming/MethodParameterName:
Enabled: false
Naming/MemoizedInstanceVariableName:
Enabled: false
Naming/HeredocDelimiterNaming:
Enabled: false

Bundler/OrderedGems:
Enabled: false
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ gem 'nokogiri', RUBY_VERSION < '2.6' ? '~> 1.12.0' : '>= 0', require: false
# Code Quality
gem 'rubocop', require: false
gem 'rubocop-performance', require: false
gem 'simplecov', '~> 0.10', require: false
gem 'simplecov', require: false
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
end

desc 'Run tests, both RSpec and Cucumber'
task test: %i[rubocop spec cucumber]
task test: %i[spec cucumber]

require 'rspec/core/rake_task'
desc 'Run RSpec'
Expand Down
14 changes: 7 additions & 7 deletions features/support/time_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

Given /the (date|time|date and time) is (.+?)$/ do |datetime, value|
time = case datetime
when 'date'
Date.parse(value)
when 'time'
Time.parse(value)
when 'date and time'
Time.zone.parse(value)
end
when 'date'
Date.parse(value)
when 'time'
Time.parse(value)
when 'date and time'
Time.zone.parse(value)
end

Timecop.travel time
end
Expand Down
8 changes: 4 additions & 4 deletions lib/middleman-blog/blog_article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ def date

# First get the date from frontmatter
@_date = if frontmatter_date.is_a? Time
frontmatter_date.in_time_zone
else
Time.zone.parse(frontmatter_date.to_s)
end
frontmatter_date.in_time_zone
else
Time.zone.parse(frontmatter_date.to_s)
end

# Next figure out the date from the filename
source_vars = blog_data.source_template.variables
Expand Down
2 changes: 1 addition & 1 deletion lib/middleman-blog/blog_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def initialize(app, controller, options)
# @return [Array<Middleman::Sitemap::Resource>]
##
def articles
@_articles.select(&(options.filter || proc { |a| a })).sort_by(&:date).reverse
@_articles.select(&options.filter || proc { |a| a }).sort_by(&:date).reverse
end

##
Expand Down
12 changes: 6 additions & 6 deletions lib/middleman-blog/calendar_pages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ def initialize(app, blog_controller)
# @return [String]
def link(year, month = nil, day = nil)
template = if day
@day_link_template
elsif month
@month_link_template
else
@year_link_template
end
@day_link_template
elsif month
@month_link_template
else
@year_link_template
end

apply_uri_template template, date_to_params(Date.new(year, month || 1, day || 1))
end
Expand Down
8 changes: 4 additions & 4 deletions lib/middleman-blog/commands/article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ def article
end

blog_inst = if options[:blog]
app.extensions[:blog].find { |_key, instance| instance.options[:name] == options[:blog] }[ 1 ]
else
app.extensions[:blog].values.first
end
app.extensions[:blog].find { |_key, instance| instance.options[:name] == options[:blog] }[ 1 ]
else
app.extensions[:blog].values.first
end

unless blog_inst
msg = 'Could not find an active blog instance'
Expand Down
24 changes: 12 additions & 12 deletions lib/middleman-blog/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ def initialize(app, options_hash = {}, &block)
end

# If "prefix" option is specified, all other paths are relative to it.
if options.prefix
options.prefix = "/#{options.prefix}" unless options.prefix.start_with? '/'
options.permalink = File.join(options.prefix, options.permalink)
options.sources = File.join(options.prefix, options.sources)
options.taglink = File.join(options.prefix, options.taglink)
options.year_link = File.join(options.prefix, options.year_link)
options.month_link = File.join(options.prefix, options.month_link)
options.day_link = File.join(options.prefix, options.day_link)

options.custom_collections.each do |_key, opts|
opts[:link] = File.join(options.prefix, opts[:link])
end
return unless options.prefix

options.prefix = "/#{options.prefix}" unless options.prefix.start_with? '/'
options.permalink = File.join(options.prefix, options.permalink)
options.sources = File.join(options.prefix, options.sources)
options.taglink = File.join(options.prefix, options.taglink)
options.year_link = File.join(options.prefix, options.year_link)
options.month_link = File.join(options.prefix, options.month_link)
options.day_link = File.join(options.prefix, options.day_link)

options.custom_collections.each do |_key, opts|
opts[:link] = File.join(options.prefix, opts[:link])
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/middleman-blog/truncate_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def truncate(max_length, ellipsis)
module TextNode
def truncate(max_length, ellipsis)
# Don't break in the middle of a word
trimmed_content = content.match(/(.{1,#{max_length}}[\w]*)/m).to_s
trimmed_content = content.match(/(.{1,#{max_length}}\w*)/m).to_s
trimmed_content << ellipsis if trimmed_content.length < content.length

Nokogiri::XML::Text.new(trimmed_content, parent)
Expand Down
2 changes: 1 addition & 1 deletion lib/middleman-blog/uri_templates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def safe_parameterize(str, sep = '-')

# Reimplementation of http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-parameterize that preserves un-transliterate-able multibyte chars.
parameterized_string = ::ActiveSupport::Inflector.transliterate(str.to_s).downcase
parameterized_string.gsub!(/[^a-z0-9\-_\?]+/, sep)
parameterized_string.gsub!(/[^a-z0-9\-_?]+/, sep)

# Check for multibytes and sub back in
parameterized_string.chars.to_a.each_with_index do |char, i|
Expand Down
2 changes: 0 additions & 2 deletions middleman-blog.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ Gem::Specification.new do | s |
s.files = `git ls-files -z`.split( "\0" )
s.test_files = `git ls-files -z -- {fixtures,features}/*`.split( "\0" )
s.require_paths = [ "lib" ]
s.required_ruby_version = '>= 2.3.0'

s.add_dependency("middleman-core", ">= 4.0.0")
s.add_dependency("tzinfo", ">= 0.3.0")
s.add_dependency("addressable", "~> 2.3")
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true

require 'simplecov'
SimpleCov.root(File.expand_path(File.dirname(__FILE__) + '/..'))
SimpleCov.root(File.expand_path("#{File.dirname(__FILE__)}/.."))

0 comments on commit fc35db8

Please sign in to comment.