Added Rubocop harness to enforce Ruby code style
diff --git a/lib/rb/.rubocop.yml b/lib/rb/.rubocop.yml
new file mode 100644
index 0000000..926edcb
--- /dev/null
+++ b/lib/rb/.rubocop.yml
@@ -0,0 +1,13 @@
+plugins:
+ - rubocop-performance
+ - rubocop-rspec
+
+AllCops:
+ DisabledByDefault: true
+ SuggestExtensions: false
+ TargetRubyVersion: 2.7
+ Exclude:
+ - "**/vendor/**/*"
+
+Layout/IndentationConsistency:
+ Enabled: true
diff --git a/lib/rb/Gemfile b/lib/rb/Gemfile
index 83ff867..f3da0a3 100644
--- a/lib/rb/Gemfile
+++ b/lib/rb/Gemfile
@@ -5,3 +5,5 @@
# Only required for tests with Rack 2.x on Ruby 4.0+
gem 'cgi'
gem 'ostruct'
+
+eval_gemfile File.expand_path("Gemfile.linters", __dir__)
diff --git a/lib/rb/Gemfile.linters b/lib/rb/Gemfile.linters
new file mode 100644
index 0000000..00d4d22
--- /dev/null
+++ b/lib/rb/Gemfile.linters
@@ -0,0 +1,5 @@
+source "https://rubygems.org"
+
+gem 'rubocop', '~> 1.82.0'
+gem 'rubocop-performance', '~> 1.26.1'
+gem 'rubocop-rspec', '~> 3.8.0'
diff --git a/lib/rb/Gemfile.lock b/lib/rb/Gemfile.lock
index ea47938..5030d2d 100644
--- a/lib/rb/Gemfile.lock
+++ b/lib/rb/Gemfile.lock
@@ -7,6 +7,7 @@
GEM
remote: https://rubygems.org/
specs:
+ ast (2.4.3)
binding_of_caller (1.0.1)
debug_inspector (>= 1.2.0)
byebug (11.1.3)
@@ -16,9 +17,17 @@
debug_inspector (1.2.0)
diff-lcs (1.6.2)
eventmachine (1.2.7)
+ json (2.18.1)
+ language_server-protocol (3.17.0.5)
+ lint_roller (1.1.0)
logger (1.7.0)
method_source (0.9.2)
ostruct (0.6.3)
+ parallel (1.27.0)
+ parser (3.3.10.1)
+ ast (~> 2.4.1)
+ racc
+ prism (1.9.0)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
@@ -28,10 +37,13 @@
pry-stack_explorer (0.4.9.3)
binding_of_caller (>= 0.7)
pry (>= 0.9.11)
+ racc (1.8.1)
rack (2.2.22)
rack-test (0.8.3)
rack (>= 1.0, < 3)
+ rainbow (3.1.1)
rake (13.3.1)
+ regexp_parser (2.11.3)
rspec (3.13.2)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
@@ -45,12 +57,37 @@
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.6)
+ rubocop (1.82.1)
+ json (~> 2.3)
+ language_server-protocol (~> 3.17.0.2)
+ lint_roller (~> 1.1.0)
+ parallel (~> 1.10)
+ parser (>= 3.3.0.2)
+ rainbow (>= 2.2.2, < 4.0)
+ regexp_parser (>= 2.9.3, < 3.0)
+ rubocop-ast (>= 1.48.0, < 2.0)
+ ruby-progressbar (~> 1.7)
+ unicode-display_width (>= 2.4.0, < 4.0)
+ rubocop-ast (1.49.0)
+ parser (>= 3.3.7.2)
+ prism (~> 1.7)
+ rubocop-performance (1.26.1)
+ lint_roller (~> 1.1)
+ rubocop (>= 1.75.0, < 2.0)
+ rubocop-ast (>= 1.47.1, < 2.0)
+ rubocop-rspec (3.8.0)
+ lint_roller (~> 1.1)
+ rubocop (~> 1.81)
+ ruby-progressbar (1.13.0)
srv (1.0.0)
rack (>= 1.3.0)
thin (1.8.2)
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0, >= 1.0.4)
rack (>= 1, < 3)
+ unicode-display_width (3.2.0)
+ unicode-emoji (~> 4.1)
+ unicode-emoji (4.2.0)
PLATFORMS
arm64-darwin
@@ -70,6 +107,9 @@
rack-test (~> 0.8.3)
rake (~> 13.3)
rspec (~> 3.7)
+ rubocop (~> 1.82.0)
+ rubocop-performance (~> 1.26.1)
+ rubocop-rspec (~> 3.8.0)
srv (~> 1.0)
thin (~> 1.7)
thrift!
diff --git a/lib/rb/Rakefile b/lib/rb/Rakefile
index b33d773..7b51145 100644
--- a/lib/rb/Rakefile
+++ b/lib/rb/Rakefile
@@ -81,7 +81,7 @@
Dir::chdir(File::dirname('ext/extconf.rb')) do
unless sh "ruby #{File::basename('ext/extconf.rb')}"
$stderr.puts "Failed to run extconf"
- break
+ break
end
unless sh "make"
$stderr.puts "make failed"
@@ -103,6 +103,13 @@
ruby 'benchmark/benchmark.rb'
end
+begin
+ require "rubocop/rake_task"
+ RuboCop::RakeTask.new
+rescue LoadError
+ task(:rubocop) { abort "Install the rubocop gem to run a static analysis" }
+end
+
desc 'Builds the thrift gem'
task :gem => [:spec, :build_ext] do
unless sh 'gem', 'build', 'thrift.gemspec'
diff --git a/lib/rb/coding_standards.md b/lib/rb/coding_standards.md
index fa0390b..641265b 100644
--- a/lib/rb/coding_standards.md
+++ b/lib/rb/coding_standards.md
@@ -1 +1,9 @@
-Please follow [General Coding Standards](/doc/coding_standards.md)
+## Ruby Coding Standards
+
+Please follow:
+* [Thrift General Coding Standards](/doc/coding_standards.md)
+* Code Style for Ruby code enforced by RuboCop
+
+To check you code for compliance, run:
+
+ bundle exec rake rubocop