lib/rubocop/comment_config.rb in rubocop-0.52.1 vs lib/rubocop/comment_config.rb in rubocop-0.53.0

- old
+ new

@@ -2,11 +2,11 @@ module RuboCop # This class parses the special `rubocop:disable` comments in a source # and provides a way to check if each cop is enabled at arbitrary line. class CommentConfig - UNNEEDED_DISABLE = 'Lint/UnneededDisable'.freeze + UNNEEDED_DISABLE = 'Lint/UnneededCopDisableDirective'.freeze COP_NAME_PATTERN = '([A-Z]\w+/)?(?:[A-Z]\w+)'.freeze COP_NAMES_PATTERN = "(?:#{COP_NAME_PATTERN} , )*#{COP_NAME_PATTERN}".freeze COPS_PATTERN = "(all|#{COP_NAMES_PATTERN})".freeze @@ -32,12 +32,33 @@ def cop_disabled_line_ranges @cop_disabled_line_ranges ||= analyze end + def extra_enabled_comments + extra_enabled_comments_with_names([], {}) + end + private + def extra_enabled_comments_with_names(extras, names) + each_directive do |comment, cop_names, disabled| + next unless comment_only_line?(comment.loc.expression.line) + cop_names.each do |name| + names[name] ||= 0 + if disabled + names[name] += 1 + elsif names[name] > 0 + names[name] -= 1 + else + extras << [comment, name] + end + end + end + extras + end + def analyze analyses = Hash.new { |hash, key| hash[key] = CopAnalysis.new([], nil) } each_mentioned_cop do |cop_name, disabled, line, single_line| analyses[cop_name] = @@ -104,11 +125,11 @@ end def each_directive return if processed_source.comments.nil? - processed_source.comments.each do |comment| + processed_source.each_comment do |comment| directive = directive_parts(comment) next unless directive yield comment, *directive end @@ -127,10 +148,10 @@ [cop_names, disabled] end def qualified_cop_name(cop_name) - Cop::Cop.qualified_cop_name(cop_name.strip, processed_source.buffer.name) + Cop::Cop.qualified_cop_name(cop_name.strip, processed_source.file_path) end def all_cop_names @all_cop_names ||= Cop::Cop.registry.names - [UNNEEDED_DISABLE] end