Method: HTMLProofer::Check::Scripts#run

Defined in:
lib/html_proofer/check/scripts.rb

#runObject


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/html_proofer/check/scripts.rb', line 6

def run
  @html.css("script").each do |node|
    @script = create_element(node)

    next if @script.ignore?
    next unless @script.content.strip.empty?

    # does the script exist?
    if missing_src?
      add_failure("script is empty and has no src attribute", element: @script)
    elsif @script.url.protocol_relative?
      add_failure(
        "script link #{@script.url} is a protocol-relative URL, use explicit https:// instead",
        element: @script,
      )
    elsif @script.url.remote?
      add_to_external_urls(@script.url, @script.line)
      check_sri if @runner.check_sri?
    elsif !@script.url.exists?
      add_failure(
        "internal script reference #{@script.src} does not exist",
        element: @script,
      )
    end
  end

  external_urls
end