Skip to content

Commit a9517ac

Browse files
committed
Fix some simple cops
1 parent d238d7f commit a9517ac

File tree

10 files changed

+40
-29
lines changed

10 files changed

+40
-29
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Layout/FirstHashElementIndentation:
1818
Layout/EndAlignment:
1919
EnforcedStyleAlignWith: variable
2020

21+
Layout/HashAlignment:
22+
EnforcedHashRocketStyle: table
23+
2124
Style/TrailingCommaInArguments:
2225
EnforcedStyleForMultiline: consistent_comma
2326

Gemfile

Lines changed: 5 additions & 5 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

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

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)

spec/mysql2/statement_spec.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require './spec/spec_helper.rb'
1+
require './spec/spec_helper'
22

33
RSpec.describe Mysql2::Statement do
44
before(:example) do
@@ -277,7 +277,7 @@ def stmt_count
277277
end
278278

279279
context "#each" do
280-
# note: The current impl. of prepared statement requires results to be cached on #execute except for streaming queries
280+
# NOTE: The current impl. of prepared statement requires results to be cached on #execute except for streaming queries
281281
# The drawback of this is that args of Result#each is ignored...
282282

283283
it "should yield rows as hash's" do
@@ -320,7 +320,7 @@ def stmt_count
320320
result = @client.prepare("SELECT 1 UNION SELECT 2").execute(stream: true, cache_rows: false)
321321
expect do
322322
result.each {}
323-
result.each {}
323+
result.each {} # rubocop:disable Style/CombinableLoops
324324
end.to raise_exception(Mysql2::Error)
325325
end
326326
end
@@ -573,17 +573,17 @@ def stmt_count
573573
end
574574

575575
{
576-
'char_test' => 'CHAR',
577-
'varchar_test' => 'VARCHAR',
578-
'varbinary_test' => 'VARBINARY',
579-
'tiny_blob_test' => 'TINYBLOB',
580-
'tiny_text_test' => 'TINYTEXT',
581-
'blob_test' => 'BLOB',
582-
'text_test' => 'TEXT',
576+
'char_test' => 'CHAR',
577+
'varchar_test' => 'VARCHAR',
578+
'varbinary_test' => 'VARBINARY',
579+
'tiny_blob_test' => 'TINYBLOB',
580+
'tiny_text_test' => 'TINYTEXT',
581+
'blob_test' => 'BLOB',
582+
'text_test' => 'TEXT',
583583
'medium_blob_test' => 'MEDIUMBLOB',
584584
'medium_text_test' => 'MEDIUMTEXT',
585-
'long_blob_test' => 'LONGBLOB',
586-
'long_text_test' => 'LONGTEXT',
585+
'long_blob_test' => 'LONGBLOB',
586+
'long_text_test' => 'LONGTEXT',
587587
}.each do |field, type|
588588
it "should return a String for #{type}" do
589589
expect(test_result[field]).to be_an_instance_of(String)

spec/spec_helper.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def new_client(option_overrides = {})
3232
@clients ||= []
3333
@clients << client
3434
return client unless block_given?
35+
3536
begin
3637
yield client
3738
ensure
@@ -42,7 +43,7 @@ def new_client(option_overrides = {})
4243

4344
def num_classes
4445
# rubocop:disable Lint/UnifiedInteger
45-
0.class == Integer ? [Integer] : [Fixnum, Bignum]
46+
0.instance_of?(Integer) ? [Integer] : [Fixnum, Bignum]
4647
# rubocop:enable Lint/UnifiedInteger
4748
end
4849

support/mysql_enc_to_ruby.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
collations.each do |collation|
5656
mysql_col_idx = collation[2].to_i
5757
rb_enc = mysql_to_rb.fetch(collation[1]) do |mysql_enc|
58-
$stderr.puts "WARNING: Missing mapping for collation \"#{collation[0]}\" with encoding \"#{mysql_enc}\" and id #{mysql_col_idx}, assuming NULL"
58+
warn "WARNING: Missing mapping for collation \"#{collation[0]}\" with encoding \"#{mysql_enc}\" and id #{mysql_col_idx}, assuming NULL"
5959
"NULL"
6060
end
6161
encodings[mysql_col_idx - 1] = [mysql_col_idx, rb_enc]

0 commit comments

Comments
 (0)