diff options
Diffstat (limited to 'rubocop')
-rw-r--r-- | rubocop/cop/inject_enterprise_edition_module.rb | 2 | ||||
-rw-r--r-- | rubocop/cop/rspec/be_success_matcher.rb | 53 | ||||
-rw-r--r-- | rubocop/cop/scalability/file_uploads.rb | 61 | ||||
-rw-r--r-- | rubocop/rubocop.rb | 2 |
4 files changed, 117 insertions, 1 deletions
diff --git a/rubocop/cop/inject_enterprise_edition_module.rb b/rubocop/cop/inject_enterprise_edition_module.rb index e0e1b2d6c7d..6f007e667f2 100644 --- a/rubocop/cop/inject_enterprise_edition_module.rb +++ b/rubocop/cop/inject_enterprise_edition_module.rb @@ -24,7 +24,7 @@ module RuboCop # We use `match?` here instead of RuboCop's AST matching, as this makes # it far easier to handle nested constants such as `EE::Foo::Bar::Baz`. - line.match?(/(\s|\()('|")?(::)?EE::/) + line.match?(/(\s|\()('|")?(::)?(QA::)?EE::/) end def on_send(node) diff --git a/rubocop/cop/rspec/be_success_matcher.rb b/rubocop/cop/rspec/be_success_matcher.rb new file mode 100644 index 00000000000..dce9604b3d7 --- /dev/null +++ b/rubocop/cop/rspec/be_success_matcher.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + module RSpec + # This cop checks for `be_success` usage in controller specs + # + # @example + # + # # bad + # it "responds with success" do + # expect(response).to be_success + # end + # + # it { is_expected.to be_success } + # + # # good + # it "responds with success" do + # expect(response).to be_successful + # end + # + # it { is_expected.to be_successful } + # + class BeSuccessMatcher < RuboCop::Cop::Cop + MESSAGE = 'Do not use deprecated `success?` method, use `successful?` instead.' + + def_node_search :expect_to_be_success?, <<~PATTERN + (send (send nil? :expect (send nil? ...)) {:to :not_to :to_not} (send nil? :be_success)) + PATTERN + + def_node_search :is_expected_to_be_success?, <<~PATTERN + (send (send nil? :is_expected) {:to :not_to :to_not} (send nil? :be_success)) + PATTERN + + def be_success_usage?(node) + expect_to_be_success?(node) || is_expected_to_be_success?(node) + end + + def on_send(node) + return unless be_success_usage?(node) + + add_offense(node, location: :expression, message: MESSAGE) + end + + def autocorrect(node) + lambda do |corrector| + corrector.insert_after(node.loc.expression, 'ful') + end + end + end + end + end +end diff --git a/rubocop/cop/scalability/file_uploads.rb b/rubocop/cop/scalability/file_uploads.rb new file mode 100644 index 00000000000..83017217e32 --- /dev/null +++ b/rubocop/cop/scalability/file_uploads.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + module Scalability + # This cop checks for `File` params in API + # + # @example + # + # # bad + # params do + # requires :file, type: File + # end + # + # params do + # optional :file, type: File + # end + # + # # good + # params do + # requires :file, type: ::API::Validations::Types::WorkhorseFile + # end + # + # params do + # optional :file, type: ::API::Validations::Types::WorkhorseFile + # end + # + class FileUploads < RuboCop::Cop::Cop + MSG = 'Do not upload files without workhorse acceleration. Please refer to https://docs.gitlab.com/ee/development/uploads.html' + + def_node_search :file_type_params?, <<~PATTERN + (send nil? {:requires :optional} (sym _) (hash <(pair (sym :type)(const nil? :File)) ...>)) + PATTERN + + def_node_search :file_types_params?, <<~PATTERN + (send nil? {:requires :optional} (sym _) (hash <(pair (sym :types)(array <(const nil? :File) ...>)) ...>)) + PATTERN + + def be_file_param_usage?(node) + file_type_params?(node) || file_types_params?(node) + end + + def on_send(node) + return unless be_file_param_usage?(node) + + add_offense(find_file_param(node), location: :expression) + end + + private + + def find_file_param(node) + node.each_descendant.find { |children| file_node_pattern.match(children) } + end + + def file_node_pattern + @file_node_pattern ||= RuboCop::NodePattern.new("(const nil? :File)") + end + end + end + end +end diff --git a/rubocop/rubocop.rb b/rubocop/rubocop.rb index d1328c4eb38..9d97aa86bf6 100644 --- a/rubocop/rubocop.rb +++ b/rubocop/rubocop.rb @@ -31,11 +31,13 @@ require_relative 'cop/migration/timestamps' require_relative 'cop/migration/update_column_in_batches' require_relative 'cop/migration/update_large_table' require_relative 'cop/project_path_helper' +require_relative 'cop/rspec/be_success_matcher' require_relative 'cop/rspec/env_assignment' require_relative 'cop/rspec/factories_in_migration_specs' require_relative 'cop/rspec/top_level_describe_path' require_relative 'cop/qa/element_with_pattern' require_relative 'cop/sidekiq_options_queue' +require_relative 'cop/scalability/file_uploads' require_relative 'cop/destroy_all' require_relative 'cop/ruby_interpolation_in_translation' require_relative 'code_reuse_helpers' |