Class: Shirobai::Cop::Style::FileNull

Inherits:
RuboCop::Cop::Base
  • Object
show all
Extended by:
RuboCop::Cop::AutoCorrector
Includes:
BundleEligible
Defined in:
lib/shirobai/cop/style/file_null.rb

Overview

Drop-in Rust reimplementation of Style/FileNull.

Rust reproduces the whole detection: the file-level /dev/null tally that gates a bare nul (stock's @contain_dev_null_string_in_file), the acceptable? array / hash-pair exemption, the valid_string? empty / invalid-encoding guard, and the REGEXP full match against /dev/null / NUL / NUL: (case-insensitive). It returns one [start, end, message] per offense (message carries the original-case source value); the offense range is also the File::NULL replace range, so the wrapper just applies them. Config-less, so it is always bundle-eligible for config purposes; the shared bundle_eligible? guard only guards the raw-vs-buffer byte identity (CRLF / BOM).

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.badgeObject



23
# File 'lib/shirobai/cop/style/file_null.rb', line 23

def self.badge = RuboCop::Cop::Badge.parse(cop_name)

.bundle_args(_config) ⇒ Object

Config-less: contributes nothing to nums / lists. Kept for the 4+1 single-source-of-config convention.



27
28
29
# File 'lib/shirobai/cop/style/file_null.rb', line 27

def self.bundle_args(_config)
  []
end

.cop_nameObject



22
# File 'lib/shirobai/cop/style/file_null.rb', line 22

def self.cop_name = "Style/FileNull"

Instance Method Details

#on_new_investigationObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/shirobai/cop/style/file_null.rb', line 31

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, message|
    range = Parser::Source::Range.new(buffer, off[start], off[fin])
    add_offense(range, message: message) do |corrector|
      corrector.replace(range, "File::NULL")
    end
  end
end