From e5717c9bc6cb5a1bea4c93048024f6247566f8ce Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 15 Dec 2023 09:34:24 -0500 Subject: [PATCH] Fix `Style/Lambda` cop (#28378) --- .rubocop_todo.yml | 8 -------- config/initializers/simple_form.rb | 2 +- config/routes.rb | 10 +++++----- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 03cc2e75d35..c323aa877b4 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -386,14 +386,6 @@ Style/InverseMethods: - 'app/services/update_account_service.rb' - 'spec/controllers/activitypub/replies_controller_spec.rb' -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: line_count_dependent, lambda, literal -Style/Lambda: - Exclude: - - 'config/initializers/simple_form.rb' - - 'config/routes.rb' - # This cop supports unsafe autocorrection (--autocorrect-all). Style/MapToHash: Exclude: diff --git a/config/initializers/simple_form.rb b/config/initializers/simple_form.rb index 6d9d7b8aeb3..a8bc4b19211 100644 --- a/config/initializers/simple_form.rb +++ b/config/initializers/simple_form.rb @@ -164,7 +164,7 @@ SimpleForm.setup do |config| # config.item_wrapper_class = nil # How the label text should be generated altogether with the required text. - config.label_text = lambda { |label, required, _explicit_label| "#{label} #{required}" } + config.label_text = ->(label, required, _explicit_label) { "#{label} #{required}" } # You can define the class to use on all labels. Default is nil. # config.label_class = nil diff --git a/config/routes.rb b/config/routes.rb index 150b26cf1ed..85c3b18556e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -51,7 +51,7 @@ Rails.application.routes.draw do get 'health', to: 'health#show' - authenticate :user, lambda { |u| u.role&.can?(:view_devops) } do + authenticate :user, ->(user) { user.role&.can?(:view_devops) } do mount Sidekiq::Web, at: 'sidekiq', as: :sidekiq mount PgHero::Engine, at: 'pghero', as: :pghero end @@ -105,10 +105,10 @@ Rails.application.routes.draw do } # rubocop:disable Style/FormatStringToken - those do not go through the usual formatting functions and are not safe to correct - get '/users/:username', to: redirect_with_vary('/@%{username}'), constraints: lambda { |req| req.format.nil? || req.format.html? } - get '/users/:username/following', to: redirect_with_vary('/@%{username}/following'), constraints: lambda { |req| req.format.nil? || req.format.html? } - get '/users/:username/followers', to: redirect_with_vary('/@%{username}/followers'), constraints: lambda { |req| req.format.nil? || req.format.html? } - get '/users/:username/statuses/:id', to: redirect_with_vary('/@%{username}/%{id}'), constraints: lambda { |req| req.format.nil? || req.format.html? } + get '/users/:username', to: redirect_with_vary('/@%{username}'), constraints: ->(req) { req.format.nil? || req.format.html? } + get '/users/:username/following', to: redirect_with_vary('/@%{username}/following'), constraints: ->(req) { req.format.nil? || req.format.html? } + get '/users/:username/followers', to: redirect_with_vary('/@%{username}/followers'), constraints: ->(req) { req.format.nil? || req.format.html? } + get '/users/:username/statuses/:id', to: redirect_with_vary('/@%{username}/%{id}'), constraints: ->(req) { req.format.nil? || req.format.html? } # rubocop:enable Style/FormatStringToken get '/authorize_follow', to: redirect { |_, request| "/authorize_interaction?#{request.params.to_query}" }