lib/rubocop/cop/cop.rb in rubocop-0.13.1 vs lib/rubocop/cop/cop.rb in rubocop-0.14.0
- old
+ new
@@ -91,33 +91,36 @@
def cop_config
@config.for_cop(self)
end
def autocorrect?
- @options[:autocorrect]
+ @options[:autocorrect] && support_autocorrect?
end
def debug?
@options[:debug]
end
- def autocorrect_action(node)
- end
-
def message(node = nil)
self.class::MSG
end
+ def support_autocorrect?
+ respond_to?(:autocorrect, true)
+ end
+
def add_offence(severity, node, loc, message = nil)
location = loc.is_a?(Symbol) ? node.loc.send(loc) : loc
- unless disabled_line?(location.line)
- message = message ? message : message(node)
- message = debug? ? "#{name}: #{message}" : message
- @offences << Offence.new(severity, location, message, name)
- autocorrect_action(node) if autocorrect?
- end
+ return if disabled_line?(location.line)
+
+ message = message ? message : message(node)
+ message = debug? ? "#{name}: #{message}" : message
+ @offences <<
+ Offence.new(severity, location, message, name, autocorrect?)
+
+ autocorrect(node) if autocorrect?
end
def convention(node, location, message = nil)
add_offence(:convention, node, location, message)
end
@@ -156,10 +159,10 @@
false
end
def ignored_node?(node)
- @ignored_nodes.include?(node)
+ @ignored_nodes.any? { |n| n.eql?(node) } # Same object found in array?
end
def on_node(syms, sexp, excludes = [])
yield sexp if Array(syms).include?(sexp.type)