Skip to content

Commit

Permalink
Merge pull request #14 from naokikimura/upgrade_rubocop
Browse files Browse the repository at this point in the history
Upgrade RuboCop
  • Loading branch information
naokikimura committed Feb 28, 2021
2 parents 29ff607 + 90dd5b5 commit 209443f
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rubocop-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

# This step is not necessary if you add the gem to your Gemfile
- name: Install Code Scanning integration
run: bundle add code-scanning-rubocop --version 0.3.0 --skip-install
run: bundle add code-scanning-rubocop --skip-install

- name: Install dependencies
run: bundle install
Expand Down
4 changes: 3 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
AllCops:
NewCops: enable
Exclude:
- bin/*
- pkg/*
Expand All @@ -8,6 +9,7 @@ AllCops:
- Gemfile
- '*.gemspec'
- Rakefile
- .simplecov

Metrics/BlockLength:
Exclude:
Expand All @@ -16,7 +18,7 @@ Metrics/BlockLength:
Metrics/CyclomaticComplexity:
Max: 7

Metrics/LineLength:
Layout/LineLength:
Max: 110

Metrics/MethodLength:
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
# Specify your gem's dependencies in phc_string_format.gemspec
gemspec

gem "rubocop", "~> 0.58.2", require: false, :groups => [:development, :test]
gem "rubocop", "~> 1.7", require: false, :groups => [:development, :test]
gem "reek", "~> 5.0", require: false, :groups => [:development, :test]
gem 'simplecov', '>= 0.16.1', require: false, group: :test
gem 'codacy-coverage', '>= 1.1.8', require: false, group: :test
19 changes: 11 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ GEM
docile (1.3.5)
equalizer (0.0.11)
ice_nine (0.11.2)
jaro_winkler (1.5.4)
kwalify (0.7.2)
method_source (1.0.0)
parallel (1.20.1)
parser (2.7.2.0)
ast (~> 2.4.1)
powerpack (0.1.3)
pry (0.13.1)
coderay (~> 1.1)
method_source (~> 1.0)
Expand All @@ -47,6 +45,8 @@ GEM
parser (>= 2.5.0.0, < 2.8, != 2.5.1.1)
psych (~> 3.1.0)
rainbow (>= 2.0, < 4.0)
regexp_parser (2.1.1)
rexml (3.2.4)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
Expand All @@ -60,14 +60,17 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
rubocop (0.58.2)
jaro_winkler (~> 1.5.1)
rubocop (1.7.0)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
powerpack (~> 0.1)
parser (>= 2.7.1.5)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.2.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (1.4.1)
parser (>= 2.7.1.5)
ruby-progressbar (1.11.0)
simplecov (0.21.2)
docile (~> 1.1)
Expand All @@ -94,7 +97,7 @@ DEPENDENCIES
rake (~> 13.0)
reek (~> 5.0)
rspec (~> 3.0)
rubocop (~> 0.58.2)
rubocop (~> 1.7)
simplecov (>= 0.16.1)

BUNDLED WITH
Expand Down
2 changes: 2 additions & 0 deletions lib/phc_string_format.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'phc_string_format/b64'
require 'phc_string_format/version'
require 'phc_string_format/validations'
Expand Down
4 changes: 4 additions & 0 deletions lib/phc_string_format/b64.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'base64'

module PhcStringFormat
Expand All @@ -10,11 +12,13 @@ module PhcStringFormat
module B64
def self.encode(bin)
return nil unless bin

Base64.strict_encode64(bin).delete('=')
end

def self.decode(bin)
return nil unless bin

Base64.strict_decode64(bin + '=' * (-bin.size % 4))
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/phc_string_format/formatter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module PhcStringFormat
#
# Formatter for stringifying and parsing PHC-string-format.
Expand Down
14 changes: 9 additions & 5 deletions lib/phc_string_format/phc_string.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module PhcStringFormat
#
# Parser for parsing PHC-string-format.
Expand All @@ -8,8 +10,8 @@ class PhcString
def self.parse(string)
string ||= ''
PhcString.new(*split(string))
rescue StandardError => exception
raise ParseError, exception.message
rescue StandardError => e
raise ParseError, e.message
end

# :reek:DuplicateMethodCall { allow_calls: ['elements.shift', 'elements.first'] }
Expand Down Expand Up @@ -66,15 +68,16 @@ def initialize(id, version_string, params_string, encoded_salt, encoded_hash)
end

def to_s
'$' + [
"$#{[
@id,
@version_string,
@params_string,
@encoded_salt,
@encoded_hash
].compact.join('$')
].compact.join('$')}"
end

# rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
def to_h(pick: nil, hint: {})
pick ||= %i[id version params salt hash]
{
Expand All @@ -88,6 +91,7 @@ def to_h(pick: nil, hint: {})
hash: (B64.decode(@encoded_hash) if pick.include?(:hash))
}.select { |_, value| value }
end
# rubocop:enable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity

def ==(other)
instance_variable_values = other.instance_variables.map { |name| other.instance_variable_get(name) }
Expand Down Expand Up @@ -116,7 +120,7 @@ def self.to_s(params)

def self.to_h(params_string)
params_string ||= ''
params_string
params_string # rubocop:disable Style/HashTransformValues
.split(/,/)
.map { |param| param.split '=' }
.map { |name, value| [name, value =~ /\A-?\d+(.\d+)?\Z/ ? value.to_i : value] }
Expand Down
4 changes: 4 additions & 0 deletions lib/phc_string_format/validations.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module PhcStringFormat
#
# Provides a validation framework to your objects.
Expand All @@ -6,6 +8,7 @@ module Validations
def self.included(klass)
klass.extend ClassMethods
end

#
# class methods
#
Expand All @@ -15,6 +18,7 @@ def validates(name, **options)
@validators << lambda { |object|
value = object.instance_variable_get(name)
return if options[:allow_nil] && !value

regex = options.dig(:format, :with)
raise ArgumentError, options[:message] unless !regex || value =~ regex
}
Expand Down
2 changes: 2 additions & 0 deletions lib/phc_string_format/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module PhcStringFormat
VERSION = "0.3.8"
end
2 changes: 2 additions & 0 deletions spec/phc_string_format/b64_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'pry'

RSpec.describe PhcStringFormat::B64 do
Expand Down
2 changes: 2 additions & 0 deletions spec/phc_string_format/formatter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'pry'

RSpec.describe PhcStringFormat::Formatter do
Expand Down
2 changes: 2 additions & 0 deletions spec/phc_string_format/phc_string_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'pry'

RSpec.describe PhcStringFormat::PhcString do
Expand Down
2 changes: 2 additions & 0 deletions spec/phc_string_format_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'pry'

RSpec.describe PhcStringFormat do
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "bundler/setup"
require "simplecov"

Expand Down

0 comments on commit 209443f

Please sign in to comment.