Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
tdreyno committed Sep 29, 2020
1 parent 954933c commit f4aefcf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ class FrontMatter < ::Middleman::Extension
json: [%w[;;; ;;;]],
yaml: [
# Normal
%w[--- ---],
%w[--- ---],

# Pandoc
%w[--- ...],
%w[--- ...],

# Haml with commented frontmatter
["-#\n ---", " ---"],
["-#\n ---", ' ---'],

# Slim with commented frontmatter
["\/\n ---", " ---"],
["\/\n ---", ' ---'],

# ERb with commented frontmatter
["<%#\n ---", " ---\n%>"]
]
Expand Down
22 changes: 11 additions & 11 deletions middleman-core/lib/middleman-core/util/binary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -361,17 +361,17 @@ def contains_frontmatter?(path, frontmatter_delims)

first_three_lines = [file.gets, file.gets, file.gets]
file.close

first_two_lines = if /\A(?:[^\r\n]*coding:[^\r\n]*\r?\n)/.match?(first_three_lines.first)
[first_three_lines[1], first_three_lines[2]]
else
[first_three_lines[0], first_three_lines[1]]
end
[first_three_lines[1], first_three_lines[2]]
else
[first_three_lines[0], first_three_lines[1]]
end

possible_openers = possible_delim_openers(frontmatter_delims)

!first_two_lines[0].nil? && possible_openers.any? do |delim|
!first_two_lines.join("").match(/\A#{delim}/).nil?
!first_two_lines.join('').match(/\A#{delim}/).nil?
end
rescue EOFError, IOError, ::Errno::ENOENT
false
Expand All @@ -380,11 +380,11 @@ def contains_frontmatter?(path, frontmatter_delims)
Contract Maybe[HashOf[Symbol, Any]] => Regexp
def possible_delim_openers(frontmatter_delims)
frontmatter_delims
.values
.flatten(1)
.map(&:first)
.uniq
.map { |d| Regexp.escape(d) }
.values
.flatten(1)
.map(&:first)
.uniq
.map { |d| Regexp.escape(d) }
end
end
end
8 changes: 4 additions & 4 deletions middleman-core/lib/middleman-core/util/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ def parse(source_file, frontmatter_delims, known_type = nil)
end

match = build_regexes(frontmatter_delims)
.lazy
.map { |r| r.match(content) }
.select { |r| !r.nil? }
.first || {}
.lazy
.map { |r| r.match(content) }
.reject(&:nil?)
.first || {}

unless match[:frontmatter]
case known_type
Expand Down

0 comments on commit f4aefcf

Please sign in to comment.