Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
gjtorikian committed May 6, 2024
1 parent aa70798 commit c69b32d
Show file tree
Hide file tree
Showing 23 changed files with 40 additions and 38 deletions.
3 changes: 2 additions & 1 deletion lib/html_proofer/attribute/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def unknown_extension?

def ignore?
return true if /^javascript:/.match?(@url)
return true if ignores_pattern?(@runner.options[:ignore_urls])

true if ignores_pattern?(@runner.options[:ignore_urls])
end

def valid?
Expand Down
7 changes: 4 additions & 3 deletions lib/html_proofer/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def initialize(runner, options)
end

def parsed_timeframe(timeframe)
return nil if timeframe.nil?
return if timeframe.nil?

time, date = timeframe.match(/(\d+)(\D)/).captures
time = time.to_i
Expand Down Expand Up @@ -252,7 +252,7 @@ def size(type)
SECONDS_PER_HOUR = 3600
SECONDS_PER_DAY = 86400
SECONDS_PER_WEEK = 604800
SECONDS_PER_MONTH = 2629746 # 1/12 of a gregorian year
SECONDS_PER_MONTH = 2629746 # 1/12 of a gregorian year

private def time_ago(measurement, unit)
case unit
Expand All @@ -269,7 +269,8 @@ def size(type)

private def url_matches_type?(url, type)
return true if type == :internal && url !~ URI_REGEXP
return true if type == :external && url =~ URI_REGEXP

true if type == :external && url =~ URI_REGEXP
end

private def cleaned_url(url)
Expand Down
4 changes: 2 additions & 2 deletions lib/html_proofer/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ def parse_cli_options(args)
arg.split(",").each_with_object({}) do |s, hsh|
split = s.split(/(?<!\\):/, 2)

re = split[0].gsub(/\\:/, ":")
string = split[1].gsub(/\\:/, ":")
re = split[0].gsub("\\:", ":")
string = split[1].gsub("\\:", ":")
hsh[Regexp.new(re)] = string
end
end
Expand Down
14 changes: 7 additions & 7 deletions lib/html_proofer/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def link_attribute
end

def meta_content
return nil unless meta_tag?
return unless meta_tag?

@node["content"]
end
Expand All @@ -37,7 +37,7 @@ def meta_tag?
end

def src
return nil if !img_tag? && !script_tag? && !source_tag?
return if !img_tag? && !script_tag? && !source_tag?

@node["src"]
end
Expand All @@ -51,7 +51,7 @@ def script_tag?
end

def srcset
return nil if !img_tag? && !source_tag?
return if !img_tag? && !source_tag?

@node["srcset"]
end
Expand All @@ -61,7 +61,7 @@ def source_tag?
end

def href
return nil if !a_tag? && !link_tag?
return if !a_tag? && !link_tag?

@node["href"]
end
Expand Down Expand Up @@ -96,7 +96,7 @@ def multiple_srcsets?
IMAGE_CANDIDATE_REGEX = /\s*([^,]\S*[^,](?:\s+[^,]+)?)\s*(?:,|$)/

def srcsets
return nil if blank?(srcset)
return if blank?(srcset)

srcset.split(IMAGE_CANDIDATE_REGEX).select.with_index do |_part, idx|
idx.odd?
Expand All @@ -112,7 +112,7 @@ def multiple_sizes?
end

def srcsets_wo_sizes
return nil if blank?(srcsets)
return if blank?(srcsets)

srcsets.map do |srcset|
srcset.split(" ").first
Expand All @@ -133,7 +133,7 @@ def ignore?

attrs = @runner.options[:swap_attributes][@node.name]

return true unless blank?(attrs)
true unless blank?(attrs)
end

private def swap_attributes!
Expand Down
4 changes: 2 additions & 2 deletions lib/html_proofer/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def load_external_cache
end

private def load_cache(type)
ivar = instance_variable_get("@#{type}_urls")
ivar = instance_variable_get(:"@#{type}_urls")

existing_urls_count = @cache.size(type)
cache_text = pluralize(existing_urls_count, "#{type} link", "#{type} links")
Expand All @@ -249,7 +249,7 @@ def load_external_cache

private def format_checks_list(checks)
checks.map do |check|
check.sub(/HTMLProofer::Check::/, "")
check.sub("HTMLProofer::Check::", "")
end.sort.join(", ")
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/html_proofer/url_validator/internal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def run_internal_link_checker(links)
# https://www.w3.org/TR/html5/single-page.html#scroll-to-fragid
return true if fragment_ids.include?("top")

nil
false
end

private def hash_exists_in_html?(href_hash, html)
Expand Down
2 changes: 1 addition & 1 deletion spec/html-proofer/attribute/url_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

describe HTMLProofer::Attribute::Url do
describe Attribute::Url do
let(:runner) { HTMLProofer::Runner.new("") }

describe "#ignores_pattern_check" do
Expand Down
2 changes: 1 addition & 1 deletion spec/html-proofer/cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

describe HTMLProofer::Cache do
describe Cache do
let(:cache_fixture_dir) { File.join(FIXTURES_DIR, "cache") }

let(:default_cache_options) { { storage_dir: cache_fixture_dir } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

describe HTMLProofer::Check::Favicon do
describe Check::Favicon do
it "ignores for absent favicon by default" do
absent = File.join(FIXTURES_DIR, "favicon", "favicon_absent.html")
expect(run_proofer(absent, :file).failed_checks).to(eq([]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

describe HTMLProofer::Check::Images do
describe Check::Images do
it "passes for existing external images" do
external_image_filepath = File.join(FIXTURES_DIR, "images", "existing_image_external.html")
proofer = run_proofer(external_image_filepath, :file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

describe HTMLProofer::Check::Links do
describe Check::Links do
it "fails for broken internal hash (even if the file exists)" do
broken_hash_external_filepath = File.join(FIXTURES_DIR, "links", "broken_hash_external_file.html")
proofer = run_proofer(broken_hash_external_filepath, :file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

describe HTMLProofer::Check::OpenGraph do
describe Check::OpenGraph do
it "passes for existing external url" do
url_valid = File.join(FIXTURES_DIR, "opengraph", "url-valid.html")
proofer = run_proofer(url_valid, :file, checks: ["OpenGraph"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

describe HTMLProofer::Check::Scripts do
describe Check::Scripts do
it "fails for src missing the protocol" do
file = File.join(FIXTURES_DIR, "scripts", "script_missing_protocol.html")
proofer = run_proofer(file, :file)
Expand Down
4 changes: 2 additions & 2 deletions spec/html-proofer/check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def run
end
end

describe HTMLProofer::Reporter do
it "supports a custom reporter" do
describe Check do
it "supports a custom check" do
file = File.join(FIXTURES_DIR, "links", "mailto_octocat.html")
cassette_name = make_cassette_name(file, {})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

describe HTMLProofer::CLI do
describe CLI do
it "works with allow-hash-href" do
broken = File.join(FIXTURES_DIR, "links", "hash_href.html")
output = make_bin("--allow-hash-href #{broken}")
Expand Down Expand Up @@ -215,14 +215,14 @@

it "has only one UA" do
http = make_bin(%|--typhoeus='{"verbose":true,"headers":{"User-Agent":"Mozilla/5.0 (Macintosh; My New User-Agent)"}}' --as-links https://linkedin.com|)
expect(http.scan(/User-Agent: Typhoeus/).count).to(eq(0))
expect(http.scan("User-Agent: Typhoeus").count).to(eq(0))
expect(http.scan(%r{User-Agent: Mozilla/5.0 \(Macintosh; My New User-Agent\)}i).count).to(eq(2))
end

it "supports hydra" do
http = make_bin(%(--hydra '{"max_concurrency": 5}' http://www.github.com --as-links))
expect(http.scan(/max_concurrency is invalid/).count).to(eq(0))
expect(http.scan(/successfully/).count).to(eq(1))
expect(http.scan("max_concurrency is invalid").count).to(eq(0))
expect(http.scan("successfully").count).to(eq(1))
end
end

Expand All @@ -231,7 +231,7 @@
new_time = Time.local(2022, 1, 6, 12, 0, 0)
Timecop.freeze(new_time) do
http = make_bin(%(--cache '{"timeframe": { "external": "1d"}}' http://www.github.com --as-links))
expect(http.scan(/successfully/).count).to(eq(1))
expect(http.scan("successfully").count).to(eq(1))
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "spec_helper"
require "html-proofer"

describe HTMLProofer::Configuration do
describe Configuration do
it "Throws an error when the option name is not a string" do
expect do
described_class.new.parse_json_option(
Expand Down
2 changes: 1 addition & 1 deletion spec/html-proofer/element_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

describe HTMLProofer::Element do
describe Element do
let(:runner) { HTMLProofer::Runner.new("") }

describe "#initialize" do
Expand Down
2 changes: 1 addition & 1 deletion spec/html-proofer/maliciousness_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

describe "Maliciousness test" do # rubocop:disable RSpec/DescribeClass
describe Maliciousness do
it "does not accept non-string input for single file" do
expect do
run_proofer(23, :file)
Expand Down
2 changes: 1 addition & 1 deletion spec/html-proofer/proofer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

describe HTMLProofer do
describe Proofer do
describe "#failed_checks" do
it "is an array of Failures" do
broken_link_internal_filepath = File.join(FIXTURES_DIR, "links", "broken_link_internal.html")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

describe HTMLProofer::Reporter::Terminal do
describe Reporter::Terminal do
describe "report" do
it "reports all issues accurately" do
error_file = File.join(FIXTURES_DIR, "sorting", "kitchen_sinkish.html")
Expand Down
2 changes: 1 addition & 1 deletion spec/html-proofer/reporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def report
end
end

describe HTMLProofer::Reporter do
describe Reporter do
it "supports a custom reporter" do
file = File.join(FIXTURES_DIR, "sorting", "kitchen_sinkish.html")
cassette_name = make_cassette_name(file, {})
Expand Down
2 changes: 1 addition & 1 deletion spec/html-proofer/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

describe HTMLProofer::Runner do
describe Runner do
describe "#before_request" do
it "sends authorization header to github.com" do
opts = {}
Expand Down
2 changes: 1 addition & 1 deletion spec/html-proofer/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

describe HTMLProofer::Utils do
describe Utils do
describe "::create_nokogiri" do
include described_class

Expand Down

0 comments on commit c69b32d

Please sign in to comment.