Sha256: 3810580ed1dd6cee6f1249a5462e28b8d19eef9f7ff318c89c54edb50b2602a0

Contents?: true

Size: 1.28 KB

Versions: 15

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

require 'rubocop-rspec'
require_relative 'base'

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 < Base
            extend RuboCop::Cop::AutoCorrector

            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..]
                           .map(&:source_range)
                           .reduce(:join)

              add_offense(location, message: MESSAGE) do |corrector|
                corrector.insert_after(location.end, "\n")
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
gitlab-styles-7.1.0 lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb
gitlab-styles-7.0.0 lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb
gitlab-styles-6.6.0 lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb
gitlab-styles-6.5.0 lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb
gitlab-styles-6.4.0 lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb
gitlab-styles-6.3.0 lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb
gitlab-styles-6.2.1 lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb
gitlab-styles-6.2.0 lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb
gitlab-styles-6.1.0 lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb
gitlab-styles-6.0.0 lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb
gitlab-styles-5.4.0 lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb
gitlab-styles-5.3.0 lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb
gitlab-styles-5.2.0 lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb
gitlab-styles-5.1.0 lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb
gitlab-styles-5.0.0 lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb