Module: RuboCop::Cop::FilePlacementHelp

Overview

Methods that help analyzing file placement within Nitro components

Constant Summary collapse

FILE_PLACEMENT_MSG =
"Do not add top-level files into `%<matcher_path>s`. " \
"Namespace them like `%<correct_path>s`"

Instance Method Summary collapse

Instance Method Details

#applicable_component_path?(path, matcher) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/rubocop/cop/cobra/file_placement_help.rb', line 11

def applicable_component_path?(path, matcher)
  in_a_component?(path) && path_contains_matcher?(path, matcher)
end

#file_placement_msg(path, matcher) ⇒ Object



25
26
27
28
29
# File 'lib/rubocop/cop/cobra/file_placement_help.rb', line 25

def file_placement_msg(path, matcher)
  format(FILE_PLACEMENT_MSG,
         matcher_path: matcher,
         correct_path: correct_path(path, matcher))
end

#namespaced_correctly?(path, matcher) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
# File 'lib/rubocop/cop/cobra/file_placement_help.rb', line 15

def namespaced_correctly?(path, matcher)
  potential_component_name = component_name(path, matcher)
  component_path = File.join(
    potential_component_name,
    matcher,
    potential_component_name
  )
  path.include?("#{component_path}/") || path.include?("#{component_path}.rb")
end