Skip to content

Commit 7ff0bb9

Browse files
authored
Add style_check job to CI workflow (#178)
Merge pull request 178
1 parent d35231e commit 7ff0bb9

File tree

10 files changed

+77
-48
lines changed

10 files changed

+77
-48
lines changed

.github/workflows/ci.yml

+18
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,21 @@ jobs:
3131
bundler-cache: true
3232
- name: Run Unit Tests
3333
run: bundle exec rake test
34+
35+
style_check:
36+
name: "Style Check (Ruby ${{ matrix.ruby_version }})"
37+
runs-on: "ubuntu-latest"
38+
strategy:
39+
fail-fast: false
40+
matrix:
41+
ruby_version:
42+
- "3.3"
43+
steps:
44+
- uses: actions/checkout@v4
45+
- name: "Set up Ruby ${{ matrix.ruby_version }}"
46+
uses: ruby/setup-ruby@v1
47+
with:
48+
ruby-version: ${{ matrix.ruby_version }}
49+
bundler-cache: true
50+
- name: Run RuboCop
51+
run: bash script/fmt

.rubocop.yml

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
1-
require: rubocop-jekyll
1+
require:
2+
- rubocop-jekyll
3+
- rubocop-minitest
24

35
inherit_gem:
46
rubocop-jekyll: .rubocop.yml
57

68
AllCops:
7-
TargetRubyVersion: 2.3
9+
TargetRubyVersion: 2.7
10+
SuggestExtensions: false
811
Exclude:
912
- vendor/**/*
1013

11-
Lint/ShadowingOuterLocalVariable:
14+
Layout/LineLength:
1215
Exclude:
1316
- lib/jekyll-archives.rb
14-
15-
# Remove once Jekyll core has dropped explicit support for Ruby 2.2
16-
Lint/SafeNavigationConsistency:
17-
Exclude:
1817
- lib/jekyll-archives/archive.rb
18+
- test/**/*.rb
1919

2020
Metrics/BlockLength:
2121
Exclude:
2222
- test/**/*.rb
2323

24-
Metrics/LineLength:
25-
Exclude:
26-
- lib/jekyll-archives.rb
27-
- lib/jekyll-archives/archive.rb
28-
- test/**/*.rb
24+
Minitest/AssertKindOf:
25+
Enabled: true
26+
Minitest/EmptyLineBeforeAssertionMethods:
27+
Enabled: true

Gemfile

+6
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ gemspec
55

66
gem "jekyll", ENV["JEKYLL_VERSION"] if ENV["JEKYLL_VERSION"]
77
gem "kramdown-parser-gfm" if ENV["JEKYLL_VERSION"] == "~> 3.9"
8+
9+
gem "minitest"
10+
gem "rake"
11+
gem "rubocop-jekyll", "~> 0.14.0"
12+
gem "rubocop-minitest"
13+
gem "shoulda-context"

jekyll-archives.gemspec

+1-8
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,7 @@ Gem::Specification.new do |s|
1515
all_files = `git ls-files -z`.split("\x0")
1616
s.files = all_files.grep(%r!^(lib)/!)
1717

18-
s.required_ruby_version = ">= 2.3.0"
18+
s.required_ruby_version = ">= 2.7.0"
1919

2020
s.add_dependency "jekyll", ">= 3.6", "< 5.0"
21-
22-
s.add_development_dependency "bundler"
23-
s.add_development_dependency "minitest"
24-
s.add_development_dependency "rake"
25-
s.add_development_dependency "rdoc"
26-
s.add_development_dependency "rubocop-jekyll", "~> 0.9"
27-
s.add_development_dependency "shoulda"
2821
end

lib/jekyll-archives.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def append_enabled_date_type(meta, type, posts)
133133
def date_attr_hash(posts, id)
134134
hash = Hash.new { |hsh, key| hsh[key] = [] }
135135
posts.each { |post| hash[post.date.strftime(id)] << post }
136-
hash.each_value { |posts| posts.sort!.reverse! }
136+
hash.each_value { |posts_in_hsh| posts_in_hsh.sort!.reverse! }
137137
hash
138138
end
139139
end

lib/jekyll-archives/archive.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,19 @@ def url
7777
:permalink => nil
7878
).to_s
7979
rescue ArgumentError
80-
raise ArgumentError, "Template \"#{template}\" provided is invalid."
80+
raise ArgumentError, "Template #{template.inspect} provided is invalid."
8181
end
8282

8383
def permalink
84-
data&.is_a?(Hash) && data["permalink"]
84+
data.is_a?(Hash) && data["permalink"]
8585
end
8686

8787
# Produce a title object suitable for Liquid based on type of archive.
8888
#
8989
# Returns a String (for tag and category archives) and nil for
9090
# date-based archives.
9191
def title
92-
@title if @title.is_a? String
92+
@title if @title.is_a?(String)
9393
end
9494

9595
# Produce a date object if a date-based archive

script/fmt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/bin/bash
22
set -e
33

4-
echo "Rubocop $(bundle exec rubocop --version)"
5-
bundle exec rubocop -S -D -E $@
4+
echo "RuboCop $(bundle exec rubocop --version)"
5+
bundle exec rubocop -E --disable-pending-cops $@
66
success=$?
77
if ((success != 0)); then
88
echo -e "\nTry running \`script/fmt -a\` to automatically fix errors"

test/helper.rb

+4-8
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@
55

66
require "rubygems"
77
require "minitest/autorun"
8-
require "shoulda"
8+
require "shoulda/context"
99

10-
$LOAD_PATH.unshift(File.join(__dir__, "..", "lib"))
11-
$LOAD_PATH.unshift(__dir__)
10+
require_relative "../lib/jekyll-archives"
1211

13-
require "jekyll-archives"
14-
15-
TEST_DIR = __dir__
16-
SOURCE_DIR = File.expand_path("source", TEST_DIR)
17-
DEST_DIR = File.expand_path("destination", TEST_DIR)
12+
SOURCE_DIR = File.expand_path("source", __dir__)
13+
DEST_DIR = File.expand_path("destination", __dir__)
1814

1915
module Minitest
2016
class Test

test/test_jekyll_archive.rb

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class TestJekyllArchive < Minitest::Test
2727
"url" => "/tag/test-tag/",
2828
"permalink" => nil,
2929
}
30+
3031
assert_equal expected, archive.to_liquid.to_h
3132

3233
archive = @archives.find { |a| a.type == "category" }
@@ -42,6 +43,7 @@ class TestJekyllArchive < Minitest::Test
4243
"url" => "/category/plugins/",
4344
"permalink" => nil,
4445
}
46+
4547
assert_equal expected, archive.to_liquid.to_h
4648

4749
archive = @archives.find { |a| a.type == "year" }
@@ -57,6 +59,7 @@ class TestJekyllArchive < Minitest::Test
5759
"url" => "/2013/",
5860
"permalink" => nil,
5961
}
62+
6063
assert_equal expected, archive.to_liquid.to_h
6164

6265
archive = @archives.find { |a| a.type == "month" }
@@ -72,6 +75,7 @@ class TestJekyllArchive < Minitest::Test
7275
"url" => "/2013/08/",
7376
"permalink" => nil,
7477
}
78+
7579
assert_equal expected, archive.to_liquid.to_h
7680

7781
archive = @archives.find { |a| a.type == "day" }
@@ -87,6 +91,7 @@ class TestJekyllArchive < Minitest::Test
8791
"url" => "/2013/08/16/",
8892
"permalink" => nil,
8993
}
94+
9095
assert_equal expected, archive.to_liquid.to_h
9196
end
9297
end

test/test_jekyll_archives.rb

+26-14
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,42 @@ class TestJekyllArchives < Minitest::Test
1414

1515
should "generate archive pages by year" do
1616
@archives.generate(@site)
17+
1718
assert archive_exists? @site, "2014/index.html"
1819
assert archive_exists? @site, "2013/index.html"
1920
end
2021

2122
should "generate archive pages by month" do
2223
@archives.generate(@site)
24+
2325
assert archive_exists? @site, "2014/08/index.html"
2426
assert archive_exists? @site, "2014/03/index.html"
2527
end
2628

2729
should "generate archive pages by day" do
2830
@archives.generate(@site)
31+
2932
assert archive_exists? @site, "2014/08/17/index.html"
3033
assert archive_exists? @site, "2013/08/16/index.html"
3134
end
3235

3336
should "generate archive pages by tag" do
3437
@archives.generate(@site)
38+
3539
assert archive_exists? @site, "tag/test-tag/index.html"
3640
assert archive_exists? @site, "tag/tagged/index.html"
3741
assert archive_exists? @site, "tag/new/index.html"
3842
end
3943

4044
should "generate archive pages by category" do
4145
@archives.generate(@site)
46+
4247
assert archive_exists? @site, "category/plugins/index.html"
4348
end
4449

4550
should "generate archive pages with a layout" do
4651
@site.process
52+
4753
assert_equal "Test", read_file("tag/test-tag/index.html")
4854
end
4955
end
@@ -62,6 +68,7 @@ class TestJekyllArchives < Minitest::Test
6268

6369
should "generate slugs using the mode specified" do
6470
@archives.generate(@site)
71+
6572
assert archive_exists? @site, "category/💎/index.html"
6673
end
6774
end
@@ -77,6 +84,7 @@ class TestJekyllArchives < Minitest::Test
7784

7885
should "use custom layout" do
7986
@site.process
87+
8088
assert_equal "Test too", read_file("tag/test-tag/index.html")
8189
end
8290
end
@@ -164,10 +172,10 @@ class TestJekyllArchives < Minitest::Test
164172
end
165173

166174
should "not generate the disabled archives" do
167-
assert !archive_exists?(@site, "2014/index.html")
168-
assert !archive_exists?(@site, "2014/08/index.html")
169-
assert !archive_exists?(@site, "2013/08/16/index.html")
170-
assert !archive_exists?(@site, "category/plugins/index.html")
175+
refute archive_exists?(@site, "2014/index.html")
176+
refute archive_exists?(@site, "2014/08/index.html")
177+
refute archive_exists?(@site, "2013/08/16/index.html")
178+
refute archive_exists?(@site, "category/plugins/index.html")
171179
end
172180
end
173181

@@ -186,25 +194,25 @@ class TestJekyllArchives < Minitest::Test
186194
end
187195

188196
should "populate the title field in case of category or tag" do
189-
assert @tag_archive.title.is_a? String
190-
assert @category_archive.title.is_a? String
197+
assert_kind_of String, @tag_archive.title
198+
assert_kind_of String, @category_archive.title
191199
end
192200

193201
should "use nil for the title field in case of dates" do
194-
assert @year_archive.title.nil?
195-
assert @month_archive.title.nil?
196-
assert @day_archive.title.nil?
202+
assert_nil @year_archive.title
203+
assert_nil @month_archive.title
204+
assert_nil @day_archive.title
197205
end
198206

199207
should "use nil for the date field in case of category or tag" do
200-
assert @tag_archive.date.nil?
201-
assert @category_archive.date.nil?
208+
assert_nil @tag_archive.date
209+
assert_nil @category_archive.date
202210
end
203211

204212
should "populate the date field with a Date in case of dates" do
205-
assert @year_archive.date.is_a? Date
206-
assert @month_archive.date.is_a? Date
207-
assert @day_archive.date.is_a? Date
213+
assert_kind_of Date, @year_archive.date
214+
assert_kind_of Date, @month_archive.date
215+
assert_kind_of Date, @day_archive.date
208216
end
209217
end
210218

@@ -215,6 +223,7 @@ class TestJekyllArchives < Minitest::Test
215223
site.read
216224
site.generate
217225
end
226+
218227
assert_includes output, "Archives: Expected a hash but got [\"apples\", \"oranges\"]"
219228
assert_includes output, "Archives will not be generated for this site."
220229

@@ -223,6 +232,7 @@ class TestJekyllArchives < Minitest::Test
223232
site.read
224233
site.generate
225234
end
235+
226236
assert_includes output, "Archives: Expected a hash but got nil"
227237
assert_includes output, "Archives will not be generated for this site."
228238
end
@@ -232,6 +242,7 @@ class TestJekyllArchives < Minitest::Test
232242
site = fixture_site("jekyll-archives" => nil)
233243
site.read
234244
site.generate
245+
235246
assert_nil(site.pages.find { |p| p.is_a?(Jekyll::Archives::Archive) })
236247
end
237248
end
@@ -242,6 +253,7 @@ class TestJekyllArchives < Minitest::Test
242253
@site.read
243254
@site.generate
244255
end
256+
245257
refute_includes output, "Archives: Expected a hash but got nil"
246258
assert_nil(@site.pages.find { |p| p.is_a?(Jekyll::Archives::Archive) })
247259
end

0 commit comments

Comments
 (0)