From fd1975fd99d54e0a9bdf2ae29cf3de014895f51d Mon Sep 17 00:00:00 2001 From: Benoit Date: Sun, 19 May 2024 22:35:56 +0200 Subject: [PATCH 1/2] array style brackets in rubocop conf - changing array to be compliant with rubocop --- .overcommit.yml | 1 + .rubocop.yml | 11 +++++++++++ Gemfile | 4 ++-- app/controllers/free_accesses_controller.rb | 4 ++-- app/controllers/machines_controller.rb | 4 ++-- app/controllers/subscriptions_controller.rb | 2 +- app/models/ability.rb | 4 ++-- config/initializers/filter_parameter_logging.rb | 4 +--- config/initializers/omniauth.rb | 2 +- config/routes.rb | 4 ++-- lib/tasks/system_test.rake | 2 +- test/models/ip_test.rb | 5 +++-- test/models/machine_test.rb | 6 +++--- test/models/user_test.rb | 7 +++---- 14 files changed, 35 insertions(+), 25 deletions(-) diff --git a/.overcommit.yml b/.overcommit.yml index ac2193a5..776d13ce 100644 --- a/.overcommit.yml +++ b/.overcommit.yml @@ -21,6 +21,7 @@ PreCommit: RuboCop: enabled: true on_warn: fail # Treat all warnings as failures + command: ['bundle', 'exec', 'rubocop'] FixMe: enabled: true RailsSchemaUpToDate: diff --git a/.rubocop.yml b/.rubocop.yml index be56e00e..87e06988 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -42,3 +42,14 @@ Rails/I18nLocaleTexts: I18n/RailsI18n/DecorateString: Enabled: false + +# Allow string or symbol array without literal +Style/WordArray: + EnforcedStyle: brackets + SupportedStyles: + - brackets + +Style/SymbolArray: + EnforcedStyle: brackets + SupportedStyles: + - brackets diff --git a/Gemfile b/Gemfile index 224170b5..b4588c25 100644 --- a/Gemfile +++ b/Gemfile @@ -36,7 +36,7 @@ gem 'jbuilder' # gem "bcrypt", "~> 3.1.7" # Windows does not include zoneinfo files, so bundle the tzinfo-data gem -gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] +gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', require: false @@ -57,7 +57,7 @@ gem 'cancancan', '~> 3.4' group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem - gem 'debug', platforms: %i[mri mingw x64_mingw] + gem 'debug', platforms: [:mri, :mingw, :x64_mingw] end group :development do diff --git a/app/controllers/free_accesses_controller.rb b/app/controllers/free_accesses_controller.rb index abf07a74..e024f340 100644 --- a/app/controllers/free_accesses_controller.rb +++ b/app/controllers/free_accesses_controller.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true class FreeAccessesController < ApplicationController - before_action :owner, only: %i[create new] - before_action :current_free_access, only: %i[edit update destroy] + before_action :owner, only: [:create, :new] + before_action :current_free_access, only: [:edit, :update, :destroy] def new @free_access = @owner.free_accesses.new(start_at: Time.current) diff --git a/app/controllers/machines_controller.rb b/app/controllers/machines_controller.rb index 4c9358be..33bef588 100644 --- a/app/controllers/machines_controller.rb +++ b/app/controllers/machines_controller.rb @@ -3,8 +3,8 @@ class MachinesController < ApplicationController protect_from_forgery unless: -> { request.format.json? } - before_action :owner, only: %i[create new] - before_action :current_machine, only: %i[show edit update destroy] + before_action :owner, only: [:create, :new] + before_action :current_machine, only: [:show, :edit, :update, :destroy] def show authorize! :show, @machine diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb index f85c5a76..572cbc5c 100644 --- a/app/controllers/subscriptions_controller.rb +++ b/app/controllers/subscriptions_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class SubscriptionsController < ApplicationController - before_action :owner, only: %i[create new destroy] + before_action :owner, only: [:create, :new, :destroy] def new @subscription = @owner.subscriptions.new diff --git a/app/models/ability.rb b/app/models/ability.rb index 8460abfa..c8c19ad7 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -6,8 +6,8 @@ class Ability def initialize(user) return if user.blank? - can %i[read update], User, id: user.id - can %i[read update destroy], Machine, user: user + can [:read, :update], User, id: user.id + can [:read, :update, :destroy], Machine, user: user # User can create a new machine to themselves if they don't have too many machines can [:create], Machine do |machine| machine.user == user && user.machines.size < USER_MACHINES_LIMIT diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 3df77c5b..8d83a966 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -5,6 +5,4 @@ # Configure parameters to be filtered from the log file. Use this to limit dissemination of # sensitive information. See the ActiveSupport::ParameterFilter documentation for supported # notations and behaviors. -Rails.application.config.filter_parameters += %i[ - passw secret token _key crypt salt certificate otp ssn -] +Rails.application.config.filter_parameters += [:passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn] diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index b36056f6..5c22b245 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -16,7 +16,7 @@ end provider :openid_connect, { name: :keycloak, - scope: %i[openid email profile room roles], + scope: [:openid, :email, :profile, :room, :roles], response_type: :code, issuer: 'https://auth.rezoleo.fr/realms/rezoleo', discovery: true, diff --git a/config/routes.rb b/config/routes.rb index 60e94bae..6e46b86b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,8 +8,8 @@ resources :users do resources :machines, shallow: true, except: [:index] - resources :subscriptions, shallow: true, only: %i[new create] + resources :subscriptions, shallow: true, only: [:new, :create] delete '/last_subscription', to: 'subscriptions#destroy', as: 'last_subscription' - resources :free_accesses, shallow: true, except: %i[index show] + resources :free_accesses, shallow: true, except: [:index, :show] end end diff --git a/lib/tasks/system_test.rake b/lib/tasks/system_test.rake index b52ba58f..a132ca64 100644 --- a/lib/tasks/system_test.rake +++ b/lib/tasks/system_test.rake @@ -17,7 +17,7 @@ namespace :test do end desc 'Run system tests with Firefox (can be run headless and/or use Firefox Nightly)' - task :firefox, %i[headless nightly] => [:environment] do |_task, args| + task :firefox, [:headless, :nightly] => [:environment] do |_task, args| # Small (ab)use of args.to_a, normally used to retrieve a variable number of arguments # Since here we only care that the *strings* 'headless' or 'nightly' are passed, we convert # the args struct to an array of all argument values, then just check if a specific string is in it. diff --git a/test/models/ip_test.rb b/test/models/ip_test.rb index d703d384..649b066c 100644 --- a/test/models/ip_test.rb +++ b/test/models/ip_test.rb @@ -29,8 +29,9 @@ def setup end test 'ip must be of a valid format' do - valid_ips = %w[172.30.110.68] - invalid_ips = %w[172..30.110.68 172.300.110.68 172.0004.110.68 172.30.68 172.30.110.68.17 172.30.110.68.] + valid_ips = ['172.30.110.68'] + invalid_ips = ['172..30.110.68', '172.300.110.68', '172.0004.110.68', '172.30.68', '172.30.110.68.17', + '172.30.110.68.'] valid_ips.each do |valid_ip| @ip.ip = valid_ip diff --git a/test/models/machine_test.rb b/test/models/machine_test.rb index d7edf28e..d43a9247 100644 --- a/test/models/machine_test.rb +++ b/test/models/machine_test.rb @@ -39,9 +39,9 @@ def setup end test 'mac must be of a valid format' do - valid_macs = %w[AD:14:D4:87:4B:D7 ba:d4:8a:54:47:3f 23:Eb:1a:3A:BC:f7 - AD-14-D4-87-4B-D7 ba-d4-8a-54-47-3f AD14D4874BD7 bad48a54473f - AD14.D487.4BD7 ad14.d487.4bd7 AD14.d487.4bD7] + valid_macs = ['AD:14:D4:87:4B:D7', 'ba:d4:8a:54:47:3f', '23:Eb:1a:3A:BC:f7', 'AD-14-D4-87-4B-D7', + 'ba-d4-8a-54-47-3f', 'AD14D4874BD7', 'bad48a54473f', 'AD14.D487.4BD7', + 'ad14.d487.4bd7', 'AD14.d487.4bD7'] invalid_macs = ['AD:14', # must not be too short 'AD:14:D4:87:4B:', # trailing colon diff --git a/test/models/user_test.rb b/test/models/user_test.rb index b35d23b7..c9326efb 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -39,8 +39,7 @@ def setup end test 'email must be of a valid format' do - valid_emails = %w[users@example.com USER@foo.COM A_US_ER@foo.bar.org - first.last@foo.jp alice+bob@baz.cn] + valid_emails = ['users@example.com', 'USER@foo.COM', 'A_US_ER@foo.bar.org', 'first.last@foo.jp', 'alice+bob@baz.cn'] invalid_emails = ['user@example,com', 'user_at_foo.org', 'user.name@example', 'foo@bar_baz.com', 'foo@bar+baz.com', 'foo@bar..com', ' '] @@ -91,8 +90,8 @@ def setup end test 'room must be of a valid format' do - valid_rooms = %w[A205 B134a C001b F313 D111b E231a DF1 DF2 DF3 DF4] - invalid_rooms = %w[A2005 C404 D111c B1 E22 G207] + valid_rooms = ['A205', 'B134a', 'C001b', 'F313', 'D111b', 'E231a', 'DF1', 'DF2', 'DF3', 'DF4'] + invalid_rooms = ['A2005', 'C404', 'D111c', 'B1', 'E22', 'G207'] valid_rooms.each do |valid_room| @user.room = valid_room From bdd50da993afa0f70d18ba72f5f44fa12dadceda Mon Sep 17 00:00:00 2001 From: Benoit <42510917+benoitlx@users.noreply.github.com> Date: Sun, 19 May 2024 22:52:08 +0200 Subject: [PATCH 2/2] Update .overcommit.yml removing non necessary command option from rubocop precommit --- .overcommit.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.overcommit.yml b/.overcommit.yml index 776d13ce..ac2193a5 100644 --- a/.overcommit.yml +++ b/.overcommit.yml @@ -21,7 +21,6 @@ PreCommit: RuboCop: enabled: true on_warn: fail # Treat all warnings as failures - command: ['bundle', 'exec', 'rubocop'] FixMe: enabled: true RailsSchemaUpToDate: