class Object

Constants

BOOLEANS
COMMENT_TOKENS
COMMENT_TYPES
DEFAULT_SCOPE_VARS
ESCAPE_CHAR_RE
IGNORE_TYPES
MODE_RE
MSG
POST_VAR_TOKENS
STRING_TYPES
SYM_RE
TOKENS
TOKEN_TYPES
VARIABLE_DASH_TYPES
VARIABLE_LOWERCASE_TYPES
VAR_TYPES
WHITESPACE_TOKENS
WHITESPACE_TYPES

Public Instance Methods

check() click to toggle source
# File lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb, line 6
def check
  tokens.select { |r| Set[:IN_EDGE, :IN_EDGE_SUB].include?(r.type) }.each do |token|
    next if token.next_code_token.line == token.line

    notify(
      :warning,
      :message =>  'arrow should be on the right operand\s line',
      :line    => token.line,
      :column  => token.column,
      :token   => token
    )
  end
end
find_comment_token(start_token) click to toggle source
# File lib/puppet-lint/plugins/check_documentation/documentation.rb, line 32
def find_comment_token(start_token)
  prev_token = start_token.prev_token
  while !prev_token.nil? && WHITESPACE_TOKENS.include?(prev_token.type)
    prev_token = prev_token.prev_token
  end

  return if prev_token.nil?

  prev_token if COMMENT_TOKENS.include?(prev_token.type)
end
fix(problem) click to toggle source
# File lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb, line 20
def fix(problem)
  token = problem[:token]

  prev_code_token = token.prev_code_token
  next_code_token = token.next_code_token
  indent_token = prev_code_token.prev_token_of(:INDENT)

  # Delete all tokens between the two code tokens the anchor is between
  temp_token = prev_code_token
  while (temp_token = temp_token.next_token) && (temp_token != next_code_token)
    remove_token(temp_token) unless temp_token == token
  end

  # Insert a newline and an indent before the arrow
  index = tokens.index(token)
  newline_token = PuppetLint::Lexer::Token.new(:NEWLINE, "\n", token.line, 0)
  add_token(index, newline_token)
  add_token(index + 1, indent_token) if indent_token

  # Insert a space between the arrow and the following code token
  index = tokens.index(token)
  whitespace_token = PuppetLint::Lexer::Token.new(:WHITESPACE, ' ', token.line, 3)
  add_token(index + 1, whitespace_token)
end
required_parameter?(token) click to toggle source
# File lib/puppet-lint/plugins/check_classes/parameter_order.rb, line 41
def required_parameter?(token)
  return false unless token.type == :VARIABLE

  data_type = token.prev_token_of(:TYPE, :skip_blocks => true)
  return false if data_type && data_type.value == 'Optional'

  if token.next_code_token.nil? || [:COMMA, :RPAREN].include?(token.next_code_token.type)
    return !(token.prev_code_token && token.prev_code_token.type == :EQUALS)
  end

  false
end
run_cmd(message, *cmd) click to toggle source
# File lib/puppet-lint/tasks/release_test.rb, line 5
def run_cmd(message, *cmd)
  print("  #{message}... ")

  if Open3.respond_to?(:capture2e)
    output, status = Open3.capture2e(*cmd)
  else
    output = ''

    Open3.popen3(*cmd) do |stdin, stdout, stderr|
      stdin.close
      output += stdout.read
      output += stderr.read
    end
    status = $CHILD_STATUS.dup
  end

  if status.success?
    puts 'Done'
  else
    puts 'FAILED'
  end

  [output.strip, status.success?]
end