Class: Mdlint::Linter::Rules::HeadingIncrement

Inherits:
Mdlint::Linter::Rule show all
Defined in:
lib/mdlint/linter/rules/heading_increment.rb,
sig/internal.rbs

Instance Attribute Summary

Attributes inherited from Mdlint::Linter::Rule

#violations

Instance Method Summary collapse

Methods inherited from Mdlint::Linter::Rule

#add_violation, inherited, #initialize

Constructor Details

This class inherits a constructor from Mdlint::Linter::Rule

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
# File 'lib/mdlint/linter/rules/heading_increment.rb', line 11

def check(tokens, _source)
  last_level = 0

  tokens.each do |token|
    next unless token.type == :heading_open

    level = token.tag.to_s[1].to_i
    if last_level > 0 && level > last_level + 1
      add_violation(
        message: "Heading level jumped from h#{last_level} to h#{level}",
        line: (token.map&.first || 0) + 1,
        fixable: false
      )
    end
    last_level = level
  end

  @violations
end

#fix(_tokens, source) ⇒ Object



31
32
33
# File 'lib/mdlint/linter/rules/heading_increment.rb', line 31

def fix(_tokens, source)
  source
end