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

Fixes with latest RuboCop #459

Merged
merged 4 commits into from
Dec 28, 2021
Merged
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
23 changes: 3 additions & 20 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,9 @@ AllCops:
TargetRubyVersion: 2.6
NewCops: enable
SuggestExtensions: false

Gemspec/RequiredRubyVersion:
Enabled: false

Layout/ParameterAlignment:
EnforcedStyle: with_fixed_indentation

Layout/CaseIndentation:
EnforcedStyle: end

Style/AsciiComments:
Enabled: false

Layout/FirstHashElementIndentation:
Enabled: false

Style/CollectionMethods:
Enabled: true
PreferredMethods:
inject: 'inject'
Exclude:
- 'gemfiles/*.gemfile'
- 'vendor/**/*'

Style/Documentation:
Enabled: false
Expand Down
156 changes: 0 additions & 156 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include.
# Include: **/*.gemfile, **/Gemfile, **/gems.rb
Bundler/OrderedGems:
Exclude:
- 'gemfiles/openssl.gemfile'
- 'gemfiles/rbnacl.gemfile'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: Include.
Expand All @@ -35,21 +26,6 @@ Layout/EmptyLineAfterGuardClause:
- 'lib/jwt/jwk/rsa.rb'
- 'lib/jwt/verify.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, no_empty_lines
Layout/EmptyLinesAroundBlockBody:
Exclude:
- 'spec/jwt_spec.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
Layout/ExtraSpacing:
Exclude:
- 'spec/jwk_spec.rb'

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
Expand All @@ -60,79 +36,11 @@ Layout/HashAlignment:
Exclude:
- 'lib/jwt/algos/ecdsa.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: normal, indented_internal_methods
Layout/IndentationConsistency:
Exclude:
- 'spec/jwt_spec.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: Width, IgnoredPatterns.
Layout/IndentationWidth:
Exclude:
- 'spec/jwt_spec.rb'

# Offense count: 3
# Cop supports --auto-correct.
Layout/SpaceAfterComma:
Exclude:
- 'spec/jwt_spec.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
# SupportedStyles: space, no_space
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceBeforeBlockBraces:
Exclude:
- 'spec/jwk/ec_spec.rb'
- 'spec/jwt/verify_spec.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
# SupportedStyles: space, no_space
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceInsideBlockBraces:
Exclude:
- 'spec/jwt/verify_spec.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: final_newline, final_blank_line
Layout/TrailingEmptyLines:
Exclude:
- 'bin/console.rb'

# Offense count: 1
# Cop supports --auto-correct.
Lint/AmbiguousOperatorPrecedence:
Exclude:
- 'spec/integration/readme_examples_spec.rb'

# Offense count: 1
# Configuration parameters: AllowComments, AllowEmptyLambdas.
Lint/EmptyBlock:
Exclude:
- 'Appraisals'

# Offense count: 1
Lint/MissingSuper:
Exclude:
- 'lib/jwt/jwk/key_base.rb'

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
Lint/UnusedBlockArgument:
Exclude:
- 'spec/jwk/decode_with_jwk_spec.rb'
- 'spec/jwk/ec_spec.rb'
- 'spec/jwt/verify_spec.rb'

# Offense count: 1
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
Expand All @@ -147,12 +55,6 @@ Style/ClassEqualityComparison:
Exclude:
- 'lib/jwt/algos/rsa.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/Encoding:
Exclude:
- 'lib/jwt/version.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/ExpandPathArguments:
Expand All @@ -169,9 +71,6 @@ Style/FrozenStringLiteralComment:
- 'Gemfile'
- 'Rakefile'
- 'bin/console.rb'
- 'gemfiles/openssl.gemfile'
- 'gemfiles/rbnacl.gemfile'
- 'gemfiles/standalone.gemfile'
- 'lib/jwt/algos/ecdsa.rb'
- 'lib/jwt/algos/eddsa.rb'
- 'lib/jwt/algos/hmac.rb'
Expand All @@ -183,7 +82,6 @@ Style/FrozenStringLiteralComment:
- 'lib/jwt/default_options.rb'
- 'lib/jwt/security_utils.rb'
- 'ruby-jwt.gemspec'
- 'spec/jwt/algos/ecdsa_spec.rb'

# Offense count: 2
# Cop supports --auto-correct.
Expand All @@ -192,20 +90,6 @@ Style/HashTransformKeys:
- 'lib/jwt/claims_validator.rb'
- 'lib/jwt/encode.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: InverseMethods, InverseBlocks.
Style/InverseMethods:
Exclude:
- 'spec/jwk/ec_spec.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: IgnoredMethods.
Style/MethodCallWithoutArgsParentheses:
Exclude:
- 'spec/jwt_spec.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, Autocorrect.
Expand All @@ -227,12 +111,6 @@ Style/OptionalBooleanParameter:
Exclude:
- 'lib/jwt.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/ParallelAssignment:
Exclude:
- 'spec/integration/readme_examples_spec.rb'

# Offense count: 5
# Cop supports --auto-correct.
Style/RedundantFreeze:
Expand All @@ -242,12 +120,6 @@ Style/RedundantFreeze:
- 'lib/jwt/jwk/hmac.rb'
- 'lib/jwt/jwk/rsa.rb'

# Offense count: 4
# Cop supports --auto-correct.
Style/RedundantRegexpEscape:
Exclude:
- 'spec/jwk/decode_with_jwk_spec.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods.
Expand All @@ -262,31 +134,3 @@ Style/SlicingWithRange:
Exclude:
- 'lib/jwt/security_utils.rb'

# Offense count: 27
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Exclude:
- 'bin/console.rb'
- 'gemfiles/openssl.gemfile'
- 'gemfiles/rbnacl.gemfile'
- 'gemfiles/standalone.gemfile'
- 'spec/jwk/ec_spec.rb'
- 'spec/jwk/rsa_spec.rb'
- 'spec/jwk_spec.rb'
- 'spec/jwt_spec.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleForMultiline.
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
Style/TrailingCommaInArguments:
Exclude:
- 'spec/jwt_spec.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/UnlessElse:
Exclude:
- 'spec/jwt_spec.rb'
1 change: 1 addition & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
appraise 'standalone' do
# No additions
end

appraise 'openssl' do
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ source 'https://rubygems.org'

gemspec

gem 'rubocop', '~> 1.23.0' # Same as codeclimate default
gem 'rubocop', '~> 1.23.0' # Keep .codeclimate.yml channel in sync with this one
7 changes: 3 additions & 4 deletions bin/console.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "jwt"
require 'bundler/setup'
require 'jwt'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand All @@ -10,6 +10,5 @@
# require "pry"
# Pry.start

require "irb"
require 'irb'
IRB.start(__FILE__)

2 changes: 1 addition & 1 deletion gemfiles/openssl.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source "https://rubygems.org"

gem "rubocop", "~> 0.52.0"
gem "rubocop", "~> 1.23.0"
gem "openssl", "~> 2.1"

gemspec path: "../"
2 changes: 1 addition & 1 deletion gemfiles/rbnacl.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source "https://rubygems.org"

gem "rubocop", "~> 0.52.0"
gem "rubocop", "~> 1.23.0"
gem "rbnacl"

gemspec path: "../"
2 changes: 1 addition & 1 deletion gemfiles/standalone.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

source "https://rubygems.org"

gem "rubocop", "~> 0.52.0"
gem "rubocop", "~> 1.23.0"

gemspec path: "../"
1 change: 0 additions & 1 deletion lib/jwt/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# encoding: utf-8
# frozen_string_literal: true

# Moments version builder module
Expand Down
5 changes: 3 additions & 2 deletions spec/integration/readme_examples_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@

context 'exp' do
it 'without leeway' do
exp = Time.now.to_i + 4 * 3600
exp = Time.now.to_i + (4 * 3600)
exp_payload = { data: 'data', exp: exp }

token = JWT.encode exp_payload, hmac_secret, 'HS256'
Expand Down Expand Up @@ -260,7 +260,8 @@

it 'JWK' do
jwk = JWT::JWK.new(OpenSSL::PKey::RSA.new(2048))
payload, headers = { data: 'data' }, { kid: jwk.kid }
payload = { data: 'data' }
headers = { kid: jwk.kid }

token = JWT.encode(payload, jwk.keypair, 'RS512', headers)

Expand Down
6 changes: 3 additions & 3 deletions spec/jwk/decode_with_jwk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

context 'when jwk keys are loaded from JSON with string keys' do
it 'decodes the token' do
key_loader = ->(options) { JSON.parse(JSON.generate(public_jwks)) }
key_loader = ->(_options) { JSON.parse(JSON.generate(public_jwks)) }
payload, _header = described_class.decode(signed_token, nil, true, { algorithms: ['RS512'], jwks: key_loader})
expect(payload).to eq(token_payload)
end
Expand Down Expand Up @@ -137,7 +137,7 @@

it 'fails in some way' do
expect { described_class.decode(signed_token, nil, true, algorithms: ['RS512'], jwks: jwks) }.to(
raise_error(NoMethodError, /undefined method `verify' for \"secret\":String/)
raise_error(NoMethodError, /undefined method `verify' for "secret":String/)
)
end
end
Expand All @@ -147,7 +147,7 @@

it 'fails in some way' do
expect { described_class.decode(signed_token, nil, true, algorithms: ['ES384'], jwks: jwks) }.to(
raise_error(NoMethodError, /undefined method `group' for \"secret\":String/)
raise_error(NoMethodError, /undefined method `group' for "secret":String/)
)
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/jwk/ec_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

RSpec.describe JWT::JWK::EC do
let(:ec_key) { OpenSSL::PKey::EC.new("secp384r1").generate_key }
let(:ec_key) { OpenSSL::PKey::EC.new('secp384r1').generate_key }

describe '.new' do
subject { described_class.new(keypair) }
Expand Down Expand Up @@ -91,7 +91,7 @@
expect(subject).to be_a described_class

# Regular export returns only the non-private parts.
public_only = exported_key.select{ |k, v| k != :d }
public_only = exported_key.reject { |k, _v| k == :d }
expect(subject.export).to eq(public_only)

# Private export returns the original input.
Expand Down
4 changes: 2 additions & 2 deletions spec/jwk/rsa_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@
end

context 'when jwk_data is given without e and/or n' do
let(:params) { { kty: "RSA" } }
let(:params) { { kty: 'RSA' } }
it 'raises an error' do
expect { subject }.to raise_error(JWT::JWKError, "Key format is invalid for RSA")
expect { subject }.to raise_error(JWT::JWKError, 'Key format is invalid for RSA')
end
end
end
Expand Down
Loading