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) return if problem[:token].nil? arrow_token = problem[:token] left_operand_token = arrow_token.prev_code_token right_operand_token = arrow_token.next_code_token # Move arrow token to just before the right operand remove_token(arrow_token) right_operand_index = tokens.index(right_operand_token) add_token(right_operand_index, arrow_token) whitespace_token = PuppetLint::Lexer::Token.new(:WHITESPACE, ' ', right_operand_token.line, 3) add_token(right_operand_index + 1, whitespace_token) # Remove trailing whitespace after left operand (if it exists) return unless left_operand_token.next_token.type == :WHITESPACE trailing_whitespace_token = left_operand_token.next_token remove_token(trailing_whitespace_token) if [:NEWLINE, :WHITESPACE].include?(trailing_whitespace_token.next_token.type) 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
with_puppet_lint_head() { || ... }
click to toggle source
# File lib/puppet-lint/tasks/release_test.rb, line 30 def with_puppet_lint_head print(' Updating Gemfile to use puppet-lint HEAD... ') buffer = Parser::Source::Buffer.new('Gemfile') buffer.source = File.read('Gemfile') parser = Parser::CurrentRuby.new ast = parser.parse(buffer) modified_gemfile = GemfileRewrite.new.rewrite(buffer, ast) if modified_gemfile == buffer.source puppet_lint_root = File.expand_path(File.join(__FILE__, '..', '..', '..', '..')) File.open('Gemfile', 'a') do |f| f.puts "gem 'puppet-lint', :path => '#{puppet_lint_root}'" end else File.open('Gemfile', 'w') do |f| f.puts modified_gemfile end end puts 'Done' Bundler.with_clean_env { yield } run_cmd('Restoring Gemfile', 'git', 'checkout', '--', 'Gemfile') end