Last active
February 26, 2019 10:18
-
-
Save DmytroVasin/984875c24ebe9075ab93d928f1c68c0c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RuboCop | |
module Cop | |
module CustomCops | |
class TimecopReplacerCop < Cop | |
MSG = 'Broken rule'.freeze | |
def on_send(node) | |
return unless [:describe, :context, :it, :xit, :it_behaves_like].include?(node.method_name) | |
return unless node.last_argument&.hash_type? # Syntax: "it { is_expected.to be true }" | |
node.last_argument.each_child_node { |arg| parse_argum(arg) } | |
end | |
private | |
def parse_argum(arg_pair) | |
key_node = arg_pair.key | |
value_node = arg_pair.value | |
return unless [:freezed_date, :freezed_time].include?(key_node.value) | |
return unless value_node.send_type? # Value is a method | |
add_offense(arg_pair, location: :expression) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment