Skip to content

Commit f54bbc9

Browse files
authored
Merge pull request #467 from sparklemotion/flavorjones-standardrb-20240108
introduce standard formatting and linting
2 parents dfa2c8b + c88044d commit f54bbc9

40 files changed

+1279
-1109
lines changed

.rubocop.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# from https://evilmartians.com/chronicles/rubocoping-with-legacy-bring-your-ruby-code-up-to-standard
2+
require:
3+
- standard
4+
- standard-custom
5+
- standard-performance
6+
- rubocop-performance
7+
- rubocop-minitest
8+
9+
inherit_gem:
10+
standard: config/base.yml
11+
standard-custom: config/base.yml
12+
standard-performance: config/base.yml
13+
14+
AllCops:
15+
SuggestExtensions: false
16+
TargetRubyVersion: 3.0
17+
18+
Naming/InclusiveLanguage:
19+
Enabled: true
20+
21+
Minitest/AssertInDelta: # new in 0.10
22+
Enabled: true
23+
Minitest/AssertKindOf: # new in 0.10
24+
Enabled: true
25+
Minitest/AssertOperator: # new in 0.32
26+
Enabled: true
27+
Minitest/AssertOutput: # new in 0.10
28+
Enabled: true
29+
Minitest/AssertPathExists: # new in 0.10
30+
Enabled: true
31+
Minitest/AssertPredicate: # new in 0.18
32+
Enabled: true
33+
Minitest/AssertRaisesCompoundBody: # new in 0.21
34+
Enabled: true
35+
Minitest/AssertRaisesWithRegexpArgument: # new in 0.22
36+
Enabled: true
37+
Minitest/AssertSame: # new in 0.26
38+
Enabled: true
39+
Minitest/AssertSilent: # new in 0.10
40+
Enabled: true
41+
Minitest/AssertWithExpectedArgument: # new in 0.11
42+
Enabled: true
43+
Minitest/AssertionInLifecycleHook: # new in 0.10
44+
Enabled: true
45+
Minitest/DuplicateTestRun: # new in 0.19
46+
Enabled: true
47+
Minitest/EmptyLineBeforeAssertionMethods: # new in 0.23
48+
Enabled: false
49+
Minitest/LifecycleHooksOrder: # new in 0.28
50+
Enabled: true
51+
Minitest/LiteralAsActualArgument: # new in 0.10
52+
Enabled: true
53+
Minitest/MultipleAssertions: # new in 0.10
54+
Enabled: true
55+
Minitest/NonExecutableTestMethod: # new in 0.34
56+
Enabled: true
57+
Minitest/NonPublicTestMethod: # new in 0.27
58+
Enabled: true
59+
Minitest/RedundantMessageArgument: # new in 0.34
60+
Enabled: true
61+
Minitest/RefuteInDelta: # new in 0.10
62+
Enabled: true
63+
Minitest/RefuteKindOf: # new in 0.10
64+
Enabled: true
65+
Minitest/RefuteOperator: # new in 0.32
66+
Enabled: true
67+
Minitest/RefutePathExists: # new in 0.10
68+
Enabled: true
69+
Minitest/RefutePredicate: # new in 0.18
70+
Enabled: true
71+
Minitest/RefuteSame: # new in 0.26
72+
Enabled: true
73+
Minitest/ReturnInTestMethod: # new in 0.31
74+
Enabled: true
75+
Minitest/SkipEnsure: # new in 0.20
76+
Enabled: true
77+
Minitest/SkipWithoutReason: # new in 0.24
78+
Enabled: true
79+
Minitest/TestFileName: # new in 0.26
80+
Enabled: true
81+
Minitest/TestMethodName: # new in 0.10
82+
Enabled: true
83+
Minitest/UnreachableAssertion: # new in 0.14
84+
Enabled: true
85+
Minitest/UnspecifiedException: # new in 0.10
86+
Enabled: true
87+
Minitest/UselessAssertion: # new in 0.26
88+
Enabled: true

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

Gemfile

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@ source "https://rubygems.org"
22

33
gemspec
44

5-
gem("minitest", "5.20.0")
6-
gem("rake-compiler", "1.2.5")
7-
gem("rake-compiler-dock", "1.4.0")
8-
gem("rdoc", "6.6.2")
5+
group :development do
6+
gem "minitest", "5.20.0"
97

10-
gem("ruby_memcheck", "2.3.0") if Gem::Platform.local.os == "linux"
8+
gem "rake-compiler", "1.2.5"
9+
gem "rake-compiler-dock", "1.4.0"
10+
11+
gem "ruby_memcheck", "2.3.0" if Gem::Platform.local.os == "linux"
12+
13+
gem "rdoc", "6.6.2"
14+
15+
gem "rubocop", require: false
16+
gem "standardrb", require: false
17+
gem "rubocop-minitest", require: false
18+
end

Rakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
#
66
require "bundler"
77
SQLITE3_SPEC = Bundler.load_gemspec("sqlite3.gemspec")
8+
9+
task default: [:rubocop, :compile, :test]

bin/test-gem-file-contents

Lines changed: 88 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ gemfile_contents = Dir.mktmpdir do |dir|
3636
raise "could not unpack gem #{gemfile}"
3737
end
3838

39-
%x(tar -ztf data.tar.gz).split("\n")
39+
`tar -ztf data.tar.gz`.split("\n")
4040
end
4141
end
4242

@@ -46,7 +46,7 @@ gemspec = Dir.mktmpdir do |dir|
4646
raise "could not unpack gem #{gemfile}"
4747
end
4848

49-
YAML.unsafe_load(%x(gunzip -c metadata.gz))
49+
YAML.unsafe_load(`gunzip -c metadata.gz`)
5050
end
5151
end
5252

@@ -96,117 +96,121 @@ describe File.basename(gemfile) do
9696
describe "all platforms" do
9797
["lib", "test"].each do |dir|
9898
it "contains every ruby file in #{dir}/" do
99-
expected = %x(git ls-files #{dir}).split("\n").grep(/\.rb$/).sort
99+
expected = `git ls-files #{dir}`.split("\n").grep(/\.rb$/).sort
100100
skip "looks like this isn't a git repository" if expected.empty?
101101
actual = gemfile_contents.select { |f| f.start_with?("#{dir}/") }.grep(/\.rb$/).sort
102102
assert_equal(expected, actual)
103103
end
104104
end
105105
end
106106

107-
describe "ruby platform" do
108-
it "depends on mini_portile2" do
109-
assert(gemspec.dependencies.find { |d| d.name == "mini_portile2" })
110-
end
107+
if gemspec.platform == Gem::Platform::RUBY
108+
describe "ruby platform" do
109+
it "depends on mini_portile2" do
110+
assert(gemspec.dependencies.find { |d| d.name == "mini_portile2" })
111+
end
111112

112-
it "contains extension C and header files" do
113-
assert_equal(6, gemfile_contents.count { |f| File.fnmatch?("ext/**/*.c", f) })
114-
assert_equal(6, gemfile_contents.count { |f| File.fnmatch?("ext/**/*.h", f) })
115-
end
113+
it "contains extension C and header files" do
114+
assert_equal(6, gemfile_contents.count { |f| File.fnmatch?("ext/**/*.c", f) })
115+
assert_equal(6, gemfile_contents.count { |f| File.fnmatch?("ext/**/*.h", f) })
116+
end
116117

117-
it "includes C files in extra_rdoc_files" do
118-
assert_equal(6, gemspec.extra_rdoc_files.count { |f| File.fnmatch?("ext/**/*.c", f) })
119-
end
118+
it "includes C files in extra_rdoc_files" do
119+
assert_equal(6, gemspec.extra_rdoc_files.count { |f| File.fnmatch?("ext/**/*.c", f) })
120+
end
120121

121-
it "contains the port files" do
122-
dependencies = YAML.load_file(File.join(__dir__, "..", "dependencies.yml"), symbolize_names: true)
123-
sqlite_tarball = File.basename(dependencies[:sqlite3][:files].first[:url])
124-
actual_ports = gemfile_contents.grep(%r{^ports/})
122+
it "contains the port files" do
123+
dependencies = YAML.load_file(File.join(__dir__, "..", "dependencies.yml"), symbolize_names: true)
124+
sqlite_tarball = File.basename(dependencies[:sqlite3][:files].first[:url])
125+
actual_ports = gemfile_contents.grep(%r{^ports/})
125126

126-
assert_equal(["ports/archives/#{sqlite_tarball}"], actual_ports)
127-
end
127+
assert_equal(["ports/archives/#{sqlite_tarball}"], actual_ports)
128+
end
128129

129-
it "contains the patch files" do
130-
assert_equal(Dir.glob("patches/*.patch").length, gemfile_contents.count { |f| File.fnmatch?("patches/*", f) })
131-
end
130+
it "contains the patch files" do
131+
assert_equal(Dir.glob("patches/*.patch").length, gemfile_contents.count { |f| File.fnmatch?("patches/*", f) })
132+
end
132133

133-
it "sets metadata for msys2" do
134-
refute_nil(gemspec.metadata["msys2_mingw_dependencies"])
135-
end
134+
it "sets metadata for msys2" do
135+
refute_nil(gemspec.metadata["msys2_mingw_dependencies"])
136+
end
136137

137-
it "sets required_ruby_version appropriately" do
138-
all_supported_ruby_versions.each do |v|
139-
assert(
140-
gemspec.required_ruby_version.satisfied_by?(Gem::Version.new(v)),
141-
"required_ruby_version='#{gemspec.required_ruby_version}' should support ruby #{v}",
142-
)
138+
it "sets required_ruby_version appropriately" do
139+
all_supported_ruby_versions.each do |v|
140+
assert(
141+
gemspec.required_ruby_version.satisfied_by?(Gem::Version.new(v)),
142+
"required_ruby_version='#{gemspec.required_ruby_version}' should support ruby #{v}"
143+
)
144+
end
143145
end
144146
end
145-
end if gemspec.platform == Gem::Platform::RUBY
147+
end
146148

147-
describe "native platform" do
148-
it "does not depend on mini_portile2" do
149-
refute(gemspec.dependencies.find { |d| d.name == "mini_portile2" })
150-
end
149+
if gemspec.platform.is_a?(Gem::Platform) && gemspec.platform.cpu
150+
describe "native platform" do
151+
it "does not depend on mini_portile2" do
152+
refute(gemspec.dependencies.find { |d| d.name == "mini_portile2" })
153+
end
151154

152-
it "contains extension C and header files" do
153-
assert_equal(6, gemfile_contents.count { |f| File.fnmatch?("ext/**/*.c", f) })
154-
assert_equal(6, gemfile_contents.count { |f| File.fnmatch?("ext/**/*.h", f) })
155-
end
155+
it "contains extension C and header files" do
156+
assert_equal(6, gemfile_contents.count { |f| File.fnmatch?("ext/**/*.c", f) })
157+
assert_equal(6, gemfile_contents.count { |f| File.fnmatch?("ext/**/*.h", f) })
158+
end
156159

157-
it "includes C files in extra_rdoc_files" do
158-
assert_equal(6, gemspec.extra_rdoc_files.count { |f| File.fnmatch?("ext/**/*.c", f) })
159-
end
160+
it "includes C files in extra_rdoc_files" do
161+
assert_equal(6, gemspec.extra_rdoc_files.count { |f| File.fnmatch?("ext/**/*.c", f) })
162+
end
160163

161-
it "does not contain the port files" do
162-
assert_empty(gemfile_contents.grep(%r{^ports/}))
163-
end
164+
it "does not contain the port files" do
165+
assert_empty(gemfile_contents.grep(%r{^ports/}))
166+
end
164167

165-
it "does not contain the patch files" do
166-
assert_empty(gemfile_contents.grep(%r{^patches/}))
167-
end
168+
it "does not contain the patch files" do
169+
assert_empty(gemfile_contents.grep(%r{^patches/}))
170+
end
171+
172+
it "contains expected shared library files " do
173+
platform_supported_ruby_versions.each do |version|
174+
actual = gemfile_contents.find do |p|
175+
File.fnmatch?("lib/sqlite3/#{version}/sqlite3_native.{so,bundle}", p, File::FNM_EXTGLOB)
176+
end
177+
assert(actual, "expected to find shared library file for ruby #{version}")
178+
end
168179

169-
it "contains expected shared library files " do
170-
platform_supported_ruby_versions.each do |version|
171180
actual = gemfile_contents.find do |p|
172-
File.fnmatch?("lib/sqlite3/#{version}/sqlite3_native.{so,bundle}", p, File::FNM_EXTGLOB)
181+
File.fnmatch?("lib/sqlite3/sqlite3_native.{so,bundle}", p, File::FNM_EXTGLOB)
173182
end
174-
assert(actual, "expected to find shared library file for ruby #{version}")
175-
end
183+
refute(actual, "did not expect to find shared library file in lib/sqlite3")
176184

177-
actual = gemfile_contents.find do |p|
178-
File.fnmatch?("lib/sqlite3/sqlite3_native.{so,bundle}", p, File::FNM_EXTGLOB)
185+
actual = gemfile_contents.find_all do |p|
186+
File.fnmatch?("lib/sqlite3/**/*.{so,bundle}", p, File::FNM_EXTGLOB)
187+
end
188+
assert_equal(
189+
platform_supported_ruby_versions.length,
190+
actual.length,
191+
"did not expect extra shared library files"
192+
)
179193
end
180-
refute(actual, "did not expect to find shared library file in lib/sqlite3")
181194

182-
actual = gemfile_contents.find_all do |p|
183-
File.fnmatch?("lib/sqlite3/**/*.{so,bundle}", p, File::FNM_EXTGLOB)
195+
it "sets required_ruby_version appropriately" do
196+
unsupported_versions = all_supported_ruby_versions - platform_supported_ruby_versions
197+
platform_supported_ruby_versions.each do |v|
198+
assert(
199+
gemspec.required_ruby_version.satisfied_by?(Gem::Version.new(v)),
200+
"required_ruby_version='#{gemspec.required_ruby_version}' should support ruby #{v}"
201+
)
202+
end
203+
unsupported_versions.each do |v|
204+
refute(
205+
gemspec.required_ruby_version.satisfied_by?(Gem::Version.new(v)),
206+
"required_ruby_version='#{gemspec.required_ruby_version}' should not support ruby #{v}"
207+
)
208+
end
184209
end
185-
assert_equal(
186-
platform_supported_ruby_versions.length,
187-
actual.length,
188-
"did not expect extra shared library files",
189-
)
190-
end
191210

192-
it "sets required_ruby_version appropriately" do
193-
unsupported_versions = all_supported_ruby_versions - platform_supported_ruby_versions
194-
platform_supported_ruby_versions.each do |v|
195-
assert(
196-
gemspec.required_ruby_version.satisfied_by?(Gem::Version.new(v)),
197-
"required_ruby_version='#{gemspec.required_ruby_version}' should support ruby #{v}",
198-
)
211+
it "does not set metadata for msys2" do
212+
assert_nil(gemspec.metadata["msys2_mingw_dependencies"])
199213
end
200-
unsupported_versions.each do |v|
201-
refute(
202-
gemspec.required_ruby_version.satisfied_by?(Gem::Version.new(v)),
203-
"required_ruby_version='#{gemspec.required_ruby_version}' should not support ruby #{v}",
204-
)
205-
end
206-
end
207-
208-
it "does not set metadata for msys2" do
209-
assert_nil(gemspec.metadata["msys2_mingw_dependencies"])
210214
end
211-
end if gemspec.platform.is_a?(Gem::Platform) && gemspec.platform.cpu
215+
end
212216
end

0 commit comments

Comments
 (0)