Skip to content

Commit 259b7a6

Browse files
committed
style(standard): unsafe autocorrections
1 parent 9a9522d commit 259b7a6

File tree

6 files changed

+28
-24
lines changed

6 files changed

+28
-24
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ This release drops support for Ruby 2.7. [#453] @flavorjones
2020
- Moved some C code into Ruby. [#451, #455] @tenderlove
2121

2222

23+
### Changed
24+
25+
- Raise `StandardError` in a few places where `Exception` was previously raised.
26+
27+
2328
### Removed
2429

2530
- Remove `SQLite3::VersionProxy` which has been deprecated since v1.3.2. [#453] @flavorjones

lib/sqlite3/pragmas.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ def set_boolean_pragma(name, mode)
2222
when "on", "yes", "true", "y", "t" then mode = "'ON'"
2323
when "off", "no", "false", "n", "f" then mode = "'OFF'"
2424
else
25-
raise Exception,
25+
raise StandardError,
2626
"unrecognized pragma parameter #{mode.inspect}"
2727
end
2828
when true, 1
2929
mode = "ON"
3030
when false, 0, nil
3131
mode = "OFF"
3232
else
33-
raise Exception,
33+
raise StandardError,
3434
"unrecognized pragma parameter #{mode.inspect}"
3535
end
3636

@@ -62,7 +62,7 @@ def get_enum_pragma(name)
6262
def set_enum_pragma(name, mode, enums)
6363
match = enums.find { |p| p.find { |i| i.to_s.downcase == mode.to_s.downcase } }
6464
unless match
65-
raise Exception,
65+
raise StandardError,
6666
"unrecognized #{name} #{mode.inspect}"
6767
end
6868
execute("PRAGMA #{name}='#{match.first.upcase}'")
@@ -533,7 +533,7 @@ def table_info table
533533

534534
result = [] unless block_given?
535535
stmt.each do |row|
536-
new_row = Hash[columns.zip(row)]
536+
new_row = columns.zip(row).to_h
537537

538538
# FIXME: This should be removed but is required for older versions
539539
# of rails

lib/sqlite3/statement.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def execute(*bind_vars)
8181
bind_params(*bind_vars) unless bind_vars.empty?
8282
@results = ResultSet.new(@connection, self)
8383

84-
step if 0 == column_count
84+
step if column_count == 0
8585

8686
yield @results if block_given?
8787
@results
@@ -156,7 +156,7 @@ def get_metadata
156156
end
157157
@types = Array.new(column_count) do |column|
158158
val = column_decltype(column)
159-
val.nil? ? nil : val.downcase
159+
val&.downcase
160160
end
161161
end
162162
end

test/test_database.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_db_filename
2626
@db = SQLite3::Database.new tf.path
2727
assert_equal File.realdirpath(tf.path), File.realdirpath(@db.filename("main"))
2828
ensure
29-
tf.unlink if tf
29+
tf&.unlink
3030
end
3131

3232
def test_filename
@@ -36,7 +36,7 @@ def test_filename
3636
@db = SQLite3::Database.new tf.path
3737
assert_equal File.realdirpath(tf.path), File.realdirpath(@db.filename)
3838
ensure
39-
tf.unlink if tf
39+
tf&.unlink
4040
end
4141

4242
def test_filename_with_attachment
@@ -47,7 +47,7 @@ def test_filename_with_attachment
4747

4848
assert_equal File.realdirpath(tf.path), File.realdirpath(@db.filename("testing"))
4949
ensure
50-
tf.unlink if tf
50+
tf&.unlink
5151
end
5252

5353
def test_filename_to_path
@@ -56,8 +56,8 @@ def test_filename_to_path
5656
db = SQLite3::Database.new pn
5757
assert_equal pn.realdirpath.to_s, File.realdirpath(db.filename)
5858
ensure
59-
tf.close! if tf
60-
db.close if db
59+
tf&.close!
60+
db&.close
6161
end
6262

6363
def test_error_code
@@ -200,14 +200,14 @@ def test_new
200200
db = SQLite3::Database.new(":memory:")
201201
assert_instance_of(SQLite3::Database, db)
202202
ensure
203-
db.close if db
203+
db&.close
204204
end
205205

206206
def test_open
207207
db = SQLite3::Database.open(":memory:")
208208
assert_instance_of(SQLite3::Database, db)
209209
ensure
210-
db.close if db
210+
db&.close
211211
end
212212

213213
def test_open_returns_block_result
@@ -240,7 +240,7 @@ def test_new_with_options
240240
db = SQLite3::Database.new(":memory:".encode(utf16), utf16: true)
241241
assert_instance_of(SQLite3::Database, db)
242242
ensure
243-
db.close if db
243+
db&.close
244244
end
245245

246246
def test_close
@@ -296,7 +296,7 @@ def test_prepare
296296
stmt = db.prepare('select "hello world"')
297297
assert_instance_of(SQLite3::Statement, stmt)
298298
ensure
299-
stmt.close if stmt
299+
stmt&.close
300300
end
301301

302302
def test_block_prepare_does_not_double_close
@@ -543,7 +543,7 @@ def call action, a, b, c, d
543543
stmt = @db.prepare("select 'fooooo'")
544544
assert_nil stmt.step
545545
ensure
546-
stmt.close if stmt
546+
stmt&.close
547547
end
548548

549549
def test_authorizer_fail
@@ -570,7 +570,7 @@ def call action, a, b, c, d
570570
@db.authorizer = nil
571571
s = @db.prepare("select 'fooooo'")
572572
ensure
573-
s.close if s
573+
s&.close
574574
end
575575

576576
def test_close_with_open_statements
@@ -579,7 +579,7 @@ def test_close_with_open_statements
579579
@db.close
580580
end
581581
ensure
582-
s.close if s
582+
s&.close
583583
end
584584

585585
def test_execute_with_empty_bind_params
@@ -590,7 +590,7 @@ def test_query_with_named_bind_params
590590
resultset = @db.query("select :n", {"n" => "foo"})
591591
assert_equal [["foo"]], resultset.to_a
592592
ensure
593-
resultset.close if resultset
593+
resultset&.close
594594
end
595595

596596
def test_execute_with_named_bind_params
@@ -669,7 +669,7 @@ def test_default_transaction_mode
669669
db2.close if db2 && !db2.closed?
670670
end
671671
ensure
672-
tf.unlink if tf
672+
tf&.unlink
673673
end
674674
end
675675
end

test/test_integration_aggregate.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def test_create_aggregate_with_invalid_arity
174174
end
175175
end
176176

177-
class CustomException < Exception
177+
class CustomException < RuntimeError
178178
end
179179

180180
def test_create_aggregate_with_exception_in_step

test/test_integration_pending.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
require "helper"
22

3-
require "thread"
43
require "benchmark"
54

65
class TC_Integration_Pending < SQLite3::TestCase
@@ -30,7 +29,7 @@ def test_busy_handler_impatient
3029
busy.lock
3130
end
3231
ensure
33-
db2.close if db2
32+
db2&.close
3433
end
3534
sleep 1
3635

@@ -60,7 +59,7 @@ def test_busy_timeout
6059
busy.lock
6160
end
6261
ensure
63-
db2.close if db2
62+
db2&.close
6463
end
6564

6665
sleep 1

0 commit comments

Comments
 (0)