Class: Shirobai::Cop::Style::MagicCommentFormat
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::Style::MagicCommentFormat
- Extended by:
- RuboCop::Cop::AutoCorrector
- Includes:
- RuboCop::Cop::ConfigurableEnforcedStyle, BundleEligible
- Defined in:
- lib/shirobai/cop/style/magic_comment_format.rb
Overview
Drop-in Rust reimplementation of Style/MagicCommentFormat.
Stock's only parser-gem token access is leading_comment_lines, which
asks processed_source.tokens.find { |t| !t.comment? } for the first
non-comment token — materializing the whole parser-gem token stream on
every file (the "toucher" cost). Everything else runs on the parser-gem
comment objects (each_comment_in_lines, backed by
processed_source.comments from the parse — not the token stream) and
stock's own CommentRange regex extraction, offense predicates,
messages and corrections.
So Rust supplies ONLY the leading-line boundary (the first non-comment
token line, without tokens); this wrapper rebuilds
leading_comment_lines from it and runs stock's magic_comments and the
rest verbatim. CommentRange is reused directly from the stock cop, and
the offense/message/correction helpers are copied verbatim, so detection,
messages, and autocorrect are stock's own code — byte-identical by
construction, including non-ASCII offsets (offense ranges come from
CommentRange's loc.expression char offsets, never through Rust).
Constant Summary collapse
- SNAKE_SEPARATOR =
"_"- KEBAB_SEPARATOR =
"-"- MSG =
"Prefer %<style>s case for magic comments."- MSG_VALUE =
"Prefer %<case>s for magic comment values."- CommentRange =
Reuse stock's
CommentRange(theDIRECTIVE_REGEXP/VALUE_REGEXPscan that turns a comment into directive/value source ranges) verbatim. RuboCop::Cop::Style::MagicCommentFormat::CommentRange
Class Method Summary collapse
- .badge ⇒ Object
-
.bundle_args(_config) ⇒ Object
Config-less on the Rust side (the leading-line boundary needs no config; every EnforcedStyle / Capitalization axis is handled here in Ruby by stock's own methods).
- .cop_name ⇒ Object
Instance Method Summary collapse
-
#on_new_investigation ⇒ Object
Stock's
on_new_investigation, verbatim.
Class Method Details
.badge ⇒ Object
40 |
# File 'lib/shirobai/cop/style/magic_comment_format.rb', line 40 def self.badge = RuboCop::Cop::Badge.parse(cop_name) |
.bundle_args(_config) ⇒ Object
Config-less on the Rust side (the leading-line boundary needs no config; every EnforcedStyle / Capitalization axis is handled here in Ruby by stock's own methods). Kept for the 4+1 single-source-of-config convention.
46 47 48 |
# File 'lib/shirobai/cop/style/magic_comment_format.rb', line 46 def self.bundle_args(_config) [] end |
.cop_name ⇒ Object
39 |
# File 'lib/shirobai/cop/style/magic_comment_format.rb', line 39 def self.cop_name = "Style/MagicCommentFormat" |
Instance Method Details
#on_new_investigation ⇒ Object
Stock's on_new_investigation, verbatim.
51 52 53 54 55 56 57 58 |
# File 'lib/shirobai/cop/style/magic_comment_format.rb', line 51 def on_new_investigation return unless processed_source.ast magic_comments.each do |comment| issues = find_issues(comment) register_offenses(issues) if issues.any? end end |