Top Level Namespace

Defined Under Namespace

Classes: InvalidTokenForState, Reference, ReferenceWorkflow

Constant Summary collapse

REF_TYPE_ENUM =
{
  internal: 0,
  component: 1,
  feature: 2
}.freeze
INTERNAL_MODULE_REGEXP =
/^(role|profile)::/.freeze

Instance Method Summary collapse

Instance Method Details

#get_comments(tokens, token_start) ⇒ Object

Find the header comments for a class or a defined type

Parameters:

  • tokens

    The list of all tokens

  • token_start

    The index of the token to start from upwards

Returns:

  • The head comments



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/puppet-lint/plugins/check_module_reference.rb', line 10

def get_comments(tokens, token_start)
  comments = []
  token_pointer = token_start - 1
  while token_pointer >= 0
    break unless i[COMMENT NEWLINE].include? tokens[token_pointer].type

    comments.append(tokens[token_pointer])
    token_pointer -= 1
  end
  comments.reject { |comment| comment.type == :NEWLINE }.reverse!
end

#get_first_index_of_type(comments, type, feature_refs) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/puppet-lint/plugins/check_module_reference.rb', line 22

def get_first_index_of_type(comments, type, feature_refs)
  comments.each_with_index do |comment, index|
    comment.match(/@see (?<name>\S+)/) do |match|
      next if feature_refs.any? { |ref| ref[:name] == match.named_captures['name'] }
      return index if match.named_captures['name'].match?(INTERNAL_MODULE_REGEXP) && type == REF_TYPE_ENUM[:internal]
      return index if !match.named_captures['name'].match?(INTERNAL_MODULE_REGEXP) && type == REF_TYPE_ENUM[:component]
    end
  end
  0
end