Class: RuboCop::Cop::Legion::Extension::RunnerPluralModule

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/legion/extension/runner_plural_module.rb

Overview

Detects ‘module Runner` (singular) inside `Legion::Extensions::*` namespaces and auto-corrects it to `module Runners` (plural), which is what the LEX framework uses when discovering runner modules.

The framework does ‘actor_str.sub(’::Actor::‘, ’::Runners::‘)` — hardcoded plural. A singular `Runner` module will never be found.

Examples:

# bad
module Legion::Extensions::Foo
  module Runner
  end
end

# good
module Legion::Extensions::Foo
  module Runners
  end
end

Constant Summary collapse

MSG =
'Use `module Runners` (plural), not `module Runner`. ' \
'The framework discovers runners inside `Runners`.'

Instance Method Summary collapse

Instance Method Details

#on_module(node) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/rubocop/cop/legion/extension/runner_plural_module.rb', line 32

def on_module(node)
  name_node = node.identifier
  return unless name_node.short_name == :Runner

  return unless inside_legion_extensions_namespace?(node)

  add_offense(name_node) do |corrector|
    corrector.replace(name_node.loc.name, 'Runners')
  end
end