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

grape_api_instance.rb « api « cop « rubocop - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: de11b9ef3f6e18b1165097e556f8940d0e0b9dda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# frozen_string_literal: true

module RuboCop
  module Cop
    module API
      class GrapeAPIInstance < RuboCop::Cop::Cop
        # This cop checks that APIs subclass Grape::API::Instance with Grape v1.3+.
        #
        # @example
        #
        # # bad
        # module API
        #   class Projects < Grape::API
        #   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.'

        def_node_matcher :grape_api_definition, <<~PATTERN
          (class
            (const _ _)
            (const
              (const nil? :Grape) :API)
            ...
          )
        PATTERN

        def on_class(node)
          grape_api_definition(node) do
            add_offense(node.children[1])
          end
        end
      end
    end
  end
end