diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /rubocop/cop/avoid_route_redirect_leading_slash.rb | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'rubocop/cop/avoid_route_redirect_leading_slash.rb')
-rw-r--r-- | rubocop/cop/avoid_route_redirect_leading_slash.rb | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/rubocop/cop/avoid_route_redirect_leading_slash.rb b/rubocop/cop/avoid_route_redirect_leading_slash.rb index 0b0dc7d3d33..0535ae16a33 100644 --- a/rubocop/cop/avoid_route_redirect_leading_slash.rb +++ b/rubocop/cop/avoid_route_redirect_leading_slash.rb @@ -13,7 +13,9 @@ module RuboCop # root to: redirect('-/autocomplete/users') # - class AvoidRouteRedirectLeadingSlash < RuboCop::Cop::Cop + class AvoidRouteRedirectLeadingSlash < RuboCop::Cop::Base + extend RuboCop::Cop::AutoCorrector + MSG = 'Do not use a leading "/" in route redirects' def_node_matcher :leading_slash_in_redirect?, <<~PATTERN @@ -24,7 +26,9 @@ module RuboCop return unless in_routes?(node) return unless leading_slash_in_redirect?(node) - add_offense(node) + add_offense(node) do |corrector| + corrector.replace(node.loc.expression, remove_leading_slash(node)) + end end def has_leading_slash?(str) @@ -38,12 +42,6 @@ module RuboCop dirname.end_with?('config/routes') || filename.end_with?('routes.rb') end - def autocorrect(node) - lambda do |corrector| - corrector.replace(node.loc.expression, remove_leading_slash(node)) - end - end - def remove_leading_slash(node) node.source.sub('/', '') end |