Class: Shirobai::Cop::Lint::UselessAccessModifier
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::Lint::UselessAccessModifier
- Extended by:
- RuboCop::Cop::AutoCorrector
- Includes:
- RuboCop::Cop::RangeHelp
- Defined in:
- lib/shirobai/cop/lint/useless_access_modifier.rb
Overview
Drop-in Rust reimplementation of ‘Lint/UselessAccessModifier`.
Rust walks the AST once and replicates the union of stock’s entry points: the ‘check_node` handlers on class/module/sclass bodies and eval-style / `included` blocks, the `check_scope` recursion that tracks `cur_vis`/`unused` through transparent children (conditionals, `begin` bodies, plain blocks, hash values…) while skipping method definitions and `defs`, and the unconditional top-level `on_begin` flagging — including the `macro?` scope chain that gates `bare_access_modifier?` and the `private_class_method`-with-arguments state reset. Offense ranges (the modifier send) and modifier names come from Rust; Ruby formats stock’s message and derives the whole-line removal with the stock ‘range_by_whole_lines` helper, so the autocorrect is byte-identical by construction. Offenses come from the per-file bundled run (`Shirobai::Dispatch`); the config is two string lists (`ContextCreatingMethods` / `MethodCreatingMethods`) plus the `ActiveSupportExtensionsEnabled` flag, so this cop is always bundle-eligible.
Constant Summary collapse
- MSG =
"Useless `%<current>s` access modifier."
Class Method Summary collapse
- .badge ⇒ Object
-
.bundle_args(config) ⇒ Object
Packed args for the bundled run: ‘[context_creating_methods, method_creating_methods, active_support_extensions_enabled]`.
- .cop_name ⇒ Object
Instance Method Summary collapse
Class Method Details
.badge ⇒ Object
31 |
# File 'lib/shirobai/cop/lint/useless_access_modifier.rb', line 31 def self.badge = RuboCop::Cop::Badge.parse("Lint/UselessAccessModifier") |
.bundle_args(config) ⇒ Object
Packed args for the bundled run: ‘[context_creating_methods, method_creating_methods, active_support_extensions_enabled]`.
35 36 37 38 39 40 41 42 |
# File 'lib/shirobai/cop/lint/useless_access_modifier.rb', line 35 def self.bundle_args(config) cop_cfg = config.for_badge(badge) [ Array(cop_cfg["ContextCreatingMethods"]).map(&:to_s), Array(cop_cfg["MethodCreatingMethods"]).map(&:to_s), !!config.active_support_extensions_enabled? ] end |
.cop_name ⇒ Object
30 |
# File 'lib/shirobai/cop/lint/useless_access_modifier.rb', line 30 def self.cop_name = "Lint/UselessAccessModifier" |
Instance Method Details
#on_new_investigation ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/shirobai/cop/lint/useless_access_modifier.rb', line 44 def on_new_investigation buffer = processed_source.buffer offenses = Dispatch.offenses_for(processed_source, config, :useless_access_modifier) return if offenses.empty? off = SourceOffsets.for(processed_source.raw_source) offenses.each do |start, fin, current| range = Parser::Source::Range.new(buffer, off[start], off[fin]) add_offense(range, message: format(MSG, current: current)) do |corrector| corrector.remove(range_by_whole_lines(range, include_final_newline: true)) end end end |