Class: Mdlint::Linter::Rules::NoBareUrls

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



196
197
198
199
200
201
202
203
204
205
206
# File 'lib/mdlint/linter/rules/source_style.rb', line 196

def check(tokens, source)
  return @violations unless Dialect.resolve(@options[:dialect]).feature?(:bare_autolinks)

  source.each_line.with_index(1) do |line, line_number|
    next if line.match?(FENCE_REGEXP)
    next unless line.match?(%r{(?<![<\w"'=(])https?://[^\s<>]+})

    add_violation(message: "Enclose bare URLs in angle brackets", line: line_number, fixable: false)
  end
  @violations
end