Skip to content

Commit

Permalink
Lint with rubocop-jekyll (#128)
Browse files Browse the repository at this point in the history
Merge pull request 128
  • Loading branch information
jekyllbot committed Oct 8, 2018
1 parent c832738 commit 5fed34c
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 46 deletions.
11 changes: 9 additions & 2 deletions .rubocop.yml
@@ -1,15 +1,22 @@
require: rubocop-jekyll

inherit_gem:
jekyll: .rubocop.yml
rubocop-jekyll: .rubocop.yml

AllCops:
TargetRubyVersion: 2.1
TargetRubyVersion: 2.2
Exclude:
- vendor/**/*

Lint/ShadowingOuterLocalVariable:
Exclude:
- lib/jekyll-archives.rb

# Remove once Jekyll core has dropped explicit support for Ruby 2.2
Lint/SafeNavigationConsistency:
Exclude:
- lib/jekyll-archives/archive.rb

Metrics/BlockLength:
Exclude:
- test/**/*.rb
Expand Down
7 changes: 3 additions & 4 deletions .travis.yml
Expand Up @@ -3,20 +3,19 @@ script : script/cibuild
cache: bundler
sudo: false

before_install:
before_install:
- gem update --system
- bundle update
rvm:
- 2.2
- 2.3
- 2.4
- 2.5
env:
- ""
- JEKYLL_VERSION=3.6
- JEKYLL_VERSION=3.7.4

matrix:
include:
- # GitHub Pages
rvm: 2.4.0
rvm: 2.5.1
env: GH_PAGES=true
3 changes: 0 additions & 3 deletions Gemfile
Expand Up @@ -8,6 +8,3 @@ if ENV["GH_PAGES"]
elsif ENV["JEKYLL_VERSION"]
gem "jekyll", "~> #{ENV["JEKYLL_VERSION"]}"
end

# Support for Ruby < 2.2.2 & activesupport
gem "activesupport", "~> 4.2" if RUBY_VERSION < "2.2.2"
18 changes: 10 additions & 8 deletions jekyll-archives.gemspec
Expand Up @@ -14,14 +14,16 @@ Gem::Specification.new do |s|
s.homepage = "https://github.com/jekyll/jekyll-archives"
s.licenses = ["MIT"]

all_files = `git ls-files -z`.split("\x0")
s.files = all_files.grep(%r!^(lib)/!)
all_files = `git ls-files -z`.split("\x0")
s.files = all_files.grep(%r!^(lib)/!)

s.add_dependency "jekyll", ">= 3.1"
s.required_ruby_version = ">= 2.2.0"

s.add_development_dependency "minitest"
s.add_development_dependency "rake"
s.add_development_dependency "rdoc"
s.add_development_dependency "rubocop", "0.51"
s.add_development_dependency "shoulda"
s.add_dependency "jekyll", "~> 3.6"

s.add_development_dependency "minitest"
s.add_development_dependency "rake"
s.add_development_dependency "rdoc"
s.add_development_dependency "rubocop-jekyll", "~> 0.2.0"
s.add_development_dependency "shoulda"
end
6 changes: 3 additions & 3 deletions lib/jekyll-archives/archive.rb
Expand Up @@ -78,11 +78,11 @@ def url_placeholders
#
# Returns the String url.
def url
@url ||= URL.new({
@url ||= URL.new(
:template => template,
:placeholders => url_placeholders,
:permalink => nil,
}).to_s
:permalink => nil
).to_s
rescue ArgumentError
raise ArgumentError, "Template \"#{template}\" provided is invalid."
end
Expand Down
38 changes: 18 additions & 20 deletions test/helper.rb
Expand Up @@ -16,32 +16,30 @@
SOURCE_DIR = File.expand_path("source", TEST_DIR)
DEST_DIR = File.expand_path("destination", TEST_DIR)

class Minitest::Test
def fixture_site(config = {})
Jekyll::Site.new(
Jekyll::Utils.deep_merge_hashes(
module Minitest
class Test
def fixture_site(config = {})
Jekyll::Site.new(
Jekyll::Utils.deep_merge_hashes(
Jekyll::Configuration::DEFAULTS,
{
Jekyll::Utils.deep_merge_hashes(
Jekyll::Configuration::DEFAULTS,
"source" => SOURCE_DIR,
"destination" => DEST_DIR,
}
),
config
"destination" => DEST_DIR
),
config
)
)
)
end
end

def archive_exists?(site, path)
site.config["archives"].any? { |archive| archive.path == path }
end
def archive_exists?(site, path)
site.config["archives"].any? { |archive| archive.path == path }
end

def read_file(path)
read_path = File.join(DEST_DIR, path)
return false unless File.exist?(read_path)

def read_file(path)
read_path = File.join(DEST_DIR, path)
if File.exist? read_path
File.read(read_path).strip
else
return false
end
end
end
12 changes: 6 additions & 6 deletions test/test_jekyll_archives.rb
Expand Up @@ -65,14 +65,14 @@ class TestJekyllArchives < Minitest::Test

context "the jekyll-archives plugin with type-specific layout" do
setup do
@site = fixture_site({
@site = fixture_site(
"jekyll-archives" => {
"enabled" => true,
"layouts" => {
"year" => "archive-too",
},
},
})
}
)
@site.process
end

Expand All @@ -85,16 +85,16 @@ class TestJekyllArchives < Minitest::Test

context "the jekyll-archives plugin with custom permalinks" do
setup do
@site = fixture_site({
@site = fixture_site(
"jekyll-archives" => {
"enabled" => true,
"permalinks" => {
"year" => "/year/:year/",
"tag" => "/tag-:name.html",
"category" => "/category-:name.html",
},
},
})
}
)
@site.process
end

Expand Down

0 comments on commit 5fed34c

Please sign in to comment.