aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/rubocops/bottle_block_cop.rb
blob: 3cfde01ad6b70302ed0e35af7a47cf32c969b9cb (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
require_relative "./extend/formula_cop"

module RuboCop
  module Cop
    module FormulaAuditStrict
      # This cop audits `bottle` block in Formulae
      #
      # - `rebuild` should be used instead of `revision` in `bottle` block

      class BottleBlock < FormulaCop
        MSG = "Use rebuild instead of revision in bottle block".freeze

        def audit_formula(_node, _class_node, _parent_class_node, body_node)
          bottle = find_block(body_node, :bottle)
          return if bottle.nil? || block_size(bottle).zero?
          problem "Use rebuild instead of revision in bottle block" if method_called_in_block?(bottle, :revision)
        end

        def autocorrect(node)
          lambda do |corrector|
            correction = node.source.sub("revision", "rebuild")
            corrector.insert_before(node.source_range, correction)
            corrector.remove(node.source_range)
          end
        end
      end
    end
  end
end