Class: RuboCop::Cop::Gusto::RablExtends

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/gusto/rabl_extends.rb

Overview

Disallows the use of ‘extends` in Rabl templates due to poor caching performance. Inline the templating to generate your JSON instead.

Examples:

# bad
extends 'path/to/template'

# bad - but not covered by this rule
partial 'path/to/template'

# good - inline your templating
node 'some_node'
attributes :foo, :bar
child(:baz) { attributes :qux }

Constant Summary collapse

MSG =
"Avoid using Rabl extends as it has poor caching performance. Inline your JSON instead."
RABL_EXTENSION =
".rabl"
RESTRICT_ON_SEND =
%i(extends).freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



31
32
33
34
35
# File 'lib/rubocop/cop/gusto/rabl_extends.rb', line 31

def on_send(node)
  return unless rabl_extends?(node)

  add_offense(node)
end

#rabl_extends?(node) ⇒ Object



27
28
29
# File 'lib/rubocop/cop/gusto/rabl_extends.rb', line 27

def_node_matcher :rabl_extends?, <<~PATTERN
  (send nil? :extends (str _) ...)
PATTERN

#relevant_file?(file) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/rubocop/cop/gusto/rabl_extends.rb', line 37

def relevant_file?(file)
  file.end_with?(RABL_EXTENSION)
end