Class: RuboCop::Cop::Standard::RailsViewRenderPathsExist
- Inherits:
-
RuboCop::Cop
- Object
- RuboCop::Cop
- RuboCop::Cop::Standard::RailsViewRenderPathsExist
- Defined in:
- lib/rubocop/cop/standard/rails/rails_view_render_paths_exist.rb
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rubocop/cop/standard/rails/rails_view_render_paths_exist.rb', line 25 def on_send(node) return unless cop_config['ViewPath'] if (args = render_str?(node)) node, path = args add_offense(node, location: :expression, message: 'Partial template could not be found') unless resolve_partial(path.to_s) elsif (pairs = (node)) if (pair = pairs.detect { |p| partial_key?(p) }) node, path = partial_key?(pair) add_offense(node, location: :expression, message: 'Partial template could not be found') unless resolve_partial(path.to_s) end end end |
#resolve_partial(path) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rubocop/cop/standard/rails/rails_view_render_paths_exist.rb', line 40 def resolve_partial(path) parts = path.split(File::SEPARATOR) parts << "_#{parts.pop}" path = parts.join(File::SEPARATOR) cop_config['ViewPath'].each do |view_path| if (m = Dir[File.join(config.path_relative_to_config(view_path), path) + '*'].first) return m end end nil end |