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
-
.uri_regexp_for(cop_config) ⇒ Object
LineLengthHelp#uri_regexpmemoizes per cop instance, and the real CLI builds a fresh cop per file — so stock rebuilds the same Regexp (an expensiveURIparser call) for every file with a candidate line.
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" |
.uri_regexp_for(cop_config) ⇒ Object
LineLengthHelp#uri_regexp memoizes per cop instance, and the real
CLI builds a fresh cop per file — so stock rebuilds the same Regexp
(an expensive URI parser call) for every file with a candidate
line. The regexp depends only on the cop's URISchemes, so share it
per cop-config object instead.
50 51 52 53 54 55 56 |
# File 'lib/shirobai/cop/layout/line_length.rb', line 50 def self.uri_regexp_for(cop_config) @uri_regexp_cache ||= {}.compare_by_identity @uri_regexp_cache[cop_config] ||= begin parser = defined?(URI::RFC2396_PARSER) ? URI::RFC2396_PARSER : URI::DEFAULT_PARSER parser.make_regexp(cop_config["URISchemes"]) end end |
Instance Method Details
#on_new_investigation ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/shirobai/cop/layout/line_length.rb', line 58 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 |