class Object
Constants
- BOOLEANS
- COMMENT_TOKENS
- COMMENT_TYPES
- DEFAULT_SCOPE_VARS
- ESCAPE_CHAR_RE
- IGNORE_TYPES
- MODE_RE
- MSG
- POST_VAR_TOKENS
- STRING_TOKEN_TYPES
- 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
extract_hash_or_array_ref(token)
click to toggle source
# File lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb, line 37 def extract_hash_or_array_ref(token) scanner = StringScanner.new(token.value) brack_depth = 0 result = { :ref => '' } until scanner.eos? result[:ref] += scanner.getch # Pass a length of 1 when slicing the last character from the string # to prevent Ruby 1.8 returning a Fixnum instead of a String. case result[:ref][-1, 1] when '[' brack_depth += 1 when ']' brack_depth -= 1 end break if brack_depth.zero? && scanner.peek(1) != '[' end result[:remainder] = scanner.rest result 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) newlines = 0 prev_token = start_token.prev_token while !prev_token.nil? && WHITESPACE_TOKENS.include?(prev_token.type) newlines += 1 if prev_token.type == :NEWLINE break if newlines > 1 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
handle_variable_containing_dash(var_token)
click to toggle source
# File lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb, line 66 def handle_variable_containing_dash(var_token) str_token = var_token.next_token var_name, text = var_token.value.split('-', 2) var_token.value = var_name return if str_token.nil? str_token.value = "-#{text}#{str_token.value}" end
hash_or_array_ref?(token)
click to toggle source
# File lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb, line 31 def hash_or_array_ref?(token) token.next_token && STRING_TOKEN_TYPES.include?(token.next_token.type) && token.next_token.value.start_with?('[') end
parameter?(token)
click to toggle source
# File lib/puppet-lint/plugins/check_classes/parameter_order.rb, line 42 def parameter?(token) return false unless token.type == :VARIABLE return false unless token.prev_code_token [ :LPAREN, # First parameter, no type specification :COMMA, # Subsequent parameter, no type specification :TYPE, # Parameter with simple type specification :RBRACK, # Parameter with complex type specification ].include?(token.prev_code_token.type) end
required_parameter?(token)
click to toggle source
# File lib/puppet-lint/plugins/check_classes/parameter_order.rb, line 54 def required_parameter?(token) 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
variable_contains_dash?(token)
click to toggle source
# File lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb, line 62 def variable_contains_dash?(token) token.value.include?('-') 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