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/project_path_helper.rb | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'rubocop/cop/project_path_helper.rb')
-rw-r--r-- | rubocop/cop/project_path_helper.rb | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/rubocop/cop/project_path_helper.rb b/rubocop/cop/project_path_helper.rb index 0d12f2d2b12..104a352949f 100644 --- a/rubocop/cop/project_path_helper.rb +++ b/rubocop/cop/project_path_helper.rb @@ -2,7 +2,9 @@ module RuboCop module Cop - class ProjectPathHelper < RuboCop::Cop::Cop + class ProjectPathHelper < RuboCop::Cop::Base + extend RuboCop::Cop::AutoCorrector + MSG = 'Use short project path helpers without explicitly passing the namespace: ' \ '`foo_project_bar_path(project, bar)` instead of ' \ '`foo_namespace_project_bar_path(project.namespace, project, bar)`.' @@ -19,18 +21,14 @@ module RuboCop return unless method_name(namespace_expr) == :namespace return unless receiver(namespace_expr) == project_expr - add_offense(node, location: :selector) - end - - def autocorrect(node) - helper_name = method_name(node).to_s.sub('namespace_project', 'project') + add_offense(node.loc.selector) do |corrector| + helper_name = method_name(node).to_s.sub('namespace_project', 'project') - arguments = arguments(node) - arguments.shift # Remove namespace argument + arguments = arguments(node) + arguments.shift # Remove namespace argument - replacement = "#{helper_name}(#{arguments.map(&:source).join(', ')})" + replacement = "#{helper_name}(#{arguments.map(&:source).join(', ')})" - lambda do |corrector| corrector.replace(node.source_range, replacement) end end |