diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
commit | b39512ed755239198a9c294b6a45e65c05900235 (patch) | |
tree | d234a3efade1de67c46b9e5a38ce813627726aa7 /rubocop/formatter | |
parent | d31474cf3b17ece37939d20082b07f6657cc79a9 (diff) |
Add latest changes from gitlab-org/gitlab@15-3-stable-eev15.3.0-rc42
Diffstat (limited to 'rubocop/formatter')
-rw-r--r-- | rubocop/formatter/todo_formatter.rb | 48 |
1 files changed, 4 insertions, 44 deletions
diff --git a/rubocop/formatter/todo_formatter.rb b/rubocop/formatter/todo_formatter.rb index 662cc1551ff..789d0418f96 100644 --- a/rubocop/formatter/todo_formatter.rb +++ b/rubocop/formatter/todo_formatter.rb @@ -5,6 +5,7 @@ require 'rubocop' require 'yaml' require_relative '../todo_dir' +require_relative '../cop_todo' module RuboCop module Formatter @@ -14,26 +15,6 @@ module RuboCop # For example, this formatter stores offenses for `RSpec/VariableName` # in `.rubocop_todo/rspec/variable_name.yml`. class TodoFormatter < BaseFormatter - class Todo - attr_reader :cop_name, :files, :offense_count - - def initialize(cop_name) - @cop_name = cop_name - @files = Set.new - @offense_count = 0 - @cop_class = RuboCop::Cop::Registry.global.find_by_cop_name(cop_name) - end - - def record(file, offense_count) - @files << file - @offense_count += offense_count - end - - def autocorrectable? - @cop_class&.support_autocorrect? - end - end - DEFAULT_BASE_DIRECTORY = File.expand_path('../../.rubocop_todo', __dir__) class << self @@ -44,7 +25,7 @@ module RuboCop def initialize(output, _options = {}) @directory = self.class.base_directory - @todos = Hash.new { |hash, cop_name| hash[cop_name] = Todo.new(cop_name) } + @todos = Hash.new { |hash, cop_name| hash[cop_name] = CopTodo.new(cop_name) } @todo_dir = TodoDir.new(directory) @config_inspect_todo_dir = load_config_inspect_todo_dir @config_old_todo_yml = load_config_old_todo_yml @@ -65,8 +46,8 @@ module RuboCop def finished(_inspected_files) @todos.values.sort_by(&:cop_name).each do |todo| - yaml = to_yaml(todo) - path = @todo_dir.write(todo.cop_name, yaml) + todo.previously_disabled = previously_disabled?(todo) + path = @todo_dir.write(todo.cop_name, todo.to_yaml) output.puts "Written to #{relative_path(path)}\n" end @@ -90,27 +71,6 @@ module RuboCop path.delete_prefix("#{parent}/") end - def to_yaml(todo) - yaml = [] - yaml << '---' - yaml << '# Cop supports --auto-correct.' if todo.autocorrectable? - yaml << "#{todo.cop_name}:" - - if previously_disabled?(todo) - yaml << " # Offense count: #{todo.offense_count}" - yaml << ' # Temporarily disabled due to too many offenses' - yaml << ' Enabled: false' - end - - yaml << ' Exclude:' - - files = todo.files.sort.map { |file| " - '#{file}'" } - yaml.concat files - yaml << '' - - yaml.join("\n") - end - def check_multiple_configurations! cop_names = @config_inspect_todo_dir.keys & @config_old_todo_yml.keys return if cop_names.empty? |