Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/sca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ jobs:
run: |
python -m pip install --upgrade pip setuptools wheel flake8

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "2.7"
bundler-cache: true
working-directory: "lib/rb"

# Generate thrift files so the static code analysis includes an analysis
# of the files the thrift compiler spits out.
- name: Build compiler
Expand Down Expand Up @@ -155,6 +162,13 @@ jobs:
composer install --quiet
./vendor/bin/phpcs

- name: Run rubocop
id: rubocop
continue-on-error: true
working-directory: "lib/rb"
run: |
bundle exec rubocop --config .rubocop.yml --format progress --format github . ../../test/rb ../../tutorial/rb

- name: Print statistics
if: ${{ always() }}
run: |
Expand All @@ -176,6 +190,7 @@ jobs:
CPPCHECK_OUTCOME: ${{ steps.cppcheck.outcome }}
FLAKE8_OUTCOME: ${{ steps.flake8.outcome }}
PHPCS_OUTCOME: ${{ steps.phpcs.outcome }}
RUBOCOP_OUTCOME: ${{ steps.rubocop.outcome }}
run: |
failed=0

Expand All @@ -191,5 +206,9 @@ jobs:
echo "::error::Step 'phpcs' failed (outcome: $PHPCS_OUTCOME)"
failed=1
fi
if [ "$RUBOCOP_OUTCOME" != "success" ]; then
echo "::error::Step 'rubocop' failed (outcome: $RUBOCOP_OUTCOME)"
failed=1
fi

exit $failed
13 changes: 13 additions & 0 deletions lib/rb/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
plugins:
- rubocop-performance
- rubocop-rspec

AllCops:
DisabledByDefault: true
SuggestExtensions: false
TargetRubyVersion: 2.7
Exclude:
- "**/vendor/**/*"

Layout/IndentationConsistency:
Enabled: true
2 changes: 2 additions & 0 deletions lib/rb/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ gemspec
# Only required for tests with Rack 2.x on Ruby 4.0+
gem 'cgi'
gem 'ostruct'

eval_gemfile File.expand_path("Gemfile.linters", __dir__)
5 changes: 5 additions & 0 deletions lib/rb/Gemfile.linters
Original file line number Diff line number Diff line change
@@ -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'
40 changes: 40 additions & 0 deletions lib/rb/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ PATH
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)
Expand All @@ -16,9 +17,17 @@ GEM
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)
Expand All @@ -28,10 +37,13 @@ GEM
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)
Expand All @@ -45,12 +57,37 @@ GEM
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
Expand All @@ -70,6 +107,9 @@ DEPENDENCIES
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!
Expand Down
9 changes: 8 additions & 1 deletion lib/rb/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ task :build_ext => :'gen-rb' do
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"
Expand All @@ -103,6 +103,13 @@ task :benchmark do
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'
Expand Down
10 changes: 9 additions & 1 deletion lib/rb/coding_standards.md
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/rb/.rubocop.yml
2 changes: 2 additions & 0 deletions test/rb/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ gem 'thrift', path: '../../lib/rb'
gem 'rack', '~> 2.2'
gem 'thin', '~> 1.7', '>= 1.7.2'
gem 'test-unit', '~> 3.2', '>= 3.2.7'

eval_gemfile File.expand_path("../../lib/rb/Gemfile.linters", __dir__)
40 changes: 40 additions & 0 deletions test/rb/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,54 @@ PATH
GEM
remote: https://rubygems.org/
specs:
ast (2.4.3)
daemons (1.4.1)
eventmachine (1.2.7)
json (2.18.1)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
logger (1.7.0)
parallel (1.27.0)
parser (3.3.10.1)
ast (~> 2.4.1)
racc
power_assert (3.0.1)
prism (1.9.0)
racc (1.8.1)
rack (2.2.22)
rainbow (3.1.1)
regexp_parser (2.11.3)
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)
test-unit (3.7.3)
power_assert
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
Expand All @@ -28,6 +65,9 @@ PLATFORMS

DEPENDENCIES
rack (~> 2.2)
rubocop (~> 1.82.0)
rubocop-performance (~> 1.26.1)
rubocop-rspec (~> 3.8.0)
test-unit (~> 3.2, >= 3.2.7)
thin (~> 1.7, >= 1.7.2)
thrift!
Expand Down