Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V5 #759

Merged
merged 18 commits into from
Oct 8, 2022
Merged

V5 #759

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name: Ruby CI

on:
pull_request:
push:
branches:
- main

permissions:
contents: read
Expand All @@ -16,9 +19,7 @@ jobs:
fail-fast: true
matrix:
ruby-version:
- 3.1.0
- 3.0.0
- 2.7.6
- 3.1
experimental: [false]
include:
- ruby-version: head
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ name: Linting

on:
pull_request:
types: [opened, synchronize, reopened]
push:
branches:
- main

permissions:
contents: read
Expand All @@ -17,7 +13,7 @@ jobs:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0
ruby-version: 3.1
bundler-cache: true
- run: bundle install
- name: Rubocop
Expand Down
18 changes: 18 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,23 @@ inherit_gem:
rubocop-standard:
- config/default.yml

require:
- rubocop-rspec

Naming/FileName:
Enabled: false

RSpec/AnyInstance:
Enabled: false

RSpec/ExampleLength:
Enabled: false

RSpec/FilePath:
Enabled: false

RSpec/MultipleExpectations:
Enabled: false

RSpec/MultipleMemoizedHelpers:
Enabled: false
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
source "https://rubygems.org"

gemspec

gem "ruby-lsp", "~> 0.3.2", group: :development
25 changes: 5 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,18 @@ HTMLProofer.check_links(['https://github.com', 'https://jekyllrb.com']).run
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:

```ruby
run_proofer(file, :file, swap_urls: { %r{^https//example.com}: 'https://website.com' })
run_proofer(file, :file, swap_urls: { %r{^https//placeholder.com}: 'https://website.com' })
```

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

A similar swapping process can be done for attributes:

```ruby
run_proofer(file, :file, swap_attributes: { 'img': [['src', 'data-src']] })
run_proofer(file, :file, swap_attributes: { 'img': [['data-src', 'src']] })
```

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.
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.

### Using on the command-line

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

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

#### Special cases for the command-line

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

* `:typhoeus` / `:hydra`
* `:parallel`
* `:cache`

### Configuring Typhoeus and Hydra
Expand Down Expand Up @@ -339,20 +338,6 @@ proofer.run

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.

### Configuring Parallel

[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:

``` ruby
HTMLProofer.check_directories(["out/"], {extension: ".htm", parallel: { in_processes: 3} })
```

In this example, `in_processes: 3` is passed into Parallel as a configuration option.

Pass in `parallel: { enable: false }` to disable parallel runs.

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.

## Configuring caching

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.
Expand Down
114 changes: 114 additions & 0 deletions bin/bundle
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'bundle' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "rubygems"

m = Module.new do
module_function

def invoked_as_script?
File.expand_path($0) == File.expand_path(__FILE__)
end

def env_var_version
ENV["BUNDLER_VERSION"]
end

def cli_arg_version
return unless invoked_as_script? # don't want to hijack other binstubs
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
bundler_version = nil
update_index = nil
ARGV.each_with_index do |a, i|
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
bundler_version = a
end
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
bundler_version = $1
update_index = i
end
bundler_version
end

def gemfile
gemfile = ENV["BUNDLE_GEMFILE"]
return gemfile if gemfile && !gemfile.empty?

File.expand_path("../Gemfile", __dir__)
end

def lockfile
lockfile =
case File.basename(gemfile)
when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
else "#{gemfile}.lock"
end
File.expand_path(lockfile)
end

def lockfile_version
return unless File.file?(lockfile)
lockfile_contents = File.read(lockfile)
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
Regexp.last_match(1)
end

def bundler_requirement
@bundler_requirement ||=
env_var_version || cli_arg_version ||
bundler_requirement_for(lockfile_version)
end

def bundler_requirement_for(version)
return "#{Gem::Requirement.default}.a" unless version

bundler_gem_version = Gem::Version.new(version)

requirement = bundler_gem_version.approximate_recommendation

return requirement unless Gem.rubygems_version < Gem::Version.new("2.7.0")

requirement += ".a" if bundler_gem_version.prerelease?

requirement
end

def load_bundler!
ENV["BUNDLE_GEMFILE"] ||= gemfile

activate_bundler
end

def activate_bundler
gem_error = activation_error_handling do
gem "bundler", bundler_requirement
end
return if gem_error.nil?
require_error = activation_error_handling do
require "bundler/version"
end
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
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}'`"
exit 42
end

def activation_error_handling
yield
nil
rescue StandardError, LoadError => e
e
end
end

m.load_bundler!

if m.invoked_as_script?
load Gem.bin_path("bundler", "bundle")
end
102 changes: 0 additions & 102 deletions bin/htmlproofer

This file was deleted.

17 changes: 17 additions & 0 deletions exe/htmlproofer
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

$stdout.sync = true

$LOAD_PATH.unshift("#{__dir__}/../lib")

require "html-proofer"
require "benchmark"

exit_status = -1
cli = HTMLProofer::CLI.new

time = Benchmark.realtime { exit_status = cli.run }

puts "Finished in #{time.round(2)} seconds"
exit exit_status
Loading