Class: Mdlint::Linter::Rules::EmphasisStyle

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

Constant Summary

Constants included from SourceStyleSupport

SourceStyleSupport::FENCE_REGEXP, SourceStyleSupport::LIST_MARKER_REGEXP

Instance Attribute Summary

Attributes inherited from Mdlint::Linter::Rule

#violations

Instance Method Summary collapse

Methods included from SourceStyleSupport

#fenced_lines, #inline_tokens, #line_is_blank?, #lines, #outside_fence?

Methods inherited from Mdlint::Linter::Rule

#add_violation, #fix, inherited, #initialize

Constructor Details

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

Instance Method Details

#check(tokens, _source) ⇒ Object



285
286
287
288
289
290
291
292
293
294
# File 'lib/mdlint/linter/rules/source_style.rb', line 285

def check(tokens, _source)
  expected = @options.fetch(:emphasis_style, :asterisk).to_s
  inline_tokens(tokens).each do |token|
    next unless token.type == :em_open
    next unless (expected == "asterisk" && token.markup == "_") || (expected == "underscore" && token.markup == "*")

    add_violation(message: "Use #{expected} emphasis markers", line: 1, fixable: false)
  end
  @violations
end