Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions app/presenters/cancellation_presenter.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class CancellationPresenter
include Rails.application.routes.url_helpers

attr_reader :referer
attr_reader :referer, :url_options

def initialize(referer:, url_options:)
@referer = referer
Expand All @@ -12,10 +12,6 @@ def go_back_path
referer_path || authentication_methods_setup_path
end

def url_options
@url_options
end

private

def referer_path
Expand Down
6 changes: 1 addition & 5 deletions app/presenters/idv/gpo_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Idv
class GpoPresenter
include Rails.application.routes.url_helpers

attr_reader :current_user
attr_reader :current_user, :url_options

def initialize(current_user, url_options)
@current_user = current_user
Expand Down Expand Up @@ -37,10 +37,6 @@ def letter_already_sent?
gpo_mail_service.any_mail_sent?
end

def url_options
@url_options
end

private

def gpo_mail_service
Expand Down
6 changes: 1 addition & 5 deletions app/presenters/navigation_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class NavigationPresenter

NavItem = Struct.new(:title, :href, :children)

attr_reader :user
attr_reader :user, :url_options

def initialize(user:, url_options:)
@user = user
Expand Down Expand Up @@ -58,10 +58,6 @@ def navigation_items
]
end

def url_options
@url_options
end

def backup_codes_path
if TwoFactorAuthentication::BackupCodePolicy.new(user).configured?
backup_code_regenerate_path
Expand Down
6 changes: 1 addition & 5 deletions app/presenters/piv_cac_authentication_login_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class PivCacAuthenticationLoginPresenter
include Rails.application.routes.url_helpers
include ActionView::Helpers::TranslationHelper

attr_reader :form
attr_reader :form, :url_options

def initialize(form, url_options)
@form = form
Expand All @@ -28,8 +28,4 @@ def heading
def info
t('instructions.mfa.piv_cac.sign_in', app_name: APP_NAME)
end

def url_options
@url_options
end
end
15 changes: 11 additions & 4 deletions lib/linters/url_options_linter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@ module IdentityIdp
# class MyViewModelClass
# include Rails.application.routes.url_helpers
#
# attr_reader :url_options
#
# def initialize(url_options)
# @url_options = url_options
# end
#
# def my_method
# account_path
# end
#
# def url_options
# @url_options
# end
# end
#
class UrlOptionsLinter < RuboCop::Cop::Cop
Expand Down Expand Up @@ -59,8 +57,17 @@ def defines_url_options?(node)
return true if descendant.method?(:url_options)
end

node.parent.each_descendant(:send) do |descendant|
return true if url_options_attr_method?(descendant)
end

false
end

def url_options_attr_method?(descendant)
return false unless descendant.method_name.match?(/^attr_(reader|accessor)$/)
descendant.arguments.any? { |arg| arg.value == :url_options }
end
end
end
end
Expand Down
18 changes: 18 additions & 0 deletions spec/lib/linters/url_options_linter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,22 @@ def url_options
end
RUBY
end

it 'registers no offense when including Rails url_helpers and defining attr_reader' do
expect_no_offenses(<<~RUBY)
class MyViewModelClass
include Rails.application.routes.url_helpers
attr_reader :url_options
end
RUBY
end

it 'registers no offense when including Rails url_helpers and defining attr_accessor' do
expect_no_offenses(<<~RUBY)
class MyViewModelClass
include Rails.application.routes.url_helpers
attr_accessor :url_options
end
RUBY
end
end