Class: RuboCop::Formatter::SimpleTextFormatter
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
BaseFormatter
|
|
Instance Chain:
|
|
Inherits: |
RuboCop::Formatter::BaseFormatter
|
Defined in: | lib/rubocop/formatter/simple_text_formatter.rb |
Overview
A basic formatter that displays only files with offenses. Offenses are displayed at compact form - just the location of the problem and the associated message.
Constant Summary
-
COLOR_FOR_SEVERITY =
# File 'lib/rubocop/formatter/simple_text_formatter.rb', line 14{ info: :gray, refactor: :yellow, convention: :yellow, warning: :magenta, error: :red, fatal: :red }.freeze
::RuboCop::PathUtil
- Included
Class Method Summary
BaseFormatter
- Inherited
Instance Attribute Summary
BaseFormatter
- Inherited
Instance Method Summary
- #file_finished(file, offenses)
- #finished(inspected_files)
- #report_file(file, offenses)
- #report_summary(file_count, offense_count, correction_count, correctable_count)
- #started(_target_files)
- #annotate_message(msg) private
- #colored_severity_code(offense) private
- #count_stats(offenses) private
- #message(offense) private
::RuboCop::PathUtil
- Included
#absolute? | Returns true for an absolute Unix or Windows path. |
#glob? | Returns true for a glob. |
#hidden_dir?, #hidden_file?, #hidden_file_in_not_hidden_dir?, | |
#match_path? | Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity. |
#maybe_hidden_file? | Loose check to reduce memory allocations. |
#relative_path, #smart_path |
Colorizable
- Included
BaseFormatter
- Inherited
#file_finished | Invoked at the end of inspecting each files. |
#file_started | Invoked at the beginning of inspecting each files. |
#finished | Invoked after all files are inspected or interrupted by user. |
#started | Invoked once before any files are inspected. |
Constructor Details
This class inherits a constructor from RuboCop::Formatter::BaseFormatter
Instance Method Details
#annotate_message(msg) (private)
[ GitHub ]# File 'lib/rubocop/formatter/simple_text_formatter.rb', line 85
def (msg) msg.gsub(/`(.*?)`/m, yellow('\1')) end
#colored_severity_code(offense) (private)
[ GitHub ]# File 'lib/rubocop/formatter/simple_text_formatter.rb', line 80
def colored_severity_code(offense) color = COLOR_FOR_SEVERITY.fetch(offense.severity.name) colorize(offense.severity.code, color) end
#count_stats(offenses) (private)
[ GitHub ]# File 'lib/rubocop/formatter/simple_text_formatter.rb', line 73
def count_stats(offenses) @total_offense_count += offenses.count corrected = offenses.count(&:corrected?) @total_correction_count += corrected @total_correctable_count += offenses.count(&:correctable?) - corrected end
#file_finished(file, offenses)
[ GitHub ]# File 'lib/rubocop/formatter/simple_text_formatter.rb', line 29
def file_finished(file, offenses) return if offenses.empty? count_stats(offenses) report_file(file, offenses) end
#finished(inspected_files)
[ GitHub ]# File 'lib/rubocop/formatter/simple_text_formatter.rb', line 36
def finished(inspected_files) report_summary(inspected_files.count, @total_offense_count, @total_correction_count, @total_correctable_count) end
#message(offense) (private)
[ GitHub ]# File 'lib/rubocop/formatter/simple_text_formatter.rb', line 89
def (offense) = if offense.corrected_with_todo? green('[Todo] ') elsif offense.corrected? green('[Corrected] ') elsif offense.correctable? yellow('[Correctable] ') else '' end "#{}#{ (offense. )}" end
#report_file(file, offenses)
[ GitHub ]# File 'lib/rubocop/formatter/simple_text_formatter.rb', line 43
def report_file(file, offenses) output.puts yellow("== #{smart_path(file)} ==") offenses.each do |o| output.printf( "%<severity>s:%3<line>d:%3<column>d: %<message>s\n", severity: colored_severity_code(o), line: o.line, column: o.real_column, message: (o) ) end end
#report_summary(file_count, offense_count, correction_count, correctable_count)
[ GitHub ]# File 'lib/rubocop/formatter/simple_text_formatter.rb', line 57
def report_summary(file_count, offense_count, correction_count, correctable_count) report = Report.new(file_count, offense_count, correction_count, correctable_count, rainbow, # :safe_autocorrect is a derived option based on several command-line # arguments - see RuboCop::Options#add_autocorrection_options safe_autocorrect: @options[:safe_autocorrect]) output.puts output.puts report.summary end
#started(_target_files)
[ GitHub ]# File 'lib/rubocop/formatter/simple_text_formatter.rb', line 23
def started(_target_files) @total_offense_count = 0 @total_correction_count = 0 @total_correctable_count = 0 end