Class: Shirobai::Cop::Layout::LineLength
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::Layout::LineLength
- Extended by:
- RuboCop::Cop::AutoCorrector
- Includes:
- RuboCop::Cop::AllowedPattern, RuboCop::Cop::CheckLineBreakable, RuboCop::Cop::LineLengthHelp, RuboCop::Cop::RangeHelp
- Defined in:
- lib/shirobai/cop/layout/line_length.rb
Overview
Drop-in Rust reimplementation of ‘Layout/LineLength` (detection only).
The per-line scan over every line of the file happens in Rust, which returns only the lines that exceed ‘Max` (plus the heredoc delimiter for lines inside a heredoc body). Ruby then applies the regex-based exemptions (`AllowedPatterns`, `AllowURI`, `AllowQualifiedName`, cop directives, RBS annotations) that rely on Ruby’s ‘URI`/`Regexp`, reusing the upstream mixins so the offense ranges match exactly. Candidates and breakables come from the per-file bundled run (`Shirobai::Dispatch`); the regex exemptions run after the ext call either way, so this cop is always bundle-eligible.
Constant Summary collapse
- MSG =
"Line is too long. [%<length>d/%<max>d]"
Class Method Summary collapse
- .badge ⇒ Object
-
.bundle_args(config) ⇒ Object
Packed args for the bundled run: ‘[max, tab_width, split_strings]`.
- .cop_name ⇒ Object
Instance Method Summary collapse
Class Method Details
.badge ⇒ Object
29 |
# File 'lib/shirobai/cop/layout/line_length.rb', line 29 def self.badge = RuboCop::Cop::Badge.parse("Layout/LineLength") |
.bundle_args(config) ⇒ Object
Packed args for the bundled run: ‘[max, tab_width, split_strings]`. `tab_width` replicates `LineLengthHelp#tab_indentation_width` (`Layout/IndentationStyle` width, falling back to `Alignment#configured_indentation_width`). `Max` defaults to 120 (default.yml) so a config that does not mention this cop still packs cleanly; the computed slice is discarded in that case.
37 38 39 40 41 42 43 |
# File 'lib/shirobai/cop/layout/line_length.rb', line 37 def self.bundle_args(config) cop_config = config.for_badge(badge) tab_width = config.for_cop("Layout/IndentationStyle")["IndentationWidth"] || cop_config["IndentationWidth"] || config.for_cop("Layout/IndentationWidth")["Width"] || 2 [cop_config["Max"] || 120, tab_width, !!cop_config["SplitStrings"]] end |
.cop_name ⇒ Object
28 |
# File 'lib/shirobai/cop/layout/line_length.rb', line 28 def self.cop_name = "Layout/LineLength" |
Instance Method Details
#on_new_investigation ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/shirobai/cop/layout/line_length.rb', line 45 def on_new_investigation candidates = Dispatch.offenses_for(processed_source, config, :line_length) # Breakable (autocorrection) data must be installed even in lint mode: # with AutoCorrect defaulting to 'always', the corrector block runs and # a non-empty corrector makes the offense `:uncorrected` (correctable), # which stock reports as "[Correctable]" / counts as auto-correctable. # Skipping it would flip the offense to `:unsupported` and diverge from # stock's lint output. The bundle restricts the walk to candidate lines # (length > Max) on the Rust side — the sole lines that can become # offenses and consume a breakable range — which is identical to # computing it for all lines. install_breakables(Dispatch.offenses_for(processed_source, config, :line_length_breakables)) candidates.each do |candidate| line_index, length, _line_start, _line_end, _indent_diff, heredoc_delimiters = candidate line = processed_source.lines[line_index] check_candidate(line, line_index, length, heredoc_delimiters) end end |