From fcb47858493d1b4c9bfd26921bef3404db07c544 Mon Sep 17 00:00:00 2001 From: Luilver Garces Date: Wed, 30 Mar 2022 16:24:02 -0500 Subject: [PATCH 1/3] Add rubocop --- ruby/Gemfile | 3 +++ ruby/Gemfile.lock | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/ruby/Gemfile b/ruby/Gemfile index 27d1a7d..194e491 100644 --- a/ruby/Gemfile +++ b/ruby/Gemfile @@ -10,4 +10,7 @@ gem 'mx-platform-ruby' group :test do # Test it with RSpec (BDD for Ruby) gem 'rspec-core' + + # Keep files consistent + gem 'rubocop', require: false end diff --git a/ruby/Gemfile.lock b/ruby/Gemfile.lock index 83e6c32..534f29f 100644 --- a/ruby/Gemfile.lock +++ b/ruby/Gemfile.lock @@ -1,6 +1,7 @@ GEM remote: https://rubygems.org/ specs: + ast (2.4.2) dotenv (2.7.6) faraday (1.10.0) faraday-em_http (~> 1.0) @@ -30,12 +31,30 @@ GEM ruby2_keywords (~> 0.0.1) mx-platform-ruby (0.11.2) faraday (~> 1.0, >= 1.0.1) + parallel (1.22.1) + parser (3.1.1.0) + ast (~> 2.4.1) rack (2.2.3) rack-protection (2.2.0) rack + rainbow (3.1.1) + regexp_parser (2.2.1) + rexml (3.2.5) rspec-core (3.11.0) rspec-support (~> 3.11.0) rspec-support (3.11.0) + rubocop (1.26.1) + parallel (~> 1.10) + parser (>= 3.1.0.0) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml + rubocop-ast (>= 1.16.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.16.0) + parser (>= 3.1.1.0) + ruby-progressbar (1.11.0) ruby2_keywords (0.0.5) sinatra (2.2.0) mustermann (~> 1.0) @@ -44,6 +63,7 @@ GEM tilt (~> 2.0) sinatra-cross_origin (0.3.2) tilt (2.0.10) + unicode-display_width (2.1.0) PLATFORMS x86_64-darwin-20 @@ -52,6 +72,7 @@ DEPENDENCIES dotenv (~> 2.7) mx-platform-ruby rspec-core + rubocop sinatra sinatra-cross_origin (~> 0.3.1) From 3ccb7bf788f16097bde5e0cde1606bbc5ccf478c Mon Sep 17 00:00:00 2001 From: Luilver Garces Date: Wed, 30 Mar 2022 16:24:38 -0500 Subject: [PATCH 2/3] Add coping file --- .rubocop.yml | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..00c33e4 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,88 @@ +AllCops: + TargetRubyVersion: 2.7.5 + Exclude: + - 'frontend/node_modules/**/*' + - 'README.md' + NewCops: enable + +Bundler/OrderedGems: + Enabled: false + +Layout/DotPosition: + EnforcedStyle: leading + +Layout/LeadingCommentSpace: + Enabled: false + +Layout/MultilineMethodCallIndentation: + Enabled: false + +Layout/RescueEnsureAlignment: + Enabled: false + +Lint/EmptyBlock: + Enabled: false + +Lint/AmbiguousOperator: + Enabled: false + +Lint/NonLocalExitFromIterator: + Enabled: false + +Lint/ScriptPermission: + Enabled: false + +Metrics: + Enabled: false + +Naming/AccessorMethodName: + Enabled: false + +Naming/FileName: + Enabled: false + +Naming/PredicateName: + Enabled: false + +Naming/RescuedExceptionsVariableName: + Enabled: false + +Security: + Enabled: true + +Style/BlockDelimiters: + EnforcedStyle: braces_for_chaining + +Style/Documentation: + Enabled: false + +Style/NumericLiteralPrefix: + Enabled: false + +Style/NumericLiterals: + Enabled: false + +Style/PercentLiteralDelimiters: + PreferredDelimiters: + '%': () + '%i': '[]' + '%I': '[]' + '%q': () + '%Q': () + '%r': '{}' + '%s': () + '%w': '[]' + '%W': '[]' + '%x': () + +Style/StringLiterals: + Enabled: false + +Style/StringLiteralsInInterpolation: + Enabled: false + +Style/TrailingCommaInArrayLiteral: + EnforcedStyleForMultiline: no_comma + +Style/TrailingCommaInHashLiteral: + EnforcedStyleForMultiline: no_comma From db629ed533ba38dc4f298d9471962829f4817015 Mon Sep 17 00:00:00 2001 From: Luilver Garces Date: Wed, 30 Mar 2022 16:25:15 -0500 Subject: [PATCH 3/3] Fix offenses --- ruby/Gemfile | 2 ++ ruby/app.rb | 8 +++++--- ruby/spec/app_spec.rb | 2 ++ ruby/spec/spec_helper.rb | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ruby/Gemfile b/ruby/Gemfile index 194e491..49b5949 100644 --- a/ruby/Gemfile +++ b/ruby/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gem 'sinatra' diff --git a/ruby/app.rb b/ruby/app.rb index f96c2b7..a72ea90 100644 --- a/ruby/app.rb +++ b/ruby/app.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Load env vars from .env file require 'dotenv' Dotenv.load('./../.env') @@ -43,7 +45,7 @@ mx_platform_api = ::MxPlatformRuby::MxPlatformApi.new(api_client) get '/api/test' do - { :test => 'hit' }.to_json + { test: 'hit' }.to_json end get '/api/users' do @@ -73,7 +75,7 @@ def create_user(user_id, mx_platform_api) content_type :json begin - request.body.rewind # in case someone already read it + request.body.rewind # in case someone already read it data = JSON.parse(request.body.read) external_id = data['user_id'].empty? ? nil : data['user_id'] @@ -137,7 +139,7 @@ def create_user(user_id, mx_platform_api) post '/api/balances' do content_type :json begin - request.body.rewind # in case someone already read it + request.body.rewind # in case someone already read it data = JSON.parse(request.body.read) response = mx_platform_api.check_balances(data['member_guid'], data['user_guid']) diff --git a/ruby/spec/app_spec.rb b/ruby/spec/app_spec.rb index 7e10fe0..22fc000 100644 --- a/ruby/spec/app_spec.rb +++ b/ruby/spec/app_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe "app" do it 'should be implemented' do; end end diff --git a/ruby/spec/spec_helper.rb b/ruby/spec/spec_helper.rb index de9aa45..e570aab 100644 --- a/ruby/spec/spec_helper.rb +++ b/ruby/spec/spec_helper.rb @@ -1 +1,3 @@ -::Dir[File.expand_path("spec/**/*.rb")].each { |f| require f } +# frozen_string_literal: true + +::Dir[File.expand_path("spec/**/*.rb")].sort.each { |f| require f }