Top Level Namespace
Defined Under Namespace
Classes: InvalidCommentForState, OptionDoesntMatchHash, ParamComments, ParamWorkflow, UnexpectedComment
Constant Summary collapse
- 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_param_token(token, current_param) ⇒ Object
Analyze a parameter token.
-
#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_param_token(token, current_param) ⇒ Object
Analyze a parameter token
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/puppet-lint/plugins/check_param_comment.rb', line 35 def analyze_param_token(token, current_param) # noinspection RubyCaseWithoutElseBlockInspection case token.type when :VARIABLE current_param[:name] = token.value when :CLASSREF, :TYPE current_param[:type] = token.value when :EQUALS current_param[:has_default] = true current_param[:default] = token.next_token.value end current_param end |
#analyze_params(param_tokens) ⇒ Object
Analyze the parameters of a class or a defined type
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/puppet-lint/plugins/check_param_comment.rb', line 52 def analyze_params(param_tokens) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity params = [] current_param = EMPTY_PARAM.dup brackets = 0 param_tokens.reject { |token| %i[WHITESPACE NEWLINE INDENT].include? token.type }.each do |token| brackets += 1 if %i[LBRACK LBRACE].include? token.type brackets -= 1 if %i[RBRACK RBRACE].include? token.type next unless brackets.zero? current_param = analyze_param_token(token, current_param) unless token.type == :COMMA if token.type == :COMMA params.append(current_param) current_param = EMPTY_PARAM.dup end end params.append(current_param) unless current_param[:name] == '' 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
76 77 78 79 |
# File 'lib/puppet-lint/plugins/check_param_comment.rb', line 76 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 |