Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and auto-fix lots of things with Rubocop #3

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
inherit_from: .rubocop_todo.yml

AllCops:
TargetRubyVersion: 2.3

Exclude:
- 'db/**/*'
- 'script/*'
- 'bin/*'
- 'log/**/*'
- 'node_modules/**/*'
- 'public/**/*'
- 'vendor/**/*'
- 'tmp/**/*'
- '.git/**/*'

IndentationConsistency:
EnforcedStyle: 'rails'

Naming/FileName:
Exclude:
- 'Gemfile'
- 'Guardfile'
- 'Rakefile'

Style/FrozenStringLiteralComment:
Enabled: false

Style/AsciiComments:
Enabled: false

Style/Documentation:
Enabled: false
84 changes: 84 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-08-21 17:24:16 -0700 using RuboCop version 0.58.2.
# 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: 4
Lint/IneffectiveAccessModifier:
Exclude:
- 'model/page.rb'
- 'utilities/file_parser.rb'

# Offense count: 1
# Configuration parameters: ContextCreatingMethods, MethodCreatingMethods.
Lint/UselessAccessModifier:
Exclude:
- 'utilities/file_parser.rb'

# Offense count: 6
Metrics/AbcSize:
Max: 68

# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 106

# Offense count: 1
Metrics/CyclomaticComplexity:
Max: 8

# Offense count: 8
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 42

# Offense count: 1
Metrics/PerceivedComplexity:
Max: 8

# Offense count: 5
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: io, id, to, by, on, in, at, ip
Naming/UncommunicativeMethodParamName:
Exclude:
- 'model/rss_feed.rb'
- 'renderer/renderer.rb'

# Offense count: 3
Style/ClassVars:
Exclude:
- 'renderer/renderer.rb'
- 'utilities/wildcat_file.rb'

# Offense count: 1
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'utilities/file_parser.rb'

# Offense count: 1
Style/IfInsideElse:
Exclude:
- 'model/post.rb'

# Offense count: 8
# Cop supports --auto-correct.
Style/IfUnlessModifier:
Exclude:
- 'model/blog_archive.rb'
- 'model/enclosure.rb'
- 'model/page.rb'
- 'model/post.rb'
- 'model/website_settings.rb'
- 'renderer/renderer.rb'
- 'wildcat_publish.rb'

# Offense count: 37
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 250
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ source 'https://rubygems.org'

gem 'kramdown'
gem 'stringex'

group :development do
gem 'rubocop'
end
18 changes: 18 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
GEM
remote: https://rubygems.org/
specs:
ast (2.4.0)
jaro_winkler (1.5.1)
kramdown (1.17.0)
parallel (1.12.1)
parser (2.5.1.2)
ast (~> 2.4.0)
powerpack (0.1.2)
rainbow (3.0.0)
rubocop (0.58.2)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.10.0)
stringex (2.8.4)
unicode-display_width (1.4.0)

PLATFORMS
ruby

DEPENDENCIES
kramdown
rubocop
stringex

BUNDLED WITH
Expand Down
78 changes: 37 additions & 41 deletions model/blog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
require_relative 'blog_archive'

class Blog

def initialize(settings)
@settings = settings
@cached_posts = nil
Expand All @@ -28,60 +27,57 @@ def recent_posts(count)
end

def posts
if @cached_posts.nil?
@cached_posts = all_blog_posts_reverse_sorted_by_date
end
@cached_posts = all_blog_posts_reverse_sorted_by_date if @cached_posts.nil?
@cached_posts
end

private

def all_blog_posts_reverse_sorted_by_date
def all_blog_posts_reverse_sorted_by_date
paths = WildcatUtils.text_source_files_in_folder(@settings.posts_folder)

paths = WildcatUtils.text_source_files_in_folder(@settings.posts_folder)
unsorted_posts = paths.map do |path|
wildcat_file = WildcatFile.new(path)
Post.new(@settings, wildcat_file)
end

unsorted_posts = paths.map do |path|
wildcat_file = WildcatFile.new(path)
Post.new(@settings, wildcat_file)
posts = unsorted_posts.sort_by(&:pub_date)
posts.reverse
end

posts = unsorted_posts.sort_by { |post| post.pub_date }
posts.reverse
end

def build_home_page
context = {}
context[CONTEXT_TITLE_KEY] = @settings.blog_home_page_title
def build_home_page
context = {}
context[CONTEXT_TITLE_KEY] = @settings.blog_home_page_title

html = ''
posts_for_home_page.each { |post| html+= post.to_html(true) }
context[CONTEXT_CONTENT_HTML_KEY] = html
html = ''
posts_for_home_page.each { |post| html += post.to_html(true) }
context[CONTEXT_CONTENT_HTML_KEY] = html

destination_path = File.join(@settings.blog_output_folder, 'index')
destination_path = WildcatUtils.add_suffix_if_needed(destination_path, @settings.output_file_suffix)
PageBuilder.build(@settings, 'blog_home', context, destination_path)
end
destination_path = File.join(@settings.blog_output_folder, 'index')
destination_path = WildcatUtils.add_suffix_if_needed(destination_path, @settings.output_file_suffix)
PageBuilder.build(@settings, 'blog_home', context, destination_path)
end

def build_json_feed
feed_text = JSONFeed.rendered_feed(@settings, posts_for_feed)
write_feed(feed_text, 'feed.json')
end
def build_json_feed
feed_text = JSONFeed.rendered_feed(@settings, posts_for_feed)
write_feed(feed_text, 'feed.json')
end

def build_rss_feed
feed_text = RSSFeed.rendered_feed(@settings, posts_for_feed)
write_feed(feed_text, 'xml/rss.xml')
end
def build_rss_feed
feed_text = RSSFeed.rendered_feed(@settings, posts_for_feed)
write_feed(feed_text, 'xml/rss.xml')
end

def write_feed(feed_text, relative_path)
destination_path = File.join(@settings.output_folder, relative_path)
WildcatUtils.write_file_if_different(destination_path, feed_text)
end
def write_feed(feed_text, relative_path)
destination_path = File.join(@settings.output_folder, relative_path)
WildcatUtils.write_file_if_different(destination_path, feed_text)
end

def posts_for_feed
recent_posts(@settings.feed_number_of_posts)
end
def posts_for_feed
recent_posts(@settings.feed_number_of_posts)
end

def posts_for_home_page
recent_posts(@settings.blog_number_of_posts)
end
def posts_for_home_page
recent_posts(@settings.blog_number_of_posts)
end
end
Loading