Class: Shirobai::Cop::RSpec::VariableName
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::RSpec::VariableName
- Includes:
- RuboCop::Cop::AllowedPattern, RuboCop::Cop::ConfigurableNaming, BundleEligible
- Defined in:
- lib/shirobai/cop/rspec/variable_name.rb
Overview
Drop-in Rust reimplementation of RSpec/VariableName
(rubocop-rspec 3.10.2).
Rust classifies once on the shared walk: a candidate is a
send-shaped let/subject (any block kind, or no block at all)
with a plain sym/str first argument, inside a TOP-LEVEL spec group
(stock's inside_example_group? checks the outermost enclosing
statement, not just any ancestor — a group wrapped in a top-level
class does not count). Rust also evaluates stock's
ConfigurableNaming::FORMATS regexps (probed: [[:lower:]] /
[[:upper:]] are the Unicode Lowercase/Uppercase properties,
\d is ASCII), and returns the failing candidates plus the
passing (value, kind) pairs.
The wrapper replays stock's reporting exactly: AllowedPatterns are
Ruby regexps so they are applied here, passing values drive
correct_style_detected, and each offense's block reports the
opposing style for --auto-gen-config (the alternative style when
the name is valid there, otherwise "unrecognized"). Stock's
class_emitter_method? escape hatch is dead code on send nodes,
so valid_name? reduces to the regexp.
Constant Summary collapse
- MSG =
"Use %<style>s for variable names."
Class Method Summary collapse
- .badge ⇒ Object
-
.bundle_args(config) ⇒ Object
Packed args for the bundled run:
[style](0 snake_case, 1 camelCase). - .cop_name ⇒ Object
Instance Method Summary collapse
Class Method Details
.badge ⇒ Object
35 |
# File 'lib/shirobai/cop/rspec/variable_name.rb', line 35 def self.badge = RuboCop::Cop::Badge.parse(cop_name) |
.bundle_args(config) ⇒ Object
Packed args for the bundled run: [style] (0 snake_case,
1 camelCase).
39 40 41 |
# File 'lib/shirobai/cop/rspec/variable_name.rb', line 39 def self.bundle_args(config) [config.for_badge(badge).fetch("EnforcedStyle", "snake_case") == "camelCase" ? 1 : 0] end |
.cop_name ⇒ Object
34 |
# File 'lib/shirobai/cop/rspec/variable_name.rb', line 34 def self.cop_name = "RSpec/VariableName" |
Instance Method Details
#on_new_investigation ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/shirobai/cop/rspec/variable_name.rb', line 43 def on_new_investigation offenses, passing = resolved_data return if offenses.empty? && passing.empty? passing.each do |(value, kind)| correct_style_detected unless matches_allowed_pattern?(wrap(value, kind)) end buffer = processed_source.buffer source = bundle_eligible? ? processed_source.raw_source : buffer.source off = SourceOffsets.for(source) offenses.each do |(start, fin, kind, value, valid_alt)| next if matches_allowed_pattern?(wrap(value, kind)) range = Parser::Source::Range.new(buffer, off[start], off[fin]) add_offense(range, message: format(MSG, style: style)) do if valid_alt unexpected_style_detected(alternative_style) else unrecognized_style_detected end end end end |