2017-03-02 20:26:29 +05:30
|
|
|
require_relative "./extend/formula_cop"
|
|
|
|
|
2017-01-18 15:54:47 +05:30
|
|
|
module RuboCop
|
|
|
|
module Cop
|
2017-04-23 04:09:13 +05:30
|
|
|
module FormulaAuditStrict
|
2017-03-02 20:26:29 +05:30
|
|
|
# This cop audits `bottle` block in Formulae
|
|
|
|
#
|
|
|
|
# - `rebuild` should be used instead of `revision` in `bottle` block
|
2017-01-18 15:54:47 +05:30
|
|
|
|
2017-05-03 11:33:00 +05:30
|
|
|
class BottleBlock < FormulaCop
|
2017-03-02 20:26:29 +05:30
|
|
|
MSG = "Use rebuild instead of revision in bottle block".freeze
|
2017-01-18 15:54:47 +05:30
|
|
|
|
2017-06-19 00:36:18 -04:00
|
|
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
|
|
|
bottle = find_block(body_node, :bottle)
|
2017-03-16 23:49:43 +05:30
|
|
|
return if bottle.nil? || block_size(bottle).zero?
|
2017-04-08 15:10:44 +05:30
|
|
|
problem "Use rebuild instead of revision in bottle block" if method_called_in_block?(bottle, :revision)
|
2017-01-18 15:54:47 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def autocorrect(node)
|
2017-01-18 15:55:32 +05:30
|
|
|
lambda do |corrector|
|
2017-01-18 22:37:11 +05:30
|
|
|
correction = node.source.sub("revision", "rebuild")
|
|
|
|
corrector.insert_before(node.source_range, correction)
|
|
|
|
corrector.remove(node.source_range)
|
2017-01-18 15:54:47 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|