Sha256: 30643e8748e8909e827f3eef952d3a2afafddf27c0c2b0a3fdc20a66dd3878e0

Contents?: true

Size: 1.11 KB

Versions: 23

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

PuppetLint.new_check(:manifest_whitespace_missing_newline_end_of_file) do
  def check
    last_token = tokens.last

    if last_token.type != :NEWLINE
      notify(
        :error,
        message: 'there should be a single newline at the end of a manifest',
        line: last_token.line,
        column: last_token.column,
        token: last_token,
      )
    end
  end

  def fix(problem)
    index = tokens.index(problem[:token])
    tokens.insert(index + 1, PuppetLint::Lexer::Token.new(:NEWLINE, "\n", 0, 0))
  end
end

PuppetLint.new_check(:manifest_whitespace_double_newline_end_of_file) do
  def check
    last_token = tokens.last

    if last_token.type == :NEWLINE
      while last_token.prev_token && last_token.prev_token.type == :NEWLINE
        notify(
          :error,
          message: 'there should be a single newline at the end of a manifest',
          line: last_token.line,
          column: last_token.column,
          token: last_token,
        )

        last_token = last_token.prev_token
      end
    end
  end

  def fix(problem)
    tokens.delete(problem[:token])
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
puppet-lint-manifest_whitespace-check-0.2.5 lib/puppet-lint/plugins/check_manifest_whitespace_newline_end_of_file.rb
puppet-lint-manifest_whitespace-check-0.2.4 lib/puppet-lint/plugins/check_manifest_whitespace_newline_end_of_file.rb
puppet-lint-manifest_whitespace-check-0.2.3 lib/puppet-lint/plugins/check_manifest_whitespace_newline_end_of_file.rb
puppet-lint-manifest_whitespace-check-0.2.2 lib/puppet-lint/plugins/check_manifest_whitespace_newline_end_of_file.rb
puppet-lint-manifest_whitespace-check-0.2.1 lib/puppet-lint/plugins/check_manifest_whitespace_newline_end_of_file.rb
puppet-lint-manifest_whitespace-check-0.2.0 lib/puppet-lint/plugins/check_manifest_whitespace_newline_end_of_file.rb
puppet-lint-manifest_whitespace-check-0.1.17 lib/puppet-lint/plugins/check_manifest_whitespace_newline_end_of_file.rb
puppet-lint-manifest_whitespace-check-0.1.16 lib/puppet-lint/plugins/check_manifest_whitespace_newline_end_of_file.rb
puppet-lint-manifest_whitespace-check-0.1.15 lib/puppet-lint/plugins/check_manifest_whitespace_newline_end_of_file.rb
puppet-lint-manifest_whitespace-check-0.1.14 lib/puppet-lint/plugins/check_manifest_whitespace_newline_end_of_file.rb
puppet-lint-manifest_whitespace-check-0.1.13 lib/puppet-lint/plugins/check_manifest_whitespace_newline_end_of_file.rb
puppet-lint-manifest_whitespace-check-0.1.12 lib/puppet-lint/plugins/check_manifest_whitespace_newline_end_of_file.rb
puppet-lint-manifest_whitespace-check-0.1.11 lib/puppet-lint/plugins/check_manifest_whitespace_newline_end_of_file.rb
puppet-lint-manifest_whitespace-check-0.1.10 lib/puppet-lint/plugins/check_manifest_whitespace_newline_end_of_file.rb
puppet-lint-manifest_whitespace-check-0.1.9 lib/puppet-lint/plugins/check_manifest_whitespace_newline_end_of_file.rb
puppet-lint-manifest_whitespace-check-0.1.8 lib/puppet-lint/plugins/check_manifest_whitespace_newline_end_of_file.rb
puppet-lint-manifest_whitespace-check-0.1.7 lib/puppet-lint/plugins/check_manifest_whitespace_newline_end_of_file.rb
puppet-lint-manifest_whitespace-check-0.1.6 lib/puppet-lint/plugins/check_manifest_whitespace_newline_end_of_file.rb
puppet-lint-manifest_whitespace-check-0.1.5 lib/puppet-lint/plugins/check_manifest_whitespace_newline_end_of_file.rb
puppet-lint-manifest_whitespace-check-0.1.4 lib/puppet-lint/plugins/check_manifest_whitespace_newline_end_of_file.rb