Skip to content

Commit a645946

Browse files
committed
Move logic for old posts from Document to Linter
Handle exceptions for old posts in the Linter class, not in Linter::Document. This helps in making the methods do what their name implies.
1 parent 69042a8 commit a645946

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

lib/linter.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,13 @@ def check
7272

7373
posts.each do |doc|
7474
errors[doc] << "missing author variable" if doc.author_missing?
75-
errors[doc] << "missing translator variable" if doc.translator_missing?
76-
errors[doc] << "missing or invalid date variable" if doc.date_missing?
7775
errors[doc] << "date mismatch between filename and YAML front matter (UTC)" if doc.date_mismatch?
7876
errors[doc] << "wrong time zone offset in YAML front matter (not UTC)" if doc.yaml_date_not_utc?
77+
78+
unless doc.old_post?
79+
errors[doc] << "missing translator variable" if doc.translator_missing?
80+
errors[doc] << "missing or invalid date variable" if doc.date_missing?
81+
end
7982
end
8083
end
8184

lib/linter/document.rb

+2-6
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,16 @@ def author_missing?
3232
end
3333

3434
def translator_missing?
35-
return nil if old_post?
36-
3735
!yaml.has_key?("translator")
3836
end
3937

4038
# date missing or invalid
4139
def date_missing?
42-
return nil if old_post?
43-
4440
yaml["date"].nil? || !yaml["date"].respond_to?(:getutc)
4541
end
4642

4743
def date_mismatch?
48-
return nil if (date_missing? || old_post?)
44+
return nil if date_missing?
4945

5046
yaml_date_utc != slug_date
5147
end
@@ -59,7 +55,7 @@ def slug_date
5955
end
6056

6157
def yaml_date_not_utc?
62-
return nil if (date_missing? || old_post?)
58+
return nil if date_missing?
6359

6460
yaml["date"].utc_offset != 0
6561
end

0 commit comments

Comments
 (0)