Skip to content

Commit 209443f

Browse files
authored
Merge pull request #14 from naokikimura/upgrade_rubocop
Upgrade RuboCop
2 parents 29ff607 + 90dd5b5 commit 209443f

15 files changed

Lines changed: 49 additions & 16 deletions

.github/workflows/rubocop-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222

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

2727
- name: Install dependencies
2828
run: bundle install

.rubocop.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
AllCops:
2+
NewCops: enable
23
Exclude:
34
- bin/*
45
- pkg/*
@@ -8,6 +9,7 @@ AllCops:
89
- Gemfile
910
- '*.gemspec'
1011
- Rakefile
12+
- .simplecov
1113

1214
Metrics/BlockLength:
1315
Exclude:
@@ -16,7 +18,7 @@ Metrics/BlockLength:
1618
Metrics/CyclomaticComplexity:
1719
Max: 7
1820

19-
Metrics/LineLength:
21+
Layout/LineLength:
2022
Max: 110
2123

2224
Metrics/MethodLength:

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
55
# Specify your gem's dependencies in phc_string_format.gemspec
66
gemspec
77

8-
gem "rubocop", "~> 0.58.2", require: false, :groups => [:development, :test]
8+
gem "rubocop", "~> 1.7", require: false, :groups => [:development, :test]
99
gem "reek", "~> 5.0", require: false, :groups => [:development, :test]
1010
gem 'simplecov', '>= 0.16.1', require: false, group: :test
1111
gem 'codacy-coverage', '>= 1.1.8', require: false, group: :test

Gemfile.lock

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ GEM
2525
docile (1.3.5)
2626
equalizer (0.0.11)
2727
ice_nine (0.11.2)
28-
jaro_winkler (1.5.4)
2928
kwalify (0.7.2)
3029
method_source (1.0.0)
3130
parallel (1.20.1)
3231
parser (2.7.2.0)
3332
ast (~> 2.4.1)
34-
powerpack (0.1.3)
3533
pry (0.13.1)
3634
coderay (~> 1.1)
3735
method_source (~> 1.0)
@@ -47,6 +45,8 @@ GEM
4745
parser (>= 2.5.0.0, < 2.8, != 2.5.1.1)
4846
psych (~> 3.1.0)
4947
rainbow (>= 2.0, < 4.0)
48+
regexp_parser (2.1.1)
49+
rexml (3.2.4)
5050
rspec (3.10.0)
5151
rspec-core (~> 3.10.0)
5252
rspec-expectations (~> 3.10.0)
@@ -60,14 +60,17 @@ GEM
6060
diff-lcs (>= 1.2.0, < 2.0)
6161
rspec-support (~> 3.10.0)
6262
rspec-support (3.10.2)
63-
rubocop (0.58.2)
64-
jaro_winkler (~> 1.5.1)
63+
rubocop (1.7.0)
6564
parallel (~> 1.10)
66-
parser (>= 2.5, != 2.5.1.1)
67-
powerpack (~> 0.1)
65+
parser (>= 2.7.1.5)
6866
rainbow (>= 2.2.2, < 4.0)
67+
regexp_parser (>= 1.8, < 3.0)
68+
rexml
69+
rubocop-ast (>= 1.2.0, < 2.0)
6970
ruby-progressbar (~> 1.7)
70-
unicode-display_width (~> 1.0, >= 1.0.1)
71+
unicode-display_width (>= 1.4.0, < 2.0)
72+
rubocop-ast (1.4.1)
73+
parser (>= 2.7.1.5)
7174
ruby-progressbar (1.11.0)
7275
simplecov (0.21.2)
7376
docile (~> 1.1)
@@ -94,7 +97,7 @@ DEPENDENCIES
9497
rake (~> 13.0)
9598
reek (~> 5.0)
9699
rspec (~> 3.0)
97-
rubocop (~> 0.58.2)
100+
rubocop (~> 1.7)
98101
simplecov (>= 0.16.1)
99102

100103
BUNDLED WITH

lib/phc_string_format.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'phc_string_format/b64'
24
require 'phc_string_format/version'
35
require 'phc_string_format/validations'

lib/phc_string_format/b64.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'base64'
24

35
module PhcStringFormat
@@ -10,11 +12,13 @@ module PhcStringFormat
1012
module B64
1113
def self.encode(bin)
1214
return nil unless bin
15+
1316
Base64.strict_encode64(bin).delete('=')
1417
end
1518

1619
def self.decode(bin)
1720
return nil unless bin
21+
1822
Base64.strict_decode64(bin + '=' * (-bin.size % 4))
1923
end
2024
end

lib/phc_string_format/formatter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module PhcStringFormat
24
#
35
# Formatter for stringifying and parsing PHC-string-format.

lib/phc_string_format/phc_string.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module PhcStringFormat
24
#
35
# Parser for parsing PHC-string-format.
@@ -8,8 +10,8 @@ class PhcString
810
def self.parse(string)
911
string ||= ''
1012
PhcString.new(*split(string))
11-
rescue StandardError => exception
12-
raise ParseError, exception.message
13+
rescue StandardError => e
14+
raise ParseError, e.message
1315
end
1416

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

6870
def to_s
69-
'$' + [
71+
"$#{[
7072
@id,
7173
@version_string,
7274
@params_string,
7375
@encoded_salt,
7476
@encoded_hash
75-
].compact.join('$')
77+
].compact.join('$')}"
7678
end
7779

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

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

117121
def self.to_h(params_string)
118122
params_string ||= ''
119-
params_string
123+
params_string # rubocop:disable Style/HashTransformValues
120124
.split(/,/)
121125
.map { |param| param.split '=' }
122126
.map { |name, value| [name, value =~ /\A-?\d+(.\d+)?\Z/ ? value.to_i : value] }

lib/phc_string_format/validations.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module PhcStringFormat
24
#
35
# Provides a validation framework to your objects.
@@ -6,6 +8,7 @@ module Validations
68
def self.included(klass)
79
klass.extend ClassMethods
810
end
11+
912
#
1013
# class methods
1114
#
@@ -15,6 +18,7 @@ def validates(name, **options)
1518
@validators << lambda { |object|
1619
value = object.instance_variable_get(name)
1720
return if options[:allow_nil] && !value
21+
1822
regex = options.dig(:format, :with)
1923
raise ArgumentError, options[:message] unless !regex || value =~ regex
2024
}

lib/phc_string_format/version.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module PhcStringFormat
24
VERSION = "0.3.8"
35
end

0 commit comments

Comments
 (0)