Class: RuboCop::Cop::Cobra::HelperFilePlacement

Inherits:
RuboCop::Cop::Cop
  • Object
show all
Includes:
FilePlacementHelp
Defined in:
lib/rubocop/cop/cobra/helper_file_placement.rb

Overview

This cop disallows adding global helpers to the ‘app/helpers` directory.

The goal is to encourage developers to put new helpers inside the correct namespace, where they can be more modularly isolated and ownership is clear.

Examples:

# bad
# path: components/my_component/app/helpers/foo.rb
class Foo
  # ...
end

# good
# path: components/my_component/app/helpers/my_component/foo.rb
module MyComponent
  class Foo
    # ...
  end
end

Constant Summary

Constants included from FilePlacementHelp

FilePlacementHelp::FILE_PLACEMENT_MSG

Instance Method Summary collapse

Methods included from FilePlacementHelp

#applicable_component_path?, #file_placement_msg, #namespaced_correctly?

Instance Method Details

#investigate(processed_source) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/rubocop/cop/cobra/helper_file_placement.rb', line 29

def investigate(processed_source)
  return if processed_source.blank?

  path = processed_source.file_path
  return unless applicable_component_path?(path, helpers_path)
  return if namespaced_correctly?(path, helpers_path)

  add_offense(processed_source.ast,
              message: file_placement_msg(path, helpers_path))
end