lib/rubocop/cop/cop.rb in rubocop-0.20.1 vs lib/rubocop/cop/cop.rb in rubocop-0.21.0

- old
+ new

@@ -1,9 +1,11 @@ # encoding: utf-8 module Rubocop module Cop + class CorrectionNotPossible < Exception; end + # Store for all cops with helper functions class CopStore < ::Array # @return [Array<String>] list of types for current cops. def types @types = map(&:cop_type).uniq! unless defined? @types @@ -84,10 +86,14 @@ @offenses = [] @corrections = [] end + def join_force?(_force_class) + false + end + def cop_config @config.for_cop(self) end def autocorrect? @@ -100,11 +106,11 @@ def display_cop_names? debug? || @options[:display_cop_names] end - def message(node = nil) + def message(_node = nil) self.class::MSG end def support_autocorrect? respond_to?(:autocorrect, true) @@ -121,13 +127,17 @@ severity = custom_severity || severity || default_severity message ||= message(node) message = display_cop_names? ? "#{name}: #{message}" : message - autocorrect(node) if autocorrect? - @offenses << Offense.new(severity, location, message, name, - autocorrect?) + corrected = begin + autocorrect(node) if autocorrect? + autocorrect? + rescue CorrectionNotPossible + false + end + @offenses << Offense.new(severity, location, message, name, corrected) yield if block_given? end def config_to_allow_offenses Formatter::DisabledConfigFormatter.config_to_allow_offenses[cop_name] @@ -160,10 +170,12 @@ def file_name_matches_any?(file, parameter, default_result) patterns = cop_config && cop_config[parameter] return default_result unless patterns path = config.path_relative_to_config(file) - patterns.any? { |pattern| match_path?(pattern, path) } + patterns.any? do |pattern| + match_path?(pattern, path, config.loaded_path) + end end def enabled_line?(line_number) return true unless @processed_source @processed_source.comment_config