lib/rubocop/comment_config.rb in rubocop-0.35.1 vs lib/rubocop/comment_config.rb in rubocop-0.36.0

- old
+ new

@@ -1,12 +1,13 @@ # encoding: utf-8 +# frozen_string_literal: true 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' + UNNEEDED_DISABLE = 'Lint/UnneededDisable'.freeze COMMENT_DIRECTIVE_REGEXP = Regexp.new( '\A# rubocop : ((?:dis|en)able)\b ((?:[\w/]+,? )+)'.gsub(' ', '\s*') ) attr_reader :processed_source @@ -33,10 +34,16 @@ each_mentioned_cop do |cop_name, disabled, line, single_line| if single_line disabled_line_ranges[cop_name] << (line..line) if disabled elsif disabled + if disablement_start_line_numbers[cop_name] + # Cop already disabled on this line, so we end the current disabled + # range before we start a new range. + start_line = disablement_start_line_numbers.delete(cop_name) + disabled_line_ranges[cop_name] << (start_line..line) + end disablement_start_line_numbers[cop_name] = line else start_line = disablement_start_line_numbers.delete(cop_name) disabled_line_ranges[cop_name] << (start_line..line) if start_line end @@ -64,10 +71,10 @@ disabled = (switch == 'disable') comment_line_number = comment.loc.expression.line single_line = !comment_only_line?(comment_line_number) cop_names.each do |cop_name| - cop_name = Cop::Cop.qualified_cop_name(cop_name, + cop_name = Cop::Cop.qualified_cop_name(cop_name.strip, processed_source.buffer.name) yield cop_name, disabled, comment_line_number, single_line end end end