Sha256: 5ba3fbda03e716cbecae116fbf42d530b41a9dab902f1158367e4f8628db399e
Contents?: true
Size: 1.96 KB
Versions: 1
Compression:
Stored size: 1.96 KB
Contents
PuppetLint.new_check(:parameter_types) do def check (class_indexes + defined_type_indexes).each do |idx| next if idx[:param_tokens].nil? # https://github.com/puppetlabs/puppet-specifications/blob/master/language/catalog_expressions.md # Each individual parameter in the parameter list must start with # either a datatype or a variable name, so testing whether the parameter is typed # is easy. state = :ST_BEGIN paren_stack = [] data_stack = [] idx[:param_tokens].each do |token| next if %i[NEWLINE WHITESPACE INDENT COMMENT MLCOMMENT SLASH_COMMENT].include?(token.type) case state when :ST_BEGIN paren_stack = [] data_stack = [] if (token.type == :TYPE) or (token.value =~ /^[A-Z]/) state = :ST_SKIP_TYPE elsif token.type == :VARIABLE notify :warning, { message: "missing datatype for parameter #{idx[:name_token].value}::#{token.value}", line: token.line, column: token.column, } state = :ST_SKIP end # skip over the parameter default which can contain complex data types with variable references # so a simple comma check isn't enough, brackets must be counted. when :ST_SKIP if token.type == :LPAREN paren_stack.push(true) elsif token.type == :RPAREN paren_stack.pop elsif token.type == :LBRACE || token.type == :LBRACK data_stack.push(true) elsif token.type == :RBRACE || token.type == :RBRACK data_stack.pop elsif token.type == :COMMA && data_stack.empty? && paren_stack.empty? state = :ST_BEGIN end # Datatypes cannot have variables so when a variable is found it must be # end of the data type when :ST_SKIP_TYPE state = :ST_SKIP if token.type == :VARIABLE end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
puppet-lint-param-types-2.0.0 | lib/puppet-lint/plugins/check_parameter_types.rb |