Class: Shirobai::Cop::Metrics::ModuleLength
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Shirobai::Cop::Metrics::ModuleLength
- Extended by:
- RuboCop::ExcludeLimit
- Defined in:
- lib/shirobai/cop/metrics/module_length.rb
Overview
Drop-in Rust reimplementation of Metrics/ModuleLength.
Rust parses the source, finds every module definition (module nodes
and no-argument Module.new blocks assigned to a bare constant),
measures each with the shared CodeLength calculator's classlike /
body paths and returns those exceeding Max. There is no autocorrect;
the wrapper only builds ranges and messages. A constructor-form
offense range is the constant name (stock's node.loc.name).
Constant Summary collapse
- LABEL =
"Module"- MSG =
"%<label>s has too many lines. [%<length>d/%<max>d]"- FOLDABLE_TYPES =
%w[array hash heredoc method_call].freeze
Class Method Summary collapse
- .badge ⇒ Object
-
.bundle_args(config) ⇒ Object
Packed args for the bundled run:
[max, count_comments, count_as_one]. - .cop_name ⇒ Object
Instance Method Summary collapse
Class Method Details
.badge ⇒ Object
24 |
# File 'lib/shirobai/cop/metrics/module_length.rb', line 24 def self.badge = RuboCop::Cop::Badge.parse("Metrics/ModuleLength") |
.bundle_args(config) ⇒ Object
Packed args for the bundled run: [max, count_comments, count_as_one].
Max defaults to 100 (default.yml) so a config that does not mention
this cop still packs cleanly; the computed slice is discarded in that
case.
30 31 32 33 34 35 36 37 |
# File 'lib/shirobai/cop/metrics/module_length.rb', line 30 def self.bundle_args(config) cop_config = config.for_badge(badge) [ cop_config["Max"] || 100, !!cop_config["CountComments"], Array(cop_config["CountAsOne"]).map(&:to_s) ] end |
.cop_name ⇒ Object
23 |
# File 'lib/shirobai/cop/metrics/module_length.rb', line 23 def self.cop_name = "Metrics/ModuleLength" |
Instance Method Details
#on_new_investigation ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/shirobai/cop/metrics/module_length.rb', line 39 def on_new_investigation candidates = Dispatch.offenses_for(processed_source, config, :module_length) off = SourceOffsets.for(processed_source.raw_source) candidates.each do |start, fin, head_end, length| validate_count_as_one! stop = RuboCop::LSP.enabled? ? head_end : fin range = Parser::Source::Range.new(processed_source.buffer, off[start], off[stop]) add_offense(range, message: format(MSG, label: LABEL, length: length, max: max_length)) do self.max = length end end end |