Skip to content

Commit 9d49828

Browse files
authored
Merge pull request brianmario#1268 from mishina2228/upgrade-rubocop
2 parents 80e0001 + aee1fcb commit 9d49828

File tree

13 files changed

+155
-70
lines changed

13 files changed

+155
-70
lines changed

.github/workflows/rubocop.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ jobs:
99
BUNDLE_WITHOUT: development
1010
steps:
1111
- uses: actions/checkout@v3
12-
- name: Set up Ruby 2.4
12+
- name: Set up Ruby 2.6
1313
uses: ruby/setup-ruby@v1
1414
with:
15-
ruby-version: 2.4
15+
ruby-version: 2.6
1616
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
1717
- name: Run RuboCop
1818
run: bundle exec rubocop

.rubocop.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ inherit_from: .rubocop_todo.yml
22

33
AllCops:
44
TargetRubyVersion: 2.0
5+
SuggestExtensions: false
6+
NewCops: disable
57

68
DisplayCopNames: true
79
Exclude:
@@ -12,16 +14,22 @@ AllCops:
1214
Layout/CaseIndentation:
1315
EnforcedStyle: end
1416

15-
Layout/IndentHash:
17+
Layout/FirstHashElementIndentation:
1618
EnforcedStyle: consistent
1719

18-
Lint/EndAlignment:
20+
Layout/EndAlignment:
1921
EnforcedStyleAlignWith: variable
2022

23+
Layout/HashAlignment:
24+
EnforcedHashRocketStyle: table
25+
2126
Style/TrailingCommaInArguments:
2227
EnforcedStyleForMultiline: consistent_comma
2328

24-
Style/TrailingCommaInLiteral:
29+
Style/TrailingCommaInArrayLiteral:
30+
EnforcedStyleForMultiline: consistent_comma
31+
32+
Style/TrailingCommaInHashLiteral:
2533
EnforcedStyleForMultiline: consistent_comma
2634

2735
Style/TrivialAccessors:

.rubocop_todo.yml

Lines changed: 103 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,166 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2017-11-25 19:54:28 -0500 using RuboCop version 0.50.0.
3+
# on 2022-05-30 13:48:55 UTC using RuboCop version 1.30.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

99
# Offense count: 3
10-
# Cop supports --auto-correct.
11-
# Configuration parameters: EnforcedStyle, SupportedStyles.
12-
# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
13-
Layout/IndentHeredoc:
10+
# This cop supports safe autocorrection (--autocorrect).
11+
Layout/HeredocIndentation:
1412
Exclude:
1513
- 'support/ruby_enc_to_mysql.rb'
1614
- 'tasks/compile.rake'
1715

1816
# Offense count: 2
17+
# Configuration parameters: AllowedMethods.
18+
# AllowedMethods: enums
19+
Lint/ConstantDefinitionInBlock:
20+
Exclude:
21+
- 'spec/mysql2/client_spec.rb'
22+
- 'tasks/rspec.rake'
23+
24+
# Offense count: 1
25+
Lint/MissingSuper:
26+
Exclude:
27+
- 'lib/mysql2/em.rb'
28+
29+
# Offense count: 2
30+
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
1931
Metrics/AbcSize:
20-
Max: 91
32+
Max: 94
2133

22-
# Offense count: 31
23-
# Configuration parameters: CountComments, ExcludedMethods.
34+
# Offense count: 34
35+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
36+
# IgnoredMethods: refine
2437
Metrics/BlockLength:
25-
Max: 860
38+
Max: 592
2639

2740
# Offense count: 1
2841
# Configuration parameters: CountBlocks.
2942
Metrics/BlockNesting:
3043
Max: 5
3144

3245
# Offense count: 1
33-
# Configuration parameters: CountComments.
46+
# Configuration parameters: CountComments, CountAsOne.
3447
Metrics/ClassLength:
3548
Max: 135
3649

3750
# Offense count: 3
51+
# Configuration parameters: IgnoredMethods.
3852
Metrics/CyclomaticComplexity:
39-
Max: 32
40-
41-
# Offense count: 313
42-
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
43-
# URISchemes: http, https
44-
Metrics/LineLength:
45-
Max: 232
53+
Max: 34
4654

4755
# Offense count: 6
48-
# Configuration parameters: CountComments.
56+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
4957
Metrics/MethodLength:
5058
Max: 57
5159

5260
# Offense count: 2
61+
# Configuration parameters: IgnoredMethods.
5362
Metrics/PerceivedComplexity:
54-
Max: 29
63+
Max: 32
5564

56-
# Offense count: 3
57-
# Configuration parameters: Blacklist.
58-
# Blacklist: END, (?-mix:EO[A-Z]{1})
65+
# Offense count: 2
66+
# Configuration parameters: ForbiddenDelimiters.
67+
# ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
5968
Naming/HeredocDelimiterNaming:
6069
Exclude:
6170
- 'tasks/compile.rake'
6271

63-
# Offense count: 10
72+
# Offense count: 1
73+
# This cop supports unsafe autocorrection (--autocorrect-all).
74+
Style/CaseLikeIf:
75+
Exclude:
76+
- 'ext/mysql2/extconf.rb'
77+
78+
# Offense count: 8
79+
# Configuration parameters: AllowedConstants.
6480
Style/Documentation:
6581
Exclude:
6682
- 'spec/**/*'
6783
- 'test/**/*'
6884
- 'benchmark/active_record.rb'
6985
- 'benchmark/allocations.rb'
70-
- 'benchmark/query_with_mysql_casting.rb'
7186
- 'lib/mysql2.rb'
7287
- 'lib/mysql2/client.rb'
7388
- 'lib/mysql2/em.rb'
7489
- 'lib/mysql2/error.rb'
75-
- 'lib/mysql2/result.rb'
7690
- 'lib/mysql2/statement.rb'
7791

78-
# Offense count: 14
92+
# Offense count: 6
93+
# This cop supports safe autocorrection (--autocorrect).
94+
Style/ExpandPathArguments:
95+
Exclude:
96+
- 'ext/mysql2/extconf.rb'
97+
- 'mysql2.gemspec'
98+
- 'spec/mysql2/client_spec.rb'
99+
- 'support/mysql_enc_to_ruby.rb'
100+
- 'tasks/compile.rake'
101+
102+
# Offense count: 15
79103
# Configuration parameters: AllowedVariables.
80104
Style/GlobalVars:
81105
Exclude:
82106
- 'ext/mysql2/extconf.rb'
83107

84-
# Offense count: 17
85-
# Cop supports --auto-correct.
86-
# Configuration parameters: Strict.
108+
# Offense count: 8
109+
# This cop supports safe autocorrection (--autocorrect).
110+
Style/IfUnlessModifier:
111+
Exclude:
112+
- 'lib/mysql2.rb'
113+
- 'lib/mysql2/client.rb'
114+
- 'spec/mysql2/client_spec.rb'
115+
116+
# Offense count: 1
117+
# This cop supports safe autocorrection (--autocorrect).
118+
# Configuration parameters: AllowMethodComparison.
119+
Style/MultipleComparison:
120+
Exclude:
121+
- 'lib/mysql2/client.rb'
122+
123+
# Offense count: 18
124+
# This cop supports safe autocorrection (--autocorrect).
125+
# Configuration parameters: Strict, AllowedNumbers.
87126
Style/NumericLiterals:
88127
MinDigits: 20
89128

90-
# Offense count: 726
91-
# Cop supports --auto-correct.
92-
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
129+
# Offense count: 14
130+
# This cop supports unsafe autocorrection (--autocorrect-all).
131+
# Configuration parameters: Mode.
132+
Style/StringConcatenation:
133+
Exclude:
134+
- 'benchmark/active_record.rb'
135+
- 'benchmark/active_record_threaded.rb'
136+
- 'benchmark/allocations.rb'
137+
- 'benchmark/escape.rb'
138+
- 'benchmark/query_with_mysql_casting.rb'
139+
- 'benchmark/query_without_mysql_casting.rb'
140+
- 'benchmark/sequel.rb'
141+
- 'benchmark/setup_db.rb'
142+
- 'ext/mysql2/extconf.rb'
143+
- 'lib/mysql2/client.rb'
144+
- 'tasks/compile.rake'
145+
146+
# Offense count: 782
147+
# This cop supports safe autocorrection (--autocorrect).
148+
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
93149
# SupportedStyles: single_quotes, double_quotes
94150
Style/StringLiterals:
95151
Enabled: false
152+
153+
# Offense count: 1
154+
# This cop supports safe autocorrection (--autocorrect).
155+
# Configuration parameters: WordRegex.
156+
# SupportedStyles: percent, brackets
157+
Style/WordArray:
158+
EnforcedStyle: percent
159+
MinSize: 4
160+
161+
# Offense count: 32
162+
# This cop supports safe autocorrection (--autocorrect).
163+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
164+
# URISchemes: http, https
165+
Layout/LineLength:
166+
Max: 232

Gemfile

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ source 'https://rubygems.org'
22

33
gemspec
44

5-
gem 'rake', if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.2")
6-
'~> 13.0.1'
7-
else
8-
'< 13'
9-
end
5+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.2")
6+
gem 'rake', '~> 13.0.1'
7+
else
8+
gem 'rake', '< 13'
9+
end
1010
gem 'rake-compiler', '~> 1.1.0'
1111

1212
# For local debugging, irb is Gemified since Ruby 2.6
@@ -16,10 +16,8 @@ group :test do
1616
gem 'eventmachine' unless RUBY_PLATFORM =~ /mswin|mingw/
1717
gem 'rspec', '~> 3.2'
1818

19-
# Downgrade psych because old RuboCop can't use new Psych
20-
gem 'psych', '< 4.0.0'
2119
# https://github.com/bbatsov/rubocop/pull/4789
22-
gem 'rubocop', '~> 0.50.0'
20+
gem 'rubocop', '~> 1.30', '>= 1.30.1' if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6')
2321
end
2422

2523
group :benchmarks, optional: true do

benchmark/allocations.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def bench_allocations(feature, iterations = 10, batch_size = 1000)
1616
GC::Profiler.clear
1717
GC::Profiler.enable
1818
iterations.times { yield batch_size }
19-
GC::Profiler.report(STDOUT)
19+
GC::Profiler.report($stdout)
2020
GC::Profiler.disable
2121
end
2222

ext/mysql2/extconf.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def add_ssl_defines(header)
181181
end
182182
end
183183

184-
unless disabled_sanitizers.empty?
184+
unless disabled_sanitizers.empty? # rubocop:disable Style/IfUnlessModifier
185185
abort "-----\nCould not enable requested sanitizers: #{disabled_sanitizers.join(',')}\n-----"
186186
end
187187

lib/mysql2.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ module Util
6565
#
6666
def self.key_hash_as_symbols(hash)
6767
return nil unless hash
68+
6869
Hash[hash.map { |k, v| [k.to_sym, v] }]
6970
end
7071

lib/mysql2/client.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def self.default_query_options
2020

2121
def initialize(opts = {})
2222
raise Mysql2::Error, "Options parameter must be a Hash" unless opts.is_a? Hash
23+
2324
opts = Mysql2::Util.key_hash_as_symbols(opts)
2425
@read_timeout = nil
2526
@query_options = self.class.default_query_options.dup
@@ -33,6 +34,7 @@ def initialize(opts = {})
3334
# TODO: stricter validation rather than silent massaging
3435
%i[reconnect connect_timeout local_infile read_timeout write_timeout default_file default_group secure_auth init_command automatic_close enable_cleartext_plugin default_auth].each do |key|
3536
next unless opts.key?(key)
37+
3638
case key
3739
when :reconnect, :local_infile, :secure_auth, :automatic_close, :enable_cleartext_plugin
3840
send(:"#{key}=", !!opts[key]) # rubocop:disable Style/DoubleNegation
@@ -136,6 +138,7 @@ def find_default_ca_path
136138
# and performance_schema.session_account_connect_attrs
137139
def parse_connect_attrs(conn_attrs)
138140
return {} if Mysql2::Client::CONNECT_ATTRS.zero?
141+
139142
conn_attrs ||= {}
140143
conn_attrs[:program_name] ||= $PROGRAM_NAME
141144
conn_attrs.each_with_object({}) do |(key, value), hash|
@@ -152,6 +155,7 @@ def query(sql, options = {})
152155
def query_info
153156
info = query_info_string
154157
return {} unless info
158+
155159
info_hash = {}
156160
info.split.each_slice(2) { |s| info_hash[s[0].downcase.delete(':').to_sym] = s[1].to_i }
157161
info_hash

spec/mysql2/client_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454

5555
Klient = Class.new(Mysql2::Client) do
5656
attr_reader :connect_args
57+
5758
def connect(*args)
5859
@connect_args ||= []
5960
@connect_args << args
@@ -212,6 +213,7 @@ def run_gc
212213
10.times do
213214
closed = @client.query("SHOW PROCESSLIST").none? { |row| row['Id'] == connection_id }
214215
break if closed
216+
215217
sleep(0.1)
216218
end
217219
expect(closed).to eq(true)

spec/mysql2/result_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -497,17 +497,17 @@
497497
end
498498

499499
{
500-
'char_test' => 'CHAR',
501-
'varchar_test' => 'VARCHAR',
502-
'varbinary_test' => 'VARBINARY',
503-
'tiny_blob_test' => 'TINYBLOB',
504-
'tiny_text_test' => 'TINYTEXT',
505-
'blob_test' => 'BLOB',
506-
'text_test' => 'TEXT',
500+
'char_test' => 'CHAR',
501+
'varchar_test' => 'VARCHAR',
502+
'varbinary_test' => 'VARBINARY',
503+
'tiny_blob_test' => 'TINYBLOB',
504+
'tiny_text_test' => 'TINYTEXT',
505+
'blob_test' => 'BLOB',
506+
'text_test' => 'TEXT',
507507
'medium_blob_test' => 'MEDIUMBLOB',
508508
'medium_text_test' => 'MEDIUMTEXT',
509-
'long_blob_test' => 'LONGBLOB',
510-
'long_text_test' => 'LONGTEXT',
509+
'long_blob_test' => 'LONGBLOB',
510+
'long_text_test' => 'LONGTEXT',
511511
}.each do |field, type|
512512
it "should return a String for #{type}" do
513513
expect(test_result[field]).to be_an_instance_of(String)

0 commit comments

Comments
 (0)