Class: Mdlint::Linter::Rules::FirstLineHeading
Instance Attribute Summary
#violations
Instance Method Summary
collapse
#add_violation, inherited, #initialize
Instance Method Details
#check(tokens, _source) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/mdlint/linter/rules/first_line_heading.rb', line 11
def check(tokens, _source)
first_content_token = tokens.find do |t|
%i[heading_open paragraph_open bullet_list_open ordered_list_open
blockquote_open fence code_block hr html_block].include?(t.type) && !directive?(t)
end
return @violations unless first_content_token
if first_content_token.type != :heading_open
add_violation(
message: "First line should be a top-level heading",
line: (first_content_token.map&.first || 0) + 1,
fixable: false
)
elsif first_content_token.tag != "h1"
add_violation(
message: "First heading should be h1",
line: (first_content_token.map&.first || 0) + 1,
fixable: false
)
end
@violations
end
|
#directive?(token) ⇒ Boolean
42
43
44
|
# File 'lib/mdlint/linter/rules/first_line_heading.rb', line 42
def directive?(token)
token.type == :html_block && token.content.match?(/<!--\s*mdlint-(?:disable|enable)/i)
end
|
#fix(_tokens, source) ⇒ Object
36
37
38
|
# File 'lib/mdlint/linter/rules/first_line_heading.rb', line 36
def fix(_tokens, source)
source
end
|