@@ -10,6 +10,25 @@ class Linter
10
10
attr_accessor :docs , :posts , :errors
11
11
12
12
def initialize
13
+ @docs = [ ]
14
+ @posts = [ ]
15
+ @errors = Hash . new { |h , k | h [ k ] = [ ] }
16
+ end
17
+
18
+ # Reads files and runs all checks.
19
+ def run
20
+ print "Checking markdown files..."
21
+
22
+ load_files
23
+ check
24
+ report
25
+
26
+ exit ( 1 ) if errors . any?
27
+ end
28
+
29
+ private
30
+
31
+ def load_files
13
32
md_files = glob ( "**/*.md" )
14
33
skip_patterns = [ /README.md/ , %r{[^/]*/examples/} , %r{\A _includes/} ]
15
34
@@ -19,13 +38,9 @@ def initialize
19
38
20
39
@docs = md_files . map { |fn | Document . new ( fn ) }
21
40
@posts = @docs . select { |doc | doc . filename =~ %r{/_posts/} }
22
-
23
- @errors = Hash . new { |h , k | h [ k ] = [ ] }
24
41
end
25
42
26
43
def check
27
- print "Checking markdown files..."
28
-
29
44
docs . each do |doc |
30
45
errors [ doc ] << " missing lang variable" if doc . lang_missing?
31
46
end
@@ -34,16 +49,6 @@ def check
34
49
errors [ doc ] << " missing author variable" if doc . author_missing?
35
50
errors [ doc ] << " date mismatch between filename and YAML front matter (UTC)" if doc . date_mismatch?
36
51
end
37
-
38
- report
39
-
40
- exit ( 1 ) if errors . any?
41
- end
42
-
43
- private
44
-
45
- def glob ( pattern )
46
- Pathname . glob ( pattern ) . reject { |path | path . expand_path . to_s =~ %r{\A #{ Regexp . escape ( Bundler . bundle_path . to_s ) } /} } . map ( &:to_s )
47
52
end
48
53
49
54
def report
@@ -57,4 +62,8 @@ def report
57
62
end
58
63
end
59
64
end
65
+
66
+ def glob ( pattern )
67
+ Pathname . glob ( pattern ) . reject { |path | path . expand_path . to_s =~ %r{\A #{ Regexp . escape ( Bundler . bundle_path . to_s ) } /} } . map ( &:to_s )
68
+ end
60
69
end
0 commit comments