Skip to content

Commit 563236a

Browse files
committed
Bail from frontmatterpropertyexists check if not properties configured
Also adds the ability to accept messages from successful checks
1 parent dac1a38 commit 563236a

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

lib/jekyll-pre-commit/checks/front_matter_property_exists.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ module PreCommit
33
module Check
44
class FrontMatterPropertyExists < Check
55
def Check(staged, not_staged, site, args)
6+
if !args["properties"]
7+
@result[:message] += "No properties to check."
8+
return @result
9+
end
10+
611
staged.each do |post|
712
args["properties"].each do |property|
813
if !post.data[property]

lib/jekyll-pre-commit/runner.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ def run(site, staged_files)
3232
r = o.Check(staged_posts, not_staged_posts, site, c)
3333
if !r[:ok]
3434
result[:ok] = false
35+
end
36+
if r[:message] != ""
3537
result[:messages].push(r[:message])
3638
end
3739
end

spec/jekyll-pre-commit_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@
5050
end
5151
end
5252

53+
context "with FrontMatterPropertyExistsCheck not checking any properties" do
54+
pre_commit_config = {"check" => "FrontMatterPropertyExists"}
55+
let(:site) { build_site({ 'pre-commit' => [pre_commit_config] }) }
56+
57+
it "succeeds with no properties to check message" do
58+
result = runner.run(site, ["spec/fixtures/_posts/2017-01-06-no-description.md"])
59+
expect(result[:ok]).to eql(true)
60+
expect(result[:messages]).to match_array(["No properties to check."])
61+
end
62+
end
63+
5364
context "with description is not duplicate check" do
5465
let(:site) { build_site({'pre-commit' => [{"check" => "DescriptionIsNotDuplicate"}]}) }
5566

0 commit comments

Comments
 (0)