Class: Mdlint::Linter::Rules::NoSpaceInCode

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



233
234
235
236
237
238
239
240
241
# File 'lib/mdlint/linter/rules/source_style.rb', line 233

def check(_tokens, source)
  source.each_line.with_index(1) do |line, line_number|
    invalid = line.scan(/(`+)([^`\n]*?)\1/).any? { |_marker, content| content.to_s != content.to_s.strip }
    next unless invalid

    add_violation(message: "Remove spaces inside code span markers", line: line_number, fixable: false)
  end
  @violations
end