forked from github/opensource.guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlint_test.rb
39 lines (32 loc) · 1005 Bytes
/
lint_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require_relative "./helper"
describe "lint test" do
pages.each do |page|
next unless page["path"].match?(/\.md$/)
describe page["path"] do
describe "frontmatter" do
before do
# Load raw metadata to skip defaults
@data = SafeYAML.load_file(page["path"])
end
it "has valid fields" do
assert_valid_fields @data, site.data["fields"]
end
end
end
end
def assert_valid_fields(data, fields)
extra_fields = data.keys - fields.keys
assert extra_fields.empty?, "Unexpected metadata: #{extra_fields.inspect}"
fields.each do |name, attrs|
assert data.key?(name), "#{name} is required" if attrs["required"]
if attrs["type"] && @data[name]
assert_kind_of Kernel.const_get(attrs["type"]), @data[name]
end
# Check subfields
next unless attrs["fields"] && @data[name]
@data[name].each do |d|
assert_valid_fields(d, attrs["fields"])
end
end
end
end