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 diff --git a/ruby/Gemfile b/ruby/Gemfile index 27d1a7d..49b5949 100644 --- a/ruby/Gemfile +++ b/ruby/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gem 'sinatra' @@ -10,4 +12,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) 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 }