diff --git a/lib/rubocop.rb b/lib/rubocop.rb index 7809089beec..60717410ba9 100644 --- a/lib/rubocop.rb +++ b/lib/rubocop.rb @@ -586,7 +586,6 @@ # relies on simple text require_relative 'rubocop/formatter/clang_style_formatter' require_relative 'rubocop/formatter/disabled_config_formatter' -require_relative 'rubocop/formatter/disabled_lines_formatter' require_relative 'rubocop/formatter/emacs_style_formatter' require_relative 'rubocop/formatter/file_list_formatter' require_relative 'rubocop/formatter/fuubar_style_formatter' diff --git a/lib/rubocop/formatter/disabled_lines_formatter.rb b/lib/rubocop/formatter/disabled_lines_formatter.rb deleted file mode 100644 index 5e9e0017247..00000000000 --- a/lib/rubocop/formatter/disabled_lines_formatter.rb +++ /dev/null @@ -1,57 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Formatter - # A basic formatter that displays the lines disabled - # inline comments. - class DisabledLinesFormatter < BaseFormatter - include PathUtil - include Colorizable - - attr_reader :cop_disabled_line_ranges - - def started(_target_files) - @cop_disabled_line_ranges = {} - end - - def file_started(file, options) - return unless options[:cop_disabled_line_ranges] - - @cop_disabled_line_ranges[file] = - options[:cop_disabled_line_ranges] - end - - def finished(_inspected_files) - cops_disabled_in_comments_summary - end - - private - - def cops_disabled_in_comments_summary - summary = "\nCops disabled line ranges:\n\n" - - @cop_disabled_line_ranges.each do |file, disabled_cops| - disabled_cops.each do |cop, line_ranges| - line_ranges.each do |line_range| - file = cyan(smart_path(file)) - summary += "#{file}:#{line_range}: #{cop}\n" - end - end - end - - output.puts summary - end - - def smart_path(path) - # Ideally, we calculate this relative to the project root. - base_dir = Dir.pwd - - if path.start_with? base_dir - relative_path(path, base_dir) - else - path - end - end - end - end -end diff --git a/lib/rubocop/formatter/formatter_set.rb b/lib/rubocop/formatter/formatter_set.rb index 08e83de3357..f85bf17acd3 100644 --- a/lib/rubocop/formatter/formatter_set.rb +++ b/lib/rubocop/formatter/formatter_set.rb @@ -11,7 +11,6 @@ class FormatterSet < Array BUILTIN_FORMATTERS_FOR_KEYS = { '[a]utogenconf' => AutoGenConfigFormatter, '[c]lang' => ClangStyleFormatter, - '[d]isabled' => DisabledLinesFormatter, '[e]macs' => EmacsStyleFormatter, '[fi]les' => FileListFormatter, '[fu]ubar' => FuubarStyleFormatter, diff --git a/spec/rubocop/formatter/disabled_lines_formatter_spec.rb b/spec/rubocop/formatter/disabled_lines_formatter_spec.rb deleted file mode 100644 index d10c01c3349..00000000000 --- a/spec/rubocop/formatter/disabled_lines_formatter_spec.rb +++ /dev/null @@ -1,83 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe RuboCop::Formatter::DisabledLinesFormatter do - subject(:formatter) { described_class.new(output) } - - let(:output) { StringIO.new } - - let(:files) do - %w[lib/rubocop.rb spec/spec_helper.rb exe/rubocop].map do |path| - File.expand_path(path) - end - end - - let(:file_started) do - formatter.file_started(files.first, cop_disabled_line_ranges) - end - - describe '#file_started' do - before { formatter.started(files) } - - context 'when no disable cop comments are detected' do - let(:cop_disabled_line_ranges) { {} } - - it 'does not add to cop_disabled_line_ranges' do - expect { file_started }.not_to( - change(formatter, :cop_disabled_line_ranges) - ) - end - end - - context 'when any disable cop comments are detected' do - let(:cop_disabled_line_ranges) do - { cop_disabled_line_ranges: { 'LineLength' => [1..1] } } - end - - it 'merges the changes into cop_disabled_line_ranges' do - expect { file_started }.to( - change(formatter, :cop_disabled_line_ranges) - ) - end - end - end - - describe '#finished' do - context 'when there disabled cops detected' do - let(:cop_disabled_line_ranges) do - { - cop_disabled_line_ranges: { - 'LineLength' => [1..1], - 'ClassLength' => [1..Float::INFINITY] - } - } - end - let(:offenses) do - [ - RuboCop::Cop::Offense.new(:convention, location, 'Class too long.', - 'ClassLength', :disabled), - RuboCop::Cop::Offense.new(:convention, location, 'Line too long.', - 'LineLength', :uncorrected) - ] - end - let(:location) { OpenStruct.new(line: 3) } - - before do - formatter.started(files) - formatter.file_started('lib/rubocop.rb', cop_disabled_line_ranges) - formatter.file_finished('lib/rubocop.rb', offenses) - end - - it 'lists disabled cops by file' do - formatter.finished(files) - expect(output.string) - .to eq(<<~OUTPUT) - - Cops disabled line ranges: - - lib/rubocop.rb:1..1: LineLength - lib/rubocop.rb:1..Infinity: ClassLength - OUTPUT - end - end - end -end diff --git a/spec/rubocop/options_spec.rb b/spec/rubocop/options_spec.rb index 505367cf633..04f96de1da5 100644 --- a/spec/rubocop/options_spec.rb +++ b/spec/rubocop/options_spec.rb @@ -71,7 +71,6 @@ def abs(path) [p]rogress is used by default [a]utogenconf [c]lang - [d]isabled [e]macs [fi]les [fu]ubar