Class: RuboCop::Formatter::BaseFormatter
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
|
Subclasses:
AutoGenConfigFormatter, ClangStyleFormatter, DisabledConfigFormatter, EmacsStyleFormatter, FileListFormatter, FuubarStyleFormatter, GitHubActionsFormatter, HTMLFormatter, JSONFormatter, JUnitFormatter, MarkdownFormatter, OffenseCountFormatter, PacmanFormatter, ProgressFormatter, QuietFormatter, SARIFFormatter, SimpleTextFormatter, TapFormatter, WorstOffendersFormatter
|
|
| Inherits: | Object |
| Defined in: | lib/rubocop/formatter/base_formatter.rb |
Overview
Abstract base class for formatter, implements all public API methods.
Creating Custom Formatter
You can create a custom formatter by subclassing
BaseFormatter and overriding some methods
or by implementing all the methods by duck typing.
Using Custom Formatter in Command Line
You can tell ::RuboCop to use your custom formatter with a combination of
--format and --require option.
For example, when you have defined MyCustomFormatter in
./path/to/my_custom_formatter.rb, you would type this command:
rubocop --require ./path/to/my_custom_formatter --format MyCustomFormatter
Note: The path passed to --require is directly passed to
Kernel.require.
If your custom formatter file is not in $LOAD_PATH,
you need to specify the path as relative path prefixed with ./
explicitly or absolute path.
Method Invocation Order
For example, when ::RuboCop inspects 2 files,
the invocation order should be like this:
#initialize- #started
- #file_started
- #file_finished
- #file_started
- #file_problems (only when a cop crashed or warned on the file)
- #file_finished
#finished
Class Method Summary
- .new(output, options = {}) ⇒ BaseFormatter constructor
Instance Attribute Summary
- #options ⇒ Hash readonly
- #output ⇒ IO readonly
Instance Method Summary
-
#file_finished(file, offenses)
Invoked at the end of inspecting each files.
-
#file_problems(file, errors, warnings)
Invoked before #file_finished for a file that a cop crashed on or raised a warning for, or whose corrections went into an infinite loop.
-
#file_started(file, options)
Invoked at the beginning of inspecting each files.
-
#finished(inspected_files)
Invoked after all files are inspected or interrupted by user.
-
#started(target_files)
Invoked once before any files are inspected.
Constructor Details
.new(output, options = {}) ⇒ BaseFormatter
Instance Attribute Details
#options ⇒ Hash (readonly)
# File 'lib/rubocop/formatter/base_formatter.rb', line 58
attr_reader :
#output ⇒ IO (readonly)
# File 'lib/rubocop/formatter/base_formatter.rb', line 51
attr_reader :output
Instance Method Details
#file_finished(file, offenses)
This method returns an undefined value.
Invoked at the end of inspecting each files.
# File 'lib/rubocop/formatter/base_formatter.rb', line 126
def file_finished(file, offenses); end
#file_problems(file, errors, warnings)
This method returns an undefined value.
Invoked before #file_finished for a file that a cop crashed on or raised a warning for, or whose corrections went into an infinite loop. Optional: a formatter implementing the API by duck typing is skipped when it doesn’t define it.
# File 'lib/rubocop/formatter/base_formatter.rb', line 111
def file_problems(file, errors, warnings); end
#file_started(file, options)
This method returns an undefined value.
Invoked at the beginning of inspecting each files.
# File 'lib/rubocop/formatter/base_formatter.rb', line 90
def file_started(file, ); end
#finished(inspected_files)
This method returns an undefined value.
Invoked after all files are inspected or interrupted by user.
# File 'lib/rubocop/formatter/base_formatter.rb', line 138
def finished(inspected_files); end
#started(target_files)
This method returns an undefined value.
Invoked once before any files are inspected.
# File 'lib/rubocop/formatter/base_formatter.rb', line 77
def started(target_files); end