Skip to content

Commit fa8646c

Browse files
committed
Refactor to remove rubocop:disable comments
1 parent 7807990 commit fa8646c

47 files changed

Lines changed: 1282 additions & 1106 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.rubocop.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ plugins:
44
- rubocop-minitest
55

66
inherit_from:
7-
- .rubocop_todo.yml
87
- .rubocop/layout.yml
98
- .rubocop/metrics.yml
109
- .rubocop/minitest.yml
@@ -15,3 +14,9 @@ AllCops:
1514
DisplayStyleGuide: true
1615
NewCops: enable
1716
TargetRubyVersion: 3.0
17+
18+
# Feature has no initialize, so super() is a no-op in subclasses
19+
Lint/MissingSuper:
20+
AllowedParentClasses:
21+
- BasicObject
22+
- Feature

.rubocop/metrics.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Metrics/AbcSize:
2+
Exclude:
3+
- 'test/support/**/*.rb'
4+
15
Metrics/BlockLength:
26
CountAsOne:
37
- array
@@ -18,6 +22,8 @@ Metrics/MethodLength:
1822
- array
1923
- heredoc
2024
- method_call
25+
Exclude:
26+
- 'test/support/**/*.rb'
2127

2228
Metrics/ModuleLength:
2329
CountAsOne:

.rubocop/style.yml

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,46 @@
1-
Style/Documentation:
2-
Enabled: false
3-
4-
# Hash[] is used instead of {} to satisfy Steep strict mode (UnannotatedEmptyCollection)
5-
Style/EmptyLiteral:
6-
Exclude:
7-
- 'lib/http/options.rb'
8-
9-
Style/HashConversion:
10-
Exclude:
11-
- 'lib/http/options.rb'
12-
13-
Style/OneClassPerFile:
14-
Exclude:
15-
- 'test/**/*.rb'
1+
Style/AccessorGrouping:
2+
Enabled: true
3+
EnforcedStyle: separated
164

175
Style/DocumentDynamicEvalDefinition:
186
Enabled: true
197
Exclude:
208
- 'test/**/*.rb'
219

10+
# Hash[] is used instead of {} to satisfy Steep strict mode (UnannotatedEmptyCollection)
11+
Style/EmptyLiteral:
12+
Exclude:
13+
- 'lib/http/options.rb'
14+
- 'lib/http/options/definitions.rb'
15+
2216
Style/FormatStringToken:
2317
Enabled: true
2418
EnforcedStyle: unannotated
2519

20+
Style/HashConversion:
21+
Exclude:
22+
- 'lib/http/options.rb'
23+
- 'lib/http/options/definitions.rb'
24+
2625
Style/HashSyntax:
2726
Enabled: true
2827
EnforcedStyle: ruby19_no_mixed_keys
2928

29+
Style/OneClassPerFile:
30+
Exclude:
31+
- 'test/**/*.rb'
32+
33+
# Configuration parameters: SuspiciousParamNames, Allowlist.
34+
# SuspiciousParamNames: options, opts, args, params, parameters
3035
Style/OptionHash:
3136
Enabled: true
37+
Exclude:
38+
- 'lib/http/chainable.rb'
39+
- 'lib/http/client.rb'
40+
- 'lib/http/options.rb'
41+
- 'lib/http/redirector.rb'
42+
- 'lib/http/timeout/null.rb'
43+
- 'test/support/dummy_server.rb'
3244

3345
# Using explicit `./` makes code more consistent
3446
Style/RedundantCurrentDirectoryInPath:

.rubocop_todo.yml

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

Rakefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,19 @@ task :steep do
3030
exit Steep::CLI.new(argv: ["check", "--log-level=fatal"], stdout: $stdout, stderr: $stderr, stdin: $stdin).run
3131
end
3232

33+
desc "Generate HTTP status codes from IANA registry"
3334
task :generate_status_codes do
3435
require "http"
3536
require "nokogiri"
3637

3738
url = "http://www.iana.org/assignments/http-status-codes/http-status-codes.xml"
3839
xml = Nokogiri::XML HTTP.get url
40+
excluded_descriptions = %w[Unassigned (Unused)]
3941
arr = xml.xpath("//xmlns:record").reduce([]) do |a, e|
4042
code = e.xpath("xmlns:value").text.to_s
4143
desc = e.xpath("xmlns:description").text.to_s
4244

43-
next a if %w[Unassigned (Unused)].include?(desc)
45+
next a if excluded_descriptions.include?(desc)
4446

4547
a << "#{code} => #{desc.inspect}"
4648
end

http.gemspec

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ Gem::Specification.new do |spec|
3232
end
3333
end
3434

35-
spec.bindir = "exe"
36-
spec.executables = spec.files.filter_map { |f| File.basename(f) if f.start_with?("exe/") }
37-
spec.test_files = spec.files.select { |f| f.start_with?("test/") }
3835
spec.require_paths = ["lib"]
3936

4037
spec.required_ruby_version = ">= 3.0"

lib/http/chainable.rb

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require "http/base64"
4+
require "http/chainable/helpers"
45
require "http/headers"
56

67
module HTTP
@@ -169,15 +170,12 @@ def timeout(options)
169170
when Numeric then [HTTP::Timeout::Global, { global: options }]
170171
when Hash then [HTTP::Timeout::PerOperation, options.dup]
171172
when :null then [HTTP::Timeout::Null, {}]
172-
else raise ArgumentError, "Use `.timeout(global_timeout_in_seconds)` or `.timeout(connect: x, write: y, read: z)`."
173-
173+
else raise ArgumentError,
174+
"Use `.timeout(global_timeout_in_seconds)` " \
175+
"or `.timeout(connect: x, write: y, read: z)`."
174176
end
175177

176-
%i[global read write connect].each do |k|
177-
next unless options.key? k
178-
179-
options[:"#{k}_timeout"] = options.delete k
180-
end
178+
normalize_timeout_keys!(options)
181179

182180
branch default_options.merge(
183181
timeout_class: klass,
@@ -223,8 +221,7 @@ def timeout(options)
223221
# @return [HTTP::Client, Object]
224222
# @api public
225223
def persistent(host, timeout: 5)
226-
options = { keep_alive_timeout: timeout }
227-
p_client = branch default_options.merge(options).with_persistent host
224+
p_client = branch default_options.merge(keep_alive_timeout: timeout).with_persistent(host)
228225
return p_client unless block_given?
229226

230227
yield p_client
@@ -242,13 +239,7 @@ def persistent(host, timeout: 5)
242239
# @return [HTTP::Client]
243240
# @api public
244241
def via(*proxy)
245-
proxy_hash = {} #: Hash[Symbol, untyped]
246-
proxy_hash[:proxy_address] = proxy[0] if proxy[0].is_a?(String)
247-
proxy_hash[:proxy_port] = proxy[1] if proxy[1].is_a?(Integer)
248-
proxy_hash[:proxy_username] = proxy[2] if proxy[2].is_a?(String)
249-
proxy_hash[:proxy_password] = proxy[3] if proxy[3].is_a?(String)
250-
proxy_hash[:proxy_headers] = proxy[2] if proxy[2].is_a?(Hash)
251-
proxy_hash[:proxy_headers] = proxy[4] if proxy[4].is_a?(Hash)
242+
proxy_hash = build_proxy_hash(proxy)
252243

253244
raise(RequestError, "invalid HTTP proxy: #{proxy_hash}") unless (2..5).cover?(proxy_hash.keys.size)
254245

lib/http/chainable/helpers.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# frozen_string_literal: true
2+
3+
module HTTP
4+
module Chainable
5+
# Mapping of proxy argument positions to hash keys and expected types
6+
PROXY_ARG_MAP = [
7+
[:proxy_address, 0, String],
8+
[:proxy_port, 1, Integer],
9+
[:proxy_username, 2, String],
10+
[:proxy_password, 3, String],
11+
[:proxy_headers, 2, Hash],
12+
[:proxy_headers, 4, Hash]
13+
].freeze
14+
15+
private
16+
17+
# Build proxy configuration hash from positional arguments
18+
#
19+
# @param [Array] proxy positional proxy arguments
20+
# @return [Hash] proxy configuration
21+
# @api private
22+
def build_proxy_hash(proxy)
23+
result = {} #: Hash[Symbol, untyped]
24+
PROXY_ARG_MAP.each do |key, index, type|
25+
result[key] = proxy[index] if proxy[index].is_a?(type)
26+
end
27+
result
28+
end
29+
30+
# Normalize timeout option keys to include _timeout suffix
31+
#
32+
# @param [Hash] options timeout options to normalize
33+
# @return [void]
34+
# @api private
35+
def normalize_timeout_keys!(options)
36+
%i[global read write connect].each do |k|
37+
next unless options.key? k
38+
39+
options[:"#{k}_timeout"] = options.delete k
40+
end
41+
end
42+
end
43+
end

0 commit comments

Comments
 (0)