html-proofer 3.17.0 → 3.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b5a47189e872130e01a2080e6e8ddb1f7f22520098deaf941960194d2338b2b
4
- data.tar.gz: 3543c42860956427e8c828861f76e1c5cd984d79054c091c6e5f97e0352b3137
3
+ metadata.gz: 010dde5e6758227f807cb7b17095b68df2d987ff4911c7c1e5f8876cff2f5bf2
4
+ data.tar.gz: 7925b79c6e1431c175aab35c1181ffa8127b1051427a5810411bacfe61c1ae27
5
5
  SHA512:
6
- metadata.gz: 1defd1fb2ee651015231b0ed4d1407ed56e25a907e0602ee9e175b23f3b88938e020f438d2171ceea8d52bc58984901543c97184a3da13c9b08cdaf62200a4aa
7
- data.tar.gz: 97eb6120db724822830398a85f14faa4415638e965d21aef0703991e7a14d335f32df65d72bb877be6f0706f24154deea3f08a6bbeb2cdf5d7c392d03ce2af23
6
+ metadata.gz: 794d63f91e2fd22e5e5dba8a1b1032ec0c85b5fbe4e4db991f02cef6c205ac777f0dc9ea611378fe1702ee57c2fb917d4a1d95f02e10dda402df6d451d6cbd54
7
+ data.tar.gz: 3bf224c6ed71160031e95d3258401a314d8a480b069a5c6c9d555a163f288d1128eac3f76decd3033b2d32d98ed89f65b37bfeef696fd475a2d2b8749aa097da
@@ -50,7 +50,7 @@ Mercenary.program(:htmlproofer) do |p|
50
50
  p.option 'typhoeus_config', '--typhoeus-config CONFIG', String, 'JSON-formatted string of Typhoeus config. Will override the html-proofer defaults.'
51
51
  p.option 'url_ignore', '--url-ignore link1,[link2,...]', Array, 'A comma-separated list of Strings or RegExps containing URLs that are safe to ignore. It affects all HTML attributes. Note that non-HTTP(S) URIs are always ignored'
52
52
  p.option 'url_swap', '--url-swap re:string,[re:string,...]', Array, 'A comma-separated list containing key-value pairs of `RegExp => String`. It transforms URLs that match `RegExp` into `String` via `gsub`. The escape sequences `\\:` should be used to produce literal `:`s.'
53
- p.option 'root_dir', '--root-folder PATH', String, 'The absolute path to the directory serving your html-files. Used when running html-proofer on a file, rather than a directory.'
53
+ p.option 'root_dir', '--root-dir PATH', String, 'The absolute path to the directory serving your html-files.'
54
54
 
55
55
  p.action do |args, opts|
56
56
  args = ['.'] if args.empty?
@@ -1,3 +1,4 @@
1
+ # rubocop:disable Naming/FileName
1
2
  # frozen_string_literal: true
2
3
 
3
4
  def require_all(path)
@@ -52,3 +53,4 @@ module HTMLProofer
52
53
  HTMLProofer::Runner.new(links, options)
53
54
  end
54
55
  end
56
+ # rubocop:enable Naming/FileName
@@ -26,8 +26,8 @@ module HTMLProofer
26
26
  raise NotImplementedError, 'HTMLProofer::Check subclasses must implement #run'
27
27
  end
28
28
 
29
- def add_issue(desc, line: nil, status: -1, content: nil)
30
- @issues << Issue.new(@path, desc, line: line, status: status, content: content)
29
+ def add_issue(desc, line: nil, path: nil, status: -1, content: nil)
30
+ @issues << Issue.new(path || @path, desc, line: line, status: status, content: content)
31
31
  false
32
32
  end
33
33
 
@@ -7,7 +7,7 @@ class FaviconCheck < ::HTMLProofer::Check
7
7
  favicon = create_element(node)
8
8
  next if favicon.ignore?
9
9
 
10
- found = true if favicon.rel.split(' ').last.eql? 'icon'
10
+ found = true if favicon.rel.split.last.eql? 'icon'
11
11
  break if found
12
12
  end
13
13
 
@@ -65,15 +65,15 @@ class LinkCheck < ::HTMLProofer::Check
65
65
  external_urls
66
66
  end
67
67
 
68
- def check_internal_link(link, line, content)
68
+ def check_internal_link(link, path, line, content)
69
69
  # does the local directory have a trailing slash?
70
70
  if link.unslashed_directory?(link.absolute_path)
71
- add_issue("internally linking to a directory #{link.absolute_path} without trailing slash", line: line, content: content)
71
+ add_issue("internally linking to a directory #{link.absolute_path} without trailing slash", path: path, line: line, content: content)
72
72
  return false
73
73
  end
74
74
 
75
75
  # verify the target hash
76
- return handle_hash(link, line, content) if link.hash
76
+ return handle_hash(link, path, line, content) if link.hash
77
77
 
78
78
  true
79
79
  end
@@ -103,9 +103,9 @@ class LinkCheck < ::HTMLProofer::Check
103
103
  add_issue("#{link.href} contains no phone number", line: line, content: content) if link.path.empty?
104
104
  end
105
105
 
106
- def handle_hash(link, line, content)
106
+ def handle_hash(link, path, line, content)
107
107
  if link.internal? && !hash_exists?(link.html, link.hash) # rubocop:disable Style/GuardClause
108
- return add_issue("linking to internal hash ##{link.hash} that does not exist", line: line, content: content)
108
+ return add_issue("linking to internal hash ##{link.hash} that does not exist", path: path, line: line, content: content)
109
109
  elsif link.external?
110
110
  return external_link_check(link, line, content)
111
111
  end
@@ -169,6 +169,10 @@ module HTMLProofer
169
169
  url.start_with?('?')
170
170
  end
171
171
 
172
+ def absolute_path?(path)
173
+ path.start_with?('/')
174
+ end
175
+
172
176
  def file_path
173
177
  return if path.nil? || path.empty?
174
178
 
@@ -176,22 +180,19 @@ module HTMLProofer
176
180
 
177
181
  path_dot_ext = path + @check.options[:extension] if @check.options[:assume_extension]
178
182
 
179
- if %r{^/}.match?(path) # path relative to root
180
- if File.directory?(@check.src)
181
- base = @check.src
182
- else
183
- root_dir = @check.options[:root_dir]
184
- base = root_dir || File.dirname(@check.src)
185
- end
186
- elsif File.exist?(File.expand_path(path, @check.src)) || File.exist?(File.expand_path(path_dot_ext, @check.src)) # relative links, path is a file
187
- base = File.dirname @check.path
188
- elsif File.exist?(File.join(File.dirname(@check.path), path)) || File.exist?(File.join(File.dirname(@check.path), path_dot_ext)) # rubocop:disable Lint/DuplicateBranch; relative links in nested dir, path is a file
189
- base = File.dirname @check.path
190
- else # relative link, path is a directory
191
- base = @check.path
192
- end
183
+ base = if absolute_path?(path) # path relative to root
184
+ # either overwrite with root_dir; or, if source is directory, use that; or, just get the current file's dirname
185
+ @check.options[:root_dir] || (File.directory?(@check.src) ? @check.src : File.dirname(@check.src))
186
+ elsif File.exist?(File.expand_path(path, @check.src)) || File.exist?(File.expand_path(path_dot_ext, @check.src)) # relative links, path is a file
187
+ File.dirname(@check.path)
188
+ elsif File.exist?(File.join(File.dirname(@check.path), path)) || File.exist?(File.join(File.dirname(@check.path), path_dot_ext)) # rubocop:disable Lint/DuplicateBranch; relative links in nested dir, path is a file
189
+ File.dirname(@check.path)
190
+ else # relative link, path is a directory
191
+ @check.path
192
+ end
193
+
194
+ file = File.join(base, path)
193
195
 
194
- file = File.join base, path
195
196
  if @check.options[:assume_extension] && File.file?("#{file}#{@check.options[:extension]}")
196
197
  file = "#{file}#{@check.options[:extension]}"
197
198
  elsif File.directory?(file) && !unslashed_directory?(file) # implicit index support
@@ -203,14 +204,15 @@ module HTMLProofer
203
204
 
204
205
  # checks if a file exists relative to the current pwd
205
206
  def exists?
206
- return @checked_paths[absolute_path] if @checked_paths.key? absolute_path
207
+ return @checked_paths[absolute_path] if @checked_paths.key?(absolute_path)
207
208
 
208
- @checked_paths[absolute_path] = File.exist? absolute_path
209
+ @checked_paths[absolute_path] = File.exist?(absolute_path)
209
210
  end
210
211
 
211
212
  def absolute_path
212
213
  path = file_path || @check.path
213
- File.expand_path path, Dir.pwd
214
+
215
+ File.expand_path(path, Dir.pwd)
214
216
  end
215
217
 
216
218
  def ignores_pattern_check(links)
@@ -60,7 +60,7 @@ module HTMLProofer
60
60
  body = []
61
61
  result.last.each { |e| body << e }
62
62
 
63
- body = body.join('')
63
+ body = body.join
64
64
  begin
65
65
  html = body.lstrip
66
66
  rescue StandardError
@@ -147,14 +147,17 @@ module HTMLProofer
147
147
  urls_to_check = load_internal_cache
148
148
 
149
149
  urls_to_check.each_pair do |url, internal_urls|
150
- result = @internal_link_checks.check_internal_link(internal_urls.first.link, internal_urls.first.line, internal_urls.first.content)
150
+ # pulled from cache
151
+ internal_urls = @internal_urls[url] unless internal_urls.first.is_a?(LinkCheck::InternalLink)
152
+
153
+ result = @internal_link_checks.check_internal_link(internal_urls.first.link, internal_urls.first.path, internal_urls.first.line, internal_urls.first.content)
151
154
  code = result ? 200 : 404
152
155
  @cache.add(url, @internal_urls_to_paths[url].sort, code, '') # TODO: blank msg for now
153
156
  end
154
157
  @cache.write
155
158
  else
156
159
  @internal_urls.values.flatten.each do |internal_url|
157
- @internal_link_checks.check_internal_link(internal_url.link, internal_url.line, internal_url.content)
160
+ @internal_link_checks.check_internal_link(internal_url.link, internal_url.path, internal_url.line, internal_url.content)
158
161
  end
159
162
  end
160
163
 
@@ -211,7 +214,8 @@ module HTMLProofer
211
214
  sorted_failures.sort_and_report
212
215
  count = @failures.length
213
216
  failure_text = pluralize(count, 'failure', 'failures')
214
- raise @logger.colorize :fatal, "HTML-Proofer found #{failure_text}!"
217
+ @logger.log :fatal, "\nHTML-Proofer found #{failure_text}!"
218
+ exit 1
215
219
  end
216
220
 
217
221
  # Set before_request callback.
@@ -226,7 +230,7 @@ module HTMLProofer
226
230
  # @return [ Array<Block> ] All before_request blocks.
227
231
  def before_request(&block)
228
232
  @before_request ||= []
229
- @before_request << block if block_given?
233
+ @before_request << block if block
230
234
  @before_request
231
235
  end
232
236
 
@@ -120,7 +120,7 @@ module HTMLProofer
120
120
  def clean_url(href)
121
121
  # catch any obvious issues, like strings in port numbers
122
122
  parsed = Addressable::URI.parse(href)
123
- if href =~ /^([!#{$&}-;=?-\[\]_a-z~]|%[0-9a-fA-F]{2})+$/
123
+ if href =~ /^([!#{Regexp.last_match(0)}-;=?-\[\]_a-z~]|%[0-9a-fA-F]{2})+$/
124
124
  href
125
125
  else
126
126
  parsed.normalize
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTMLProofer
4
- VERSION = '3.17.0'
4
+ VERSION = '3.18.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html-proofer
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.17.0
4
+ version: 3.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-14 00:00:00.000000000 Z
11
+ date: 2020-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -122,20 +122,6 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: codecov
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
125
  - !ruby/object:Gem::Dependency
140
126
  name: pry-byebug
141
127
  requirement: !ruby/object:Gem::Requirement
@@ -308,7 +294,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
308
294
  - !ruby/object:Gem::Version
309
295
  version: '0'
310
296
  requirements: []
311
- rubygems_version: 3.1.2
297
+ rubygems_version: 3.1.4
312
298
  signing_key:
313
299
  specification_version: 4
314
300
  summary: A set of tests to validate your HTML output. These tests check if your image