Class: RuboCop::Cop::RequireLibraryCorrector
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
RangeHelp
|
|
Inherits: | Object |
Defined in: | lib/rubocop/cop/correctors/require_library_corrector.rb |
Overview
This class ensures a require statement is present for a standard library determined by the variable library_name
Class Method Summary
RangeHelp
- Extended
add_range, column_offset_between, | |
contents_range | A range containing only the contents of a literal with delimiters (e.g. |
directions, | |
effective_column | Returns the column attribute of the range, except if the range is on the first line and there’s a byte order mark at the beginning of that line, in which case 1 is subtracted from the column value. |
final_pos, move_pos, move_pos_str, range_between, range_by_whole_lines, range_with_comments, range_with_comments_and_lines, range_with_surrounding_comma, range_with_surrounding_space, source_range |
Class Method Details
.correct(corrector, node, library_name)
[ GitHub ]# File 'lib/rubocop/cop/correctors/require_library_corrector.rb', line 11
def correct(corrector, node, library_name) node = node.parent while node.parent? node = node.children.first if node.begin_type? corrector.insert_before(node, require_statement(library_name)) end
.require_statement(library_name)
[ GitHub ]# File 'lib/rubocop/cop/correctors/require_library_corrector.rb', line 17
def require_statement(library_name) "require '#{library_name}'\n" end