Class: Shirobai::Cop::Layout::SpaceBeforeFirstArg
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::Layout::SpaceBeforeFirstArg
- Extended by:
- RuboCop::Cop::AutoCorrector
- Includes:
- BundleEligible
- Defined in:
- lib/shirobai/cop/layout/space_before_first_arg.rb
Overview
Drop-in Rust reimplementation of Layout/SpaceBeforeFirstArg.
Rust replays stock's on_send / on_csend over prism CallNodes
(parenless, non-operator, non-setter calls with arguments — a
block-pass counts like in parser-gem) and the whole
PrecedingFollowingAlignment scan for AllowForAlignment: nearest
candidate line per direction (comments and blanks transparent), the
indentation-filtered second pass, char-column aligned_words?, and
the assignment-token alignment for :sym=-shaped arguments (found
with a masked longest-match operator scan).
Each offense is the [start, end) whitespace run before the first
argument (possibly empty for glued arguments); the corrector replaces
it with a single space.
Constant Summary collapse
- MSG =
"Put one space between the method name and the first argument."
Class Method Summary collapse
- .autocorrect_incompatible_with ⇒ Object
- .badge ⇒ Object
-
.bundle_args(config) ⇒ Object
Packed args for the bundled run:
[[AllowForAlignment], []](nilcounts as falsy, like stock'sallow_for_alignment?). - .cop_name ⇒ Object
Instance Method Summary collapse
Class Method Details
.autocorrect_incompatible_with ⇒ Object
29 30 31 |
# File 'lib/shirobai/cop/layout/space_before_first_arg.rb', line 29 def self.autocorrect_incompatible_with [RuboCop::Cop::Style::MethodCallWithArgsParentheses] end |
.badge ⇒ Object
27 |
# File 'lib/shirobai/cop/layout/space_before_first_arg.rb', line 27 def self.badge = RuboCop::Cop::Badge.parse(cop_name) |
.bundle_args(config) ⇒ Object
Packed args for the bundled run: [[AllowForAlignment], []]
(nil counts as falsy, like stock's allow_for_alignment?).
35 36 37 38 |
# File 'lib/shirobai/cop/layout/space_before_first_arg.rb', line 35 def self.bundle_args(config) cop_config = config.for_badge(badge) [[cop_config["AllowForAlignment"] ? 1 : 0], []] end |
.cop_name ⇒ Object
26 |
# File 'lib/shirobai/cop/layout/space_before_first_arg.rb', line 26 def self.cop_name = "Layout/SpaceBeforeFirstArg" |
Instance Method Details
#on_new_investigation ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/shirobai/cop/layout/space_before_first_arg.rb', line 40 def on_new_investigation buffer = processed_source.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.replace(range, " ") end end end |