Skip to content

Commit ca02d8a

Browse files
authored
Merge pull request #759 from gjtorikian/v5
V5
2 parents 6f8a324 + 55ba14b commit ca02d8a

File tree

38 files changed

+1987
-579
lines changed

38 files changed

+1987
-579
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
name: Ruby CI
22

33
on:
4+
pull_request:
45
push:
6+
branches:
7+
- main
58

69
permissions:
710
contents: read
@@ -16,9 +19,7 @@ jobs:
1619
fail-fast: true
1720
matrix:
1821
ruby-version:
19-
- 3.1.0
20-
- 3.0.0
21-
- 2.7.6
22+
- 3.1
2223
experimental: [false]
2324
include:
2425
- ruby-version: head

.github/workflows/lint.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ name: Linting
22

33
on:
44
pull_request:
5-
types: [opened, synchronize, reopened]
6-
push:
7-
branches:
8-
- main
95

106
permissions:
117
contents: read
@@ -17,7 +13,7 @@ jobs:
1713
- uses: actions/checkout@v3
1814
- uses: ruby/setup-ruby@v1
1915
with:
20-
ruby-version: 3.0
16+
ruby-version: 3.1
2117
bundler-cache: true
2218
- run: bundle install
2319
- name: Rubocop

.rubocop.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,23 @@ inherit_gem:
22
rubocop-standard:
33
- config/default.yml
44

5+
require:
6+
- rubocop-rspec
7+
58
Naming/FileName:
69
Enabled: false
10+
11+
RSpec/AnyInstance:
12+
Enabled: false
13+
14+
RSpec/ExampleLength:
15+
Enabled: false
16+
17+
RSpec/FilePath:
18+
Enabled: false
19+
20+
RSpec/MultipleExpectations:
21+
Enabled: false
22+
23+
RSpec/MultipleMemoizedHelpers:
24+
Enabled: false

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
source "https://rubygems.org"
44

55
gemspec
6+
7+
gem "ruby-lsp", "~> 0.3.2", group: :development

README.md

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,18 @@ HTMLProofer.check_links(['https://github.com', 'https://jekyllrb.com']).run
149149
Sometimes, the information in your HTML is not the same as how your server serves content. In these cases, you can use `swap_urls` to map the URL in a file to the URL you'd like it to become. For example:
150150

151151
```ruby
152-
run_proofer(file, :file, swap_urls: { %r{^https//example.com}: 'https://website.com' })
152+
run_proofer(file, :file, swap_urls: { %r{^https//placeholder.com}: 'https://website.com' })
153153
```
154154

155-
In this case, any link that matches the `^https://example.com` will be converted to `https://website.com`.
155+
In this case, any link that matches the `^https://placeholder.com` will be converted to `https://website.com`.
156156

157157
A similar swapping process can be done for attributes:
158158

159159
```ruby
160-
run_proofer(file, :file, swap_attributes: { 'img': [['src', 'data-src']] })
160+
run_proofer(file, :file, swap_attributes: { 'img': [['data-src', 'src']] })
161161
```
162162

163-
In this case, we are telling HTMLProofer that, for any `img` tag detected, and for any check using the `src` attribute, to use the `data-src` attribute instead. Since the value is an array of arrays, you can pass in as many attribute swaps as you need.
163+
In this case, we are telling HTMLProofer that, for any `img` tag detected, for any `src` attribute, pretend it's actually the `src` attribute instead. Since the value is an array of arrays, you can pass in as many attribute swaps as you need for each element.
164164

165165
### Using on the command-line
166166

@@ -172,7 +172,7 @@ Pass in options through the command-line as flags, like this:
172172
htmlproofer --extensions .html.erb ./out
173173
```
174174

175-
Use `htmlproofer --help` to see all command line options, or [take a peek here](https://github.com/gjtorikian/html-proofer/blob/main/bin/htmlproofer).
175+
Use `htmlproofer --help` to see all command line options.
176176

177177
#### Special cases for the command-line
178178

@@ -294,7 +294,6 @@ The `HTMLProofer` constructor takes an optional hash of additional options:
294294
In addition, there are a few "namespaced" options. These are:
295295

296296
* `:typhoeus` / `:hydra`
297-
* `:parallel`
298297
* `:cache`
299298

300299
### Configuring Typhoeus and Hydra
@@ -339,20 +338,6 @@ proofer.run
339338

340339
The `Authorization` header is being set if and only if the `base_url` is `https://github.com`, and it is excluded for all other URLs.
341340

342-
### Configuring Parallel
343-
344-
[Parallel](https://github.com/grosser/parallel) is used to speed internal file checks. You can pass in any of its options with the options namespace `:parallel`. For example:
345-
346-
``` ruby
347-
HTMLProofer.check_directories(["out/"], {extension: ".htm", parallel: { in_processes: 3} })
348-
```
349-
350-
In this example, `in_processes: 3` is passed into Parallel as a configuration option.
351-
352-
Pass in `parallel: { enable: false }` to disable parallel runs.
353-
354-
On the CLI, you can provide the `--parallel` argument to set the configuration. This is parsed using `JSON.parse` and mapped on top of the default configuration values so that they can be overridden.
355-
356341
## Configuring caching
357342

358343
Checking external URLs can slow your tests down. If you'd like to speed that up, you can enable caching for your external and internal links. Caching simply means to skip link checking for links that are valid for a certain period of time.

bin/bundle

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
#
5+
# This file was generated by Bundler.
6+
#
7+
# The application 'bundle' is installed as part of a gem, and
8+
# this file is here to facilitate running it.
9+
#
10+
11+
require "rubygems"
12+
13+
m = Module.new do
14+
module_function
15+
16+
def invoked_as_script?
17+
File.expand_path($0) == File.expand_path(__FILE__)
18+
end
19+
20+
def env_var_version
21+
ENV["BUNDLER_VERSION"]
22+
end
23+
24+
def cli_arg_version
25+
return unless invoked_as_script? # don't want to hijack other binstubs
26+
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
27+
bundler_version = nil
28+
update_index = nil
29+
ARGV.each_with_index do |a, i|
30+
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
31+
bundler_version = a
32+
end
33+
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
34+
bundler_version = $1
35+
update_index = i
36+
end
37+
bundler_version
38+
end
39+
40+
def gemfile
41+
gemfile = ENV["BUNDLE_GEMFILE"]
42+
return gemfile if gemfile && !gemfile.empty?
43+
44+
File.expand_path("../Gemfile", __dir__)
45+
end
46+
47+
def lockfile
48+
lockfile =
49+
case File.basename(gemfile)
50+
when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
51+
else "#{gemfile}.lock"
52+
end
53+
File.expand_path(lockfile)
54+
end
55+
56+
def lockfile_version
57+
return unless File.file?(lockfile)
58+
lockfile_contents = File.read(lockfile)
59+
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
60+
Regexp.last_match(1)
61+
end
62+
63+
def bundler_requirement
64+
@bundler_requirement ||=
65+
env_var_version || cli_arg_version ||
66+
bundler_requirement_for(lockfile_version)
67+
end
68+
69+
def bundler_requirement_for(version)
70+
return "#{Gem::Requirement.default}.a" unless version
71+
72+
bundler_gem_version = Gem::Version.new(version)
73+
74+
requirement = bundler_gem_version.approximate_recommendation
75+
76+
return requirement unless Gem.rubygems_version < Gem::Version.new("2.7.0")
77+
78+
requirement += ".a" if bundler_gem_version.prerelease?
79+
80+
requirement
81+
end
82+
83+
def load_bundler!
84+
ENV["BUNDLE_GEMFILE"] ||= gemfile
85+
86+
activate_bundler
87+
end
88+
89+
def activate_bundler
90+
gem_error = activation_error_handling do
91+
gem "bundler", bundler_requirement
92+
end
93+
return if gem_error.nil?
94+
require_error = activation_error_handling do
95+
require "bundler/version"
96+
end
97+
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
98+
warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
99+
exit 42
100+
end
101+
102+
def activation_error_handling
103+
yield
104+
nil
105+
rescue StandardError, LoadError => e
106+
e
107+
end
108+
end
109+
110+
m.load_bundler!
111+
112+
if m.invoked_as_script?
113+
load Gem.bin_path("bundler", "bundle")
114+
end

bin/htmlproofer

Lines changed: 0 additions & 102 deletions
This file was deleted.

exe/htmlproofer

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
$stdout.sync = true
5+
6+
$LOAD_PATH.unshift("#{__dir__}/../lib")
7+
8+
require "html-proofer"
9+
require "benchmark"
10+
11+
exit_status = -1
12+
cli = HTMLProofer::CLI.new
13+
14+
time = Benchmark.realtime { exit_status = cli.run }
15+
16+
puts "Finished in #{time.round(2)} seconds"
17+
exit exit_status

0 commit comments

Comments
 (0)