diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-14 21:10:12 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-14 21:10:12 +0000 |
commit | 7f35b02e86cd3d2e8b4a81c5c3a8483ff6973c5a (patch) | |
tree | 958f0603e4d8d0bcd5a5fa2e0a006b6f1b280068 /rubocop | |
parent | 3244feeb4f1980251fd9ff6cc263e34072fbf7c7 (diff) | |
download | gitlab-ce-7f35b02e86cd3d2e8b4a81c5c3a8483ff6973c5a.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r-- | rubocop/cop/api/ensure_string_detail.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/rubocop/cop/api/ensure_string_detail.rb b/rubocop/cop/api/ensure_string_detail.rb new file mode 100644 index 00000000000..bc999525055 --- /dev/null +++ b/rubocop/cop/api/ensure_string_detail.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +require_relative '../../code_reuse_helpers' + +module RuboCop + module Cop + module API + class EnsureStringDetail < RuboCop::Cop::Base + include CodeReuseHelpers + + # This cop checks that API detail entries use Strings + # + # https://gitlab.com/gitlab-org/gitlab/-/issues/379037 + # + # @example + # + # # bad + # detail ['Foo bar baz bat', 'http://example.com'] + # + # # good + # detail 'Foo bar baz bat. http://example.com' + # + # end + # + MSG = 'Only String objects are permitted in API detail field.' + + def_node_matcher :detail_in_desc, <<~PATTERN + (block + (send nil? :desc ...) + _args + `(send nil? :detail $_ ...) + ) + PATTERN + + RESTRICT_ON_SEND = %i[detail].freeze + + def on_send(node) + return unless in_api?(node) + + parent = node.each_ancestor(:block).first + detail_arg = detail_in_desc(parent) + + return unless detail_arg + return if [:str, :dstr].include?(detail_arg.type) + + add_offense(node) + end + end + end + end +end |