Skip to content

Commit 8a813c4

Browse files
committed
Extract some methods
1 parent a4ba6e7 commit 8a813c4

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

Rakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ end
129129
desc "Run some tests on markdown files"
130130
task :check do
131131
require_relative "lib/linter"
132-
Linter.new.check
132+
Linter.new.run
133133
end
134134

135135
task :ci => [:test, :build]

lib/linter.rb

+23-14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,25 @@ class Linter
1010
attr_accessor :docs, :posts, :errors
1111

1212
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
1332
md_files = glob("**/*.md")
1433
skip_patterns = [/README.md/, %r{[^/]*/examples/}, %r{\A_includes/}]
1534

@@ -19,13 +38,9 @@ def initialize
1938

2039
@docs = md_files.map {|fn| Document.new(fn) }
2140
@posts = @docs.select {|doc| doc.filename =~ %r{/_posts/} }
22-
23-
@errors = Hash.new {|h, k| h[k] = [] }
2441
end
2542

2643
def check
27-
print "Checking markdown files..."
28-
2944
docs.each do |doc|
3045
errors[doc] << " missing lang variable" if doc.lang_missing?
3146
end
@@ -34,16 +49,6 @@ def check
3449
errors[doc] << " missing author variable" if doc.author_missing?
3550
errors[doc] << " date mismatch between filename and YAML front matter (UTC)" if doc.date_mismatch?
3651
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)
4752
end
4853

4954
def report
@@ -57,4 +62,8 @@ def report
5762
end
5863
end
5964
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
6069
end

0 commit comments

Comments
 (0)