From e6b903b21e0682c1156ffec583ac2836fda7d657 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 28 Sep 2023 09:40:28 -0400 Subject: [PATCH] Fix haml-lint `InstanceVariables` rule for invites/_form (#26064) --- .haml-lint_todo.yml | 11 ++++------- app/helpers/invites_helper.rb | 11 +++++++++++ app/views/admin/invites/index.html.haml | 3 ++- app/views/invites/_form.html.haml | 21 ++++++++++----------- app/views/invites/index.html.haml | 3 ++- 5 files changed, 29 insertions(+), 20 deletions(-) create mode 100644 app/helpers/invites_helper.rb diff --git a/.haml-lint_todo.yml b/.haml-lint_todo.yml index 6d2aa0641f5..e8791e05ca0 100644 --- a/.haml-lint_todo.yml +++ b/.haml-lint_todo.yml @@ -1,13 +1,13 @@ # This configuration was generated by # `haml-lint --auto-gen-config` -# on 2023-07-20 09:47:50 -0400 using Haml-Lint version 0.48.0. +# on 2023-08-28 13:08:37 -0400 using Haml-Lint version 0.50.0. # The point is for the user to remove these configuration records # one by one as the lints are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of Haml-Lint, may require this file to be generated again. linters: - # Offense count: 951 + # Offense count: 945 LineLength: enabled: false @@ -26,7 +26,7 @@ linters: - 'app/views/admin/reports/show.html.haml' - 'app/views/disputes/strikes/show.html.haml' - # Offense count: 32 + # Offense count: 28 InstanceVariables: exclude: - 'app/views/admin/reports/_actions.html.haml' @@ -34,14 +34,11 @@ linters: - 'app/views/admin/webhooks/_form.html.haml' - 'app/views/auth/registrations/_status.html.haml' - 'app/views/auth/sessions/two_factor/_otp_authentication_form.html.haml' - - 'app/views/authorize_interactions/_post_follow_actions.html.haml' - - 'app/views/invites/_form.html.haml' - 'app/views/relationships/_account.html.haml' - 'app/views/shared/_og.html.haml' - # Offense count: 3 + # Offense count: 2 IdNames: exclude: - - 'app/views/authorize_interactions/error.html.haml' - 'app/views/oauth/authorizations/error.html.haml' - 'app/views/shared/_error_messages.html.haml' diff --git a/app/helpers/invites_helper.rb b/app/helpers/invites_helper.rb new file mode 100644 index 00000000000..c189061db0b --- /dev/null +++ b/app/helpers/invites_helper.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module InvitesHelper + def invites_max_uses_options + [1, 5, 10, 25, 50, 100] + end + + def invites_expires_options + [30.minutes, 1.hour, 6.hours, 12.hours, 1.day, 1.week] + end +end diff --git a/app/views/admin/invites/index.html.haml b/app/views/admin/invites/index.html.haml index ee6ba0f5742..964deaba8f3 100644 --- a/app/views/admin/invites/index.html.haml +++ b/app/views/admin/invites/index.html.haml @@ -14,7 +14,8 @@ - if policy(:invite).create? %p= t('invites.prompt') - = render 'invites/form' + = simple_form_for(@invite, url: admin_invites_path) do |form| + = render partial: 'invites/form', object: form %hr.spacer/ diff --git a/app/views/invites/_form.html.haml b/app/views/invites/_form.html.haml index 7ea521ebc70..dbbb785e835 100644 --- a/app/views/invites/_form.html.haml +++ b/app/views/invites/_form.html.haml @@ -1,14 +1,13 @@ -= simple_form_for(@invite, url: controller.is_a?(Admin::InvitesController) ? admin_invites_path : invites_path) do |f| - = render 'shared/error_messages', object: @invite += render 'shared/error_messages', object: form.object - .fields-row - .fields-row__column.fields-row__column-6.fields-group - = f.input :max_uses, wrapper: :with_label, collection: [1, 5, 10, 25, 50, 100], label_method: ->(num) { I18n.t('invites.max_uses', count: num) }, prompt: I18n.t('invites.max_uses_prompt') - .fields-row__column.fields-row__column-6.fields-group - = f.input :expires_in, wrapper: :with_label, collection: [30.minutes, 1.hour, 6.hours, 12.hours, 1.day, 1.week].map(&:to_i), label_method: ->(i) { I18n.t("invites.expires_in.#{i}") }, prompt: I18n.t('invites.expires_in_prompt') +.fields-row + .fields-row__column.fields-row__column-6.fields-group + = form.input :max_uses, wrapper: :with_label, collection: invites_max_uses_options, label_method: ->(num) { I18n.t('invites.max_uses', count: num) }, prompt: I18n.t('invites.max_uses_prompt') + .fields-row__column.fields-row__column-6.fields-group + = form.input :expires_in, wrapper: :with_label, collection: invites_expires_options.map(&:to_i), label_method: ->(i) { I18n.t("invites.expires_in.#{i}") }, prompt: I18n.t('invites.expires_in_prompt') - .fields-group - = f.input :autofollow, wrapper: :with_label +.fields-group + = form.input :autofollow, wrapper: :with_label - .actions - = f.button :button, t('invites.generate'), type: :submit +.actions + = form.button :button, t('invites.generate'), type: :submit diff --git a/app/views/invites/index.html.haml b/app/views/invites/index.html.haml index 61420ab1e40..88ed662af89 100644 --- a/app/views/invites/index.html.haml +++ b/app/views/invites/index.html.haml @@ -4,7 +4,8 @@ - if policy(:invite).create? %p= t('invites.prompt') - = render 'form' + = simple_form_for(@invite, url: invites_path) do |form| + = render partial: 'form', object: form %hr.spacer/