Class: Shirobai::Cop::Layout::EmptyLines
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::Layout::EmptyLines
- Extended by:
- RuboCop::Cop::AutoCorrector
- Includes:
- RuboCop::Cop::RangeHelp, BundleEligible
- Defined in:
- lib/shirobai/cop/layout/empty_lines.rb
Overview
Drop-in Rust reimplementation of Layout/EmptyLines.
Stock's on_new_investigation walks processed_source.tokens and yields a
1-byte source_range(buffer, line, 0) for every line L whose previous
and current text lines are both empty AND that falls inside a gap of
cur_token_line - prev_token_line > 2. The corrector removes that 1-byte
range (the \n at column 0 of the offending line).
The Rust side reconstructs "lines with parser-gem tokens" from the prism
AST plus comments (see crates/shirobai-core/src/rules/empty_lines.rs for
the equivalence rules — string-content nodes fill their span, container
nodes mark only open/close lines, etc.) and runs the same gap-scan stock
does. It returns the offense byte ranges; the wrapper turns each into a
Parser::Source::Range, attaches the same MSG, and removes the range.
Bundle-eligible only when the parser-normalized buffer.source is
byte-identical to raw_source (no CRLF / BOM normalization). On CRLF or
BOM the standalone entry point scans buffer.source directly so every
returned offset still indexes into the parser-gem buffer.
Constant Summary collapse
- MSG =
"Extra blank line detected."
Class Method Summary collapse
- .badge ⇒ Object
-
.bundle_args(_config) ⇒ Object
The cop is config-less from the Rust side — bundle_args returns an empty pair so it contributes nothing to nums / lists.
- .cop_name ⇒ Object
Instance Method Summary collapse
Class Method Details
.badge ⇒ Object
33 |
# File 'lib/shirobai/cop/layout/empty_lines.rb', line 33 def self.badge = RuboCop::Cop::Badge.parse(cop_name) |
.bundle_args(_config) ⇒ Object
The cop is config-less from the Rust side — bundle_args returns an empty pair so it contributes nothing to nums / lists. Kept for the 4+1 single-source-of-config convention.
38 39 40 |
# File 'lib/shirobai/cop/layout/empty_lines.rb', line 38 def self.bundle_args(_config) [] end |
.cop_name ⇒ Object
32 |
# File 'lib/shirobai/cop/layout/empty_lines.rb', line 32 def self.cop_name = "Layout/EmptyLines" |
Instance Method Details
#on_new_investigation ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/shirobai/cop/layout/empty_lines.rb', line 42 def on_new_investigation buffer = processed_source.buffer # On the bundle path Rust scanned `raw_source` (byte-identical to # `buffer.source`); on the CRLF/BOM fallback the standalone path # scans `buffer.source` instead so every offset Rust returns lines # up with the parser-gem buffer. source = bundle_eligible? ? processed_source.raw_source : buffer.source off = SourceOffsets.for(source) resolved_offenses.each do |start, fin| range = Parser::Source::Range.new(buffer, off[start], off[fin]) add_offense(range, message: MSG) do |corrector| corrector.remove(range) end end end |