diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 09:07:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 09:07:11 +0300 |
commit | 75621c94b5dbe233edd72c3d8cc602fed25e84d2 (patch) | |
tree | a38d832241e66a2e296e276493bff0260bfc9712 /rubocop/node_pattern_helper.rb | |
parent | 9bf8cb8d34039f3cef9e1b2f812ce634f2bebe69 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop/node_pattern_helper.rb')
-rw-r--r-- | rubocop/node_pattern_helper.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/rubocop/node_pattern_helper.rb b/rubocop/node_pattern_helper.rb new file mode 100644 index 00000000000..ecd4560763c --- /dev/null +++ b/rubocop/node_pattern_helper.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module RuboCop + module NodePatternHelper + # Returns a nested `(const ...)` node pattern for a full qualified +name+. + # + # @examples + # const_pattern 'Foo::Bar' # => (const (const {nil? cbase} :Foo) :Bar) + # const_pattern 'Foo::Bar', parent: ':Baz' # => (const (const :Baz :Foo) :Bar) + def const_pattern(name, parent: '{nil? cbase}') + name.split('::').inject(parent) { |memo, name_part| "(const #{memo} :#{name_part})" } + end + end +end |