Class: Shirobai::Cop::Style::Semicolon
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::Style::Semicolon
- Extended by:
- RuboCop::Cop::AutoCorrector
- Includes:
- RuboCop::Cop::RangeHelp, BundleEligible
- Defined in:
- lib/shirobai/cop/style/semicolon.rb
Overview
Drop-in Rust reimplementation of Style/Semicolon.
Stock has two detection paths. Path (a) (on_new_investigation) groups
processed_source.tokens by line and flags a semicolon in six
positional token-index patterns. shirobai builds no parser token
stream, so path (a) runs in Rust: a masked byte scan (the same opaque
regions as the punctuation cops) plus a few AST-collected opener
positions reconstruct those index facts. Rust returns one [offset, last_token] pair per flagged ;.
Path (b) (on_begin, the raw-line scan for expression separators) stays
here, ported verbatim from stock: it is pure parser AST + line text and
costs no token stream, so it matches stock byte for byte for free. The
AllowAsExpressionSeparator option only turns path (b) off, exactly as
in stock.
Autocorrect is stock's, run at correction time on the real parser AST /
tokens (only reached with -a): path (a)'s last-token pattern may wrap
an endless range or a hash value omission in parentheses; path (b)
replaces the ; with a newline unless a heredoc opened earlier on the
line. Because both paths call add_offense in stock's order (path (a)
first, then path (b) during the walk), RuboCop's own offense dedup and
corrector-conflict resolution reproduce stock's result on the lines
both paths touch.
Constant Summary collapse
- MSG =
"Do not use semicolons to terminate expressions."
Class Method Summary collapse
- .autocorrect_incompatible_with ⇒ Object
- .badge ⇒ Object
-
.bundle_args(_config) ⇒ Object
Config-less on the bundle side: path (a) needs no config and path (b) reads
AllowAsExpressionSeparatordirectly fromcop_config. - .cop_name ⇒ Object
Instance Method Summary collapse
Class Method Details
.autocorrect_incompatible_with ⇒ Object
44 45 46 |
# File 'lib/shirobai/cop/style/semicolon.rb', line 44 def self.autocorrect_incompatible_with [RuboCop::Cop::Style::SingleLineMethods] end |
.badge ⇒ Object
38 |
# File 'lib/shirobai/cop/style/semicolon.rb', line 38 def self.badge = RuboCop::Cop::Badge.parse("Style/Semicolon") |
.bundle_args(_config) ⇒ Object
Config-less on the bundle side: path (a) needs no config and path (b)
reads AllowAsExpressionSeparator directly from cop_config.
42 |
# File 'lib/shirobai/cop/style/semicolon.rb', line 42 def self.bundle_args(_config) = [] |
.cop_name ⇒ Object
37 |
# File 'lib/shirobai/cop/style/semicolon.rb', line 37 def self.cop_name = "Style/Semicolon" |
Instance Method Details
#on_begin(node) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/shirobai/cop/style/semicolon.rb', line 54 def on_begin(node) return if cop_config["AllowAsExpressionSeparator"] return unless node.source.include?(";") exprs = node.children return if exprs.size < 2 expressions_per_line(exprs).each do |line, expr_on_line| # Every line with more than one expression on it is a # potential offense. next unless expr_on_line.size > 1 find_semicolon_positions(line) { |pos| register_semicolon(line, pos, true) } end end |
#on_new_investigation ⇒ Object
48 49 50 51 52 |
# File 'lib/shirobai/cop/style/semicolon.rb', line 48 def on_new_investigation return if processed_source.blank? || !processed_source.raw_source.include?(";") check_for_line_terminator_or_opener end |