Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-10-15 03:08:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-10-15 03:08:42 +0300
commit6a0085290e97f344d3ed69463c8a1f729a337bc4 (patch)
tree792f6edfaf71b3b331604a6561860eb988df8291 /rubocop
parent5c635722c66a32e170c3ba8150bc303124abb7a1 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/api/base.rb (renamed from rubocop/cop/api/grape_api_instance.rb)25
1 files changed, 18 insertions, 7 deletions
diff --git a/rubocop/cop/api/grape_api_instance.rb b/rubocop/cop/api/base.rb
index de11b9ef3f6..85b19e9a833 100644
--- a/rubocop/cop/api/grape_api_instance.rb
+++ b/rubocop/cop/api/base.rb
@@ -3,8 +3,8 @@
module RuboCop
module Cop
module API
- class GrapeAPIInstance < RuboCop::Cop::Cop
- # This cop checks that APIs subclass Grape::API::Instance with Grape v1.3+.
+ class Base < RuboCop::Cop::Cop
+ # This cop checks that APIs subclass API::Base.
#
# @example
#
@@ -14,19 +14,24 @@ module RuboCop
# end
# end
#
- # # good
# module API
# class Projects < Grape::API::Instance
# end
# end
- MSG = 'Inherit from Grape::API::Instance instead of Grape::API. ' \
- 'For more details check the https://gitlab.com/gitlab-org/gitlab/-/issues/215230.'
+ #
+ # # good
+ # module API
+ # class Projects < ::API::Base
+ # end
+ # end
+ MSG = 'Inherit from ::API::Base instead of Grape::API::Instance or Grape::API. ' \
+ 'For more details check https://gitlab.com/gitlab-org/gitlab/-/issues/215230.'
+ def_node_matcher :grape_api, '(const (const {nil? (cbase)} :Grape) :API)'
def_node_matcher :grape_api_definition, <<~PATTERN
(class
(const _ _)
- (const
- (const nil? :Grape) :API)
+ {#grape_api (const #grape_api :Instance)}
...
)
PATTERN
@@ -36,6 +41,12 @@ module RuboCop
add_offense(node.children[1])
end
end
+
+ def autocorrect(node)
+ lambda do |corrector|
+ corrector.replace(node, '::API::Base')
+ end
+ end
end
end
end