Sha256: 171ab78e913188300d5c571f048a0170c4e80ab9086bd1d805bd25ab5b735bf0

Contents?: true

Size: 1.13 KB

Versions: 5

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require 'rubocop-rspec'

module Gitlab
  module Styles
    module Rubocop
      module Cop
        module RSpec
          # This cop checks for unused parameters to the `have_link` matcher.
          #
          # @example
          #
          #   # bad
          #   expect(page).to have_link('Link', 'https://example.com')
          #
          #   # good
          #   expect(page).to have_link('Link', href: 'https://example.com')
          #   expect(page).to have_link('Example')
          class HaveLinkParameters < RuboCop::Cop::RSpec::Cop
            MESSAGE = "The second argument to `have_link` should be a Hash."

            def_node_matcher :unused_parameters?, <<~PATTERN
              (send nil? :have_link
                _ !{hash nil}
              )
            PATTERN

            def on_send(node)
              return unless unused_parameters?(node)

              location = node.arguments[1..-1]
                .map(&:source_range)
                .reduce(:join)

              add_offense(node, location: location, message: MESSAGE)
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gitlab-styles-4.3.0 lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb
gitlab-styles-4.2.0 lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb
gitlab-styles-4.1.0 lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb
gitlab-styles-4.0.0 lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb
gitlab-styles-3.4.0 lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb