Class: ERBLint::Linters::ExtraNewline
- Inherits:
-
ERBLint::Linter
- Object
- ERBLint::Linter
- ERBLint::Linters::ExtraNewline
- Includes:
- ERBLint::LinterRegistry
- Defined in:
- lib/erb_lint/linters/extra_newline.rb
Overview
Detects multiple blank lines
Constant Summary collapse
- EXTRA_NEWLINES =
/(\n{3,})/m
Constants included from ERBLint::LinterRegistry
ERBLint::LinterRegistry::CUSTOM_LINTERS_DIR
Instance Attribute Summary
Attributes inherited from ERBLint::Linter
Instance Method Summary collapse
Methods included from ERBLint::LinterRegistry
clear, find_by_name, included, linters, load_custom_linters
Methods inherited from ERBLint::Linter
#add_offense, #clear_offenses, #enabled?, #excludes_file?, inherited, #initialize, support_autocorrect?
Constructor Details
This class inherits a constructor from ERBLint::Linter
Instance Method Details
#autocorrect(_processed_source, offense) ⇒ Object
23 24 25 26 27 |
# File 'lib/erb_lint/linters/extra_newline.rb', line 23 def autocorrect(_processed_source, offense) lambda do |corrector| corrector.replace(offense.source_range, "") end end |
#run(processed_source) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/erb_lint/linters/extra_newline.rb', line 11 def run(processed_source) return unless (matches = processed_source.file_content.match(EXTRA_NEWLINES)) matches.captures.each_index do |index| add_offense( processed_source .to_source_range((matches.begin(index) + 2)...matches.end(index)), "Extra blank line detected." ) end end |