class PuppetLint::Lexer::Token

Add some utility functions to the PuppetLint::Lexer::Token class

Public Instance Methods

class_include?() click to toggle source
# File lib/puppet-lint/plugins/check_wmf_styleguide.rb, line 168
def class_include?
  # Check for include-like objects
  @type == :NAME && ['include', 'require', 'contain'].include?(@value) && @next_code_token.type != :FARROW
end
declared_class() click to toggle source
# File lib/puppet-lint/plugins/check_wmf_styleguide.rb, line 180
def declared_class
  return unless @type == :CLASS
  # In a class declaration, the first token is the class declaration itself.
  return if @next_code_token.type != :LBRACE
  @next_code_token.next_code_token
end
declared_type?() click to toggle source
# File lib/puppet-lint/plugins/check_wmf_styleguide.rb, line 187
def declared_type?
  # The token is a name and the next token is a {, while the previous one is not "class"
  @type == :NAME && @next_code_token.type == :LBRACE && @prev_code_token.type != :CLASS
end
function?() click to toggle source

Extend the basic token with utility functions

# File lib/puppet-lint/plugins/check_wmf_styleguide.rb, line 148
def function?
  # A function is something that has a name and is followed by a left parens
  [:NAME, :FUNCTION_NAME].include?(@type) && @next_code_token.type == :LPAREN
end
included_class() click to toggle source
# File lib/puppet-lint/plugins/check_wmf_styleguide.rb, line 173
def included_class
  # Fetch the token describing the included class
  return unless class_include?
  return @next_code_token.next_code_token if @next_code_token.type == :LPAREN
  @next_code_token
end
legacy_hiera?() click to toggle source
# File lib/puppet-lint/plugins/check_wmf_styleguide.rb, line 153
def legacy_hiera?
  # Using old hiera call
  function? && ['hiera', 'hiera_array', 'hiera_hash'].include?(@value)
end
legacy_validate?() click to toggle source
# File lib/puppet-lint/plugins/check_wmf_styleguide.rb, line 163
def legacy_validate?
  # A function calling one of the legacy stdlib validate functions
  function? && @value.start_with?('validate_')
end
lookup?() click to toggle source
# File lib/puppet-lint/plugins/check_wmf_styleguide.rb, line 158
def lookup?
  # A function call specifically calling lookup
  function? && ['lookup'].include?(@value)
end
node_def?() click to toggle source
# File lib/puppet-lint/plugins/check_wmf_styleguide.rb, line 192
def node_def?
  [:SSTRING, :STRING, :NAME, :REGEX].include?(@type)
end
role_keyword?() click to toggle source
# File lib/puppet-lint/plugins/check_wmf_styleguide.rb, line 196
def role_keyword?
  # This is a function with name "role"
  @type == :NAME && @value = 'role' && @next_code_token.type == :LPAREN
end