aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/rubocops/conflicts_cop.rb
blob: 96edf480cd1b110abad4bdd54a8382d72fbcce6b (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
require_relative "./extend/formula_cop"
require_relative "../extend/string"

module RuboCop
  module Cop
    module FormulaAudit
      # This cop audits versioned Formulae for `conflicts_with`
      class Conflicts < FormulaCop
        MSG = "Versioned formulae should not use `conflicts_with`. " \
              "Use `keg_only :versioned_formula` instead.".freeze

        WHITELIST = %w[
          node@
          bash-completion@
        ].freeze

        def audit_formula(_node, _class_node, _parent_class_node, body)
          return unless versioned_formula?
          problem MSG if !@formula_name.start_with?(*WHITELIST) &&
                         method_called_ever?(body, :conflicts_with)
        end
      end
    end
  end
end