Sha256: f7970f37d65d3068fcf05904315b10122ef171679297ab377c49fa0ede3b6cba

Contents?: true

Size: 1.79 KB

Versions: 3

Compression:

Stored size: 1.79 KB

Contents

PuppetLint.new_check(:relative_classname_inclusion) do
  def check
    message = 'class included by absolute name (::$class)'

    tokens.each_with_index do |token, token_idx|
      if [:NAME,:FUNCTION_NAME].include?(token.type) && ['include','contain','require'].include?(token.value)
        s = token.next_code_token
        next if s.nil?
        next if s.type == :FARROW

        in_function = 0
        while s.type != :NEWLINE
          n = s.next_code_token
          if [:NAME, :FUNCTION_NAME, :SSTRING,].include?(s.type)
            if n && n.type == :LPAREN
              in_function += 1
            elsif in_function > 0 && n && n.type == :RPAREN
              in_function -= 1
            elsif in_function.zero? && s.value.start_with?('::')
              notify :warning, {
                message: message,
                line: s.line,
                column: s.column,
                token: s
              }
            end
          end
          s = s.next_token
        end
      elsif token.type == :CLASS and token.next_code_token.type == :LBRACE
        s = token.next_code_token
        while s.type != :COLON
          if (s.type == :NAME || s.type == :SSTRING) && s.value.start_with?('::')
            notify :warning, {
              message: message,
              line: s.line,
              column: s.column,
              token: s
            }
          end
          s = s.next_token
        end
      elsif token.type == :INHERITS
        s = token.next_code_token
        if s.type == :NAME && s.value.start_with?('::')
          notify :warning, {
            message: message,
            line: s.line,
            column: s.column,
            token: s
          }
        end
      end
    end
  end

  def fix(problem)
    problem[:token].value = problem[:token].value[2..-1]
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
puppet-lint-absolute_classname-check-3.1.0 lib/puppet-lint/plugins/check_absolute_classname.rb
puppet-lint-absolute_classname-check-3.0.1 lib/puppet-lint/plugins/check_absolute_classname.rb
puppet-lint-absolute_classname-check-3.0.0 lib/puppet-lint/plugins/check_absolute_classname.rb