2022-08-27 11:52:29 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
require_relative 'formatter/graceful_formatter'
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
module RuboCop
|
|
|
|
class CopTodo
|
2022-10-11 01:57:18 +05:30
|
|
|
attr_accessor :previously_disabled, :grace_period
|
2022-08-27 11:52:29 +05:30
|
|
|
|
|
|
|
attr_reader :cop_name, :files, :offense_count
|
|
|
|
|
|
|
|
def initialize(cop_name)
|
|
|
|
@cop_name = cop_name
|
|
|
|
@files = Set.new
|
|
|
|
@offense_count = 0
|
|
|
|
@cop_class = self.class.find_cop_by_name(cop_name)
|
|
|
|
@previously_disabled = false
|
2022-10-11 01:57:18 +05:30
|
|
|
@grace_period = false
|
2022-08-27 11:52:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def record(file, offense_count)
|
|
|
|
@files << file
|
|
|
|
@offense_count += offense_count
|
|
|
|
end
|
|
|
|
|
|
|
|
def autocorrectable?
|
|
|
|
@cop_class&.support_autocorrect?
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_yaml
|
|
|
|
yaml = []
|
|
|
|
yaml << '---'
|
|
|
|
yaml << '# Cop supports --auto-correct.' if autocorrectable?
|
|
|
|
yaml << "#{cop_name}:"
|
|
|
|
|
|
|
|
if previously_disabled
|
|
|
|
yaml << " # Offense count: #{offense_count}"
|
|
|
|
yaml << ' # Temporarily disabled due to too many offenses'
|
|
|
|
yaml << ' Enabled: false'
|
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
yaml << " #{RuboCop::Formatter::GracefulFormatter.grace_period_key_value}" if grace_period
|
2022-08-27 11:52:29 +05:30
|
|
|
yaml << ' Exclude:'
|
|
|
|
yaml.concat files.sort.map { |file| " - '#{file}'" }
|
|
|
|
yaml << ''
|
|
|
|
|
|
|
|
yaml.join("\n")
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.find_cop_by_name(cop_name)
|
|
|
|
RuboCop::Cop::Registry.global.find_by_cop_name(cop_name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|