Sha256: 4996a74b7e7d15342594c991b5c2d244ff23f93a056f6fe14508906304b7988a

Contents?: true

Size: 1.94 KB

Versions: 12

Compression:

Stored size: 1.94 KB

Contents

# frozen_string_literal: true

PuppetLint.new_check(:manifest_whitespace_class_name_single_space_before) do
  def check
    (class_indexes + defined_type_indexes).each do |class_idx|
      class_token = class_idx[:tokens].first
      name_token = class_token.next_token_of(%i[NAME FUNCTION_NAME])
      next unless name_token

      next_token = class_token.next_token
      next unless tokens.index(name_token) != tokens.index(class_token) + 2 ||
                  !is_single_space(next_token)

      notify(
        :error,
        message: 'there should be a single space between the class or defined resource statement and the name',
        line: next_token.line,
        column: next_token.column,
        token: next_token,
      )
    end
  end

  def fix(problem)
    raise PuppetLint::NoFix if problem[:token].type != :WHITESPACE

    problem[:token].value = ' '
  end
end

PuppetLint.new_check(:manifest_whitespace_class_name_single_space_after) do
  def check
    (class_indexes + defined_type_indexes).each do |class_idx|
      class_token = class_idx[:tokens].first
      name_token = class_token.next_token_of(%i[NAME FUNCTION_NAME])
      next unless name_token

      next_token = name_token.next_token
      next_code_token = next_non_space_token(name_token)
      next unless tokens.index(name_token) != tokens.index(next_code_token) - 2 ||
                  !is_single_space(next_token)

      notify(
        :error,
        message: 'there should be a single space between the class or resource name and the next item',
        line: name_token.line,
        column: name_token.column,
        token: name_token,
      )
    end
  end

  def fix(problem)
    token = problem[:token]

    next_token = token.next_token
    next_code_token = next_non_space_token(token)

    while next_token != next_code_token
      remove_token(next_token)
      next_token = next_token.next_token
    end

    add_token(tokens.index(next_code_token), new_single_space)
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
puppet-lint-manifest_whitespace-check-0.3.0 lib/puppet-lint/plugins/check_manifest_whitespace_class_name_single_space.rb
puppet-lint-manifest_whitespace-check-0.2.9 lib/puppet-lint/plugins/check_manifest_whitespace_class_name_single_space.rb
puppet-lint-manifest_whitespace-check-0.2.8 lib/puppet-lint/plugins/check_manifest_whitespace_class_name_single_space.rb
puppet-lint-manifest_whitespace-check-0.2.7 lib/puppet-lint/plugins/check_manifest_whitespace_class_name_single_space.rb
puppet-lint-manifest_whitespace-check-0.2.6 lib/puppet-lint/plugins/check_manifest_whitespace_class_name_single_space.rb
puppet-lint-manifest_whitespace-check-0.2.5 lib/puppet-lint/plugins/check_manifest_whitespace_class_name_single_space.rb
puppet-lint-manifest_whitespace-check-0.2.4 lib/puppet-lint/plugins/check_manifest_whitespace_class_name_single_space.rb
puppet-lint-manifest_whitespace-check-0.2.3 lib/puppet-lint/plugins/check_manifest_whitespace_class_name_single_space.rb
puppet-lint-manifest_whitespace-check-0.2.2 lib/puppet-lint/plugins/check_manifest_whitespace_class_name_single_space.rb
puppet-lint-manifest_whitespace-check-0.2.1 lib/puppet-lint/plugins/check_manifest_whitespace_class_name_single_space.rb
puppet-lint-manifest_whitespace-check-0.2.0 lib/puppet-lint/plugins/check_manifest_whitespace_class_name_single_space.rb
puppet-lint-manifest_whitespace-check-0.1.17 lib/puppet-lint/plugins/check_manifest_whitespace_class_name_single_space.rb