Skip to content

Commit c5f053b

Browse files
committed
Enforce parentheses on method calls with arguments
Style/MethodCallWithArgsParentheses is off by default, so the codebase had drifted: JWT.encode payload, nil, alg next to JWT.encode(payload, nil, alg), with the paren-less form concentrated in the older specs. The RSpec matcher DSL is exempted, so expect(x).to eq(y) keeps reading the way it is meant to rather than becoming expect(x).to(eq(y)). The diff is rubocop -a output apart from five arrays in readme_examples_spec, where adding parens pushed the elements out to a 36 column hanging indent; those are collapsed onto one line instead. Switching Layout/FirstArrayElementIndentation to consistent would have been the other way to fix them, but that restyles 14 places to fix 5.
1 parent 4a576f8 commit c5f053b

44 files changed

Lines changed: 300 additions & 304 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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,14 @@ Gemspec/DevelopmentDependencies:
2525

2626
Naming/PredicateMethod:
2727
Enabled: false
28+
29+
Style/MethodCallWithArgsParentheses:
30+
Enabled: true
31+
AllowedMethods:
32+
- to
33+
- not_to
34+
- to_not
35+
- describe
36+
- context
37+
- it
38+
- specify

lib/jwt/base64.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def url_decode(str)
2020
rescue ArgumentError => e
2121
raise unless e.message == 'invalid base64'
2222

23-
raise Base64DecodeError, 'Invalid base64 encoding'
23+
raise(Base64DecodeError, 'Invalid base64 encoding')
2424
end
2525
end
2626
end

lib/jwt/claims/audience.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def initialize(expected_audience:)
1919
# @return [nil]
2020
def verify!(context:, **_args)
2121
aud = context.payload['aud']
22-
raise JWT::InvalidAudError, "Invalid audience. Expected #{expected_audience}, received #{aud || '<none>'}" if ([*aud] & [*expected_audience]).empty?
22+
raise(JWT::InvalidAudError, "Invalid audience. Expected #{expected_audience}, received #{aud || '<none>'}") if ([*aud] & [*expected_audience]).empty?
2323
end
2424

2525
private

lib/jwt/claims/expiration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def verify!(context:, **_args)
2121
return unless context.payload.is_a?(Hash)
2222
return unless context.payload.key?('exp')
2323

24-
raise JWT::ExpiredSignature, 'Signature has expired' if context.payload['exp'].to_i <= (Time.now.to_i - leeway)
24+
raise(JWT::ExpiredSignature, 'Signature has expired') if context.payload['exp'].to_i <= (Time.now.to_i - leeway)
2525
end
2626

2727
private

lib/jwt/claims/issuer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def verify!(context:, **_args)
2222
when *issuers
2323
nil
2424
else
25-
raise JWT::InvalidIssuerError, "Invalid issuer. Expected #{issuers}, received #{iss || '<none>'}"
25+
raise(JWT::InvalidIssuerError, "Invalid issuer. Expected #{issuers}, received #{iss || '<none>'}")
2626
end
2727
end
2828

lib/jwt/claims/not_before.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def verify!(context:, **_args)
2121
return unless context.payload.is_a?(Hash)
2222
return unless context.payload.key?('nbf')
2323

24-
raise JWT::ImmatureSignature, 'Signature nbf has not been reached' if context.payload['nbf'].to_i > (Time.now.to_i + leeway)
24+
raise(JWT::ImmatureSignature, 'Signature nbf has not been reached') if context.payload['nbf'].to_i > (Time.now.to_i + leeway)
2525
end
2626

2727
private

lib/jwt/claims/numeric.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def validate_is_numeric(payload, claim)
3838

3939
return if payload[claim].is_a?(::Numeric) || payload[claim.to_s].is_a?(::Numeric)
4040

41-
raise InvalidPayload, "#{claim} claim must be a Numeric value but it is a #{(payload[claim] || payload[claim.to_s]).class}"
41+
raise(InvalidPayload, "#{claim} claim must be a Numeric value but it is a #{(payload[claim] || payload[claim.to_s]).class}")
4242
end
4343
end
4444
end

lib/jwt/claims/required.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def verify!(context:, **_args)
2121
required_claims.each do |required_claim|
2222
next if context.payload.is_a?(Hash) && context.payload.key?(required_claim)
2323

24-
raise JWT::MissingRequiredClaim, "Missing required claim #{required_claim}"
24+
raise(JWT::MissingRequiredClaim, "Missing required claim #{required_claim}")
2525
end
2626
end
2727

lib/jwt/claims/verifier.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def iterate_verifiers(*options)
5454
end
5555

5656
def verify_one!(context, verifier, options)
57-
verifier_builder = VERIFIERS.fetch(verifier) { raise ArgumentError, "#{verifier} not a valid claim verifier" }
57+
verifier_builder = VERIFIERS.fetch(verifier) { raise(ArgumentError, "#{verifier} not a valid claim verifier") }
5858
verifier_builder.call(options || {}).verify!(context: context)
5959
end
6060
end

lib/jwt/configuration/container.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def reset!
4242
# @raise [ArgumentError] if the value is not one of the supported values.
4343
# @return [void]
4444
def deprecation_warnings=(value)
45-
raise ArgumentError, "Invalid deprecation_warnings value #{value}. Supported values: #{DEPRECATION_WARNINGS_VALUES}" unless DEPRECATION_WARNINGS_VALUES.include?(value)
45+
raise(ArgumentError, "Invalid deprecation_warnings value #{value}. Supported values: #{DEPRECATION_WARNINGS_VALUES}") unless DEPRECATION_WARNINGS_VALUES.include?(value)
4646

4747
@deprecation_warnings = value
4848
end

0 commit comments

Comments
 (0)