Top Level Namespace
Defined Under Namespace
Classes: InvalidCommentForState, InvalidDefaultForOptional, InvalidTokenForState, OptionDoesntMatchHash, Param, ParamComments, ParamCommentsWorkflow, ParamWorkflow, UnexpectedComment
Constant Summary collapse
- PARAM_TYPE_ENUM =
{ mandatory: 1, with_default: 2, optional: 3 }.freeze
- EMPTY_PARAM =
The empty data of a parameter
{ name: '', type: '', has_default: false, default: '' }.freeze
- EMPTY_PARAM_COMMENT =
The empty data of a parameter
{ name: '', description: '', options: [], line: -1 }.freeze
- EMPTY_OPTION_COMMENT =
The empty data of a hash option
{ name: '', type: '', description: '', line: -1 }.freeze
- REGEXP_PARAM_HEADER =
A regular expression describing a parameter header
/^@param (?<name>[^ ]+)$/.freeze
- REGEXP_OPTION_HEADER =
A regular expression describing a hash option header
/^@option (?<hash_name>[^ ]+) \[(?<type>.+)\] :(?<name>[^ ]+)$/.freeze
Instance Method Summary collapse
-
#analyze_params(param_tokens) ⇒ Object
Analyze the parameters of a class or a defined type.
-
#get_comments(tokens, token_start) ⇒ Object
Find the header comments for a class or a defined type.
-
#get_missing_parameters(long_list, short_list) ⇒ Object
Find, which parameters in the long list are missing in the short list and return their names.
Instance Method Details
#analyze_params(param_tokens) ⇒ Object
Analyze the parameters of a class or a defined type
34 35 36 37 38 |
# File 'lib/puppet-lint/plugins/check_param_comment.rb', line 34 def analyze_params(param_tokens) param_workflow = Param.new param_workflow.process(param_tokens) param_workflow.params end |
#get_comments(tokens, token_start) ⇒ Object
Find the header comments for a class or a defined type
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/puppet-lint/plugins/check_param_comment.rb', line 19 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_missing_parameters(long_list, short_list) ⇒ Object
Find, which parameters in the long list are missing in the short list and return their names
45 46 47 48 |
# File 'lib/puppet-lint/plugins/check_param_comment.rb', line 45 def get_missing_parameters(long_list, short_list) long_list.reject { |param| short_list.any? { |short_list_param| short_list_param[:name] == param[:name] } } .map { |param| param[:name] } end |