Sha256: 77cbff22aa5b8e87de2fce0aae9db16bcc8c7da5fdd834ee90df6803abfad59c

Contents?: true

Size: 920 Bytes

Versions: 1

Compression:

Stored size: 920 Bytes

Contents

PuppetLint.new_check(:trailing_comma) do
  def check
    # Resource and class declarations
    resource_indexes.each do |resource|
      lbo_token = resource[:tokens][-1].prev_code_token
      if lbo_token && lbo_token.type != :COLON && \
                      resource[:tokens][-1].type != :SEMIC && \
                      lbo_token.type != :COMMA && \
                      lbo_token.next_token.type == :NEWLINE
        notify :warning, {
          :message => 'missing trailing comma after last parameter',
          :line    => lbo_token.next_token.line,
          :column  => lbo_token.next_token.column,
          :token   => lbo_token.next_token,
        }
      end
    end
  end

  def fix(problem)
    comma = PuppetLint::Lexer::Token.new(
      :COMMA,
      ',',
      problem[:token].line,
      problem[:token].column
    )

    idx = tokens.index(problem[:token])
    tokens.insert(idx, comma)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
puppet-lint-trailing_comma-check-0.1.3 lib/puppet-lint/plugins/check_trailing_comma.rb