@@ -52,12 +52,12 @@ def check
5252 # indent for open groups in the previous line
5353 open_groups = 0
5454 prev_token = token . prev_token
55- while !prev_token . nil? and prev_token . type != :NEWLINE
55+ while !prev_token . nil? && ( prev_token . type != :NEWLINE )
5656 temp_indent += 1 if prev_token . type == :HEREDOC_OPEN
5757 if %i[ LBRACE LBRACK LPAREN ] . include? ( prev_token . type )
5858 if matches [ prev_token ] . nil?
5959 open_groups += 1
60- elsif matches [ prev_token ] . line > prev_token . line and !matched_open_lines . include? ( matches [ prev_token ] . line )
60+ elsif ( matches [ prev_token ] . line > prev_token . line ) && !matched_open_lines . include? ( matches [ prev_token ] . line )
6161 # increase indent for left braces not matched in the same line or in a line we have already matched a brace to
6262 open_groups += 1
6363 matched_open_lines << matches [ prev_token ] . line
@@ -69,17 +69,15 @@ def check
6969
7070 # reset prev_token to last non-whitespace token on previous line
7171 prev_token = token . prev_token
72- while !prev_token . nil? and ( prev_token . type == :WHITESPACE or prev_token . type == :COMMENT )
73- prev_token = prev_token . prev_token
74- end
72+ prev_token = prev_token . prev_token while !prev_token . nil? && ( ( prev_token . type == :WHITESPACE ) || ( prev_token . type == :COMMENT ) )
7573
7674 # get type if available
77- prev_type = prev_token . nil? ? nil : prev_token . type
75+ prev_type = prev_token & .type
7876
7977 # handle change in indent based on last token
8078 case prev_type
8179 when :COLON
82- if open_groups == 0
80+ if open_groups . zero?
8381 if colon_indent . nil?
8482 # only indent for a colon when you haven't indented yet
8583 colon_indent = prev_token . line
@@ -101,23 +99,23 @@ def check
10199 # unindent for closing brackets in the current line
102100 next_token = token . next_token
103101 matched_close_lines = [ ]
104- while !next_token . nil? and next_token . type != :NEWLINE
102+ while !next_token . nil? && ( next_token . type != :NEWLINE )
105103 if %i[ RBRACE RBRACK RPAREN ] . include? ( next_token . type )
106- if !matches [ next_token ] . nil? and
107- matches [ next_token ] . line < next_token . line and
104+ if !matches [ next_token ] . nil? &&
105+ ( matches [ next_token ] . line < next_token . line ) &&
108106 !matched_close_lines . include? ( matches [ next_token ] . line )
109107 # right braces matched in a previous line decrease indent unless we already matched a brace in the same line
110108 indent -= 1
111109 matched_close_lines << matches [ next_token ] . line
112110 end
113- if next_token . type == :RBRACE and !colon_indent . nil? && ( !matches [ next_token ] . nil? and matches [ next_token ] . line < colon_indent )
111+ if ( next_token . type == :RBRACE ) && !colon_indent . nil? && !matches [ next_token ] . nil? && ( matches [ next_token ] . line < colon_indent )
114112 # unindent at the end of resources if needed
115113 indent -= 1
116114 colon_indent = nil
117115 end
118- elsif next_token . type == :SEMIC and !colon_indent . nil? and
119- %i[ INDENT NEWLINE ] . include? ( next_token . prev_token . type ) and
120- ( next_token . next_token . nil? or next_token . next_token . type == :NEWLINE )
116+ elsif ( next_token . type == :SEMIC ) && !colon_indent . nil? &&
117+ %i[ INDENT NEWLINE ] . include? ( next_token . prev_token . type ) &&
118+ ( next_token . next_token . nil? || ( next_token . next_token . type == :NEWLINE ) )
121119 # For a lone semicolon within a block decrement immediately. Use temp_indent because
122120 # indent will be decremented in the next line by the prev_token logic above.
123121 temp_indent -= 1
@@ -126,7 +124,7 @@ def check
126124 end
127125
128126 # obviously we have a problem
129- if indent < 0
127+ if indent . negative?
130128 notify :error , {
131129 message : 'Error calculating indent. Please file an issue at https://github.com/relud/puppet-lint-indent-check/issues' ,
132130 line : token . next_token . line ,
@@ -153,7 +151,7 @@ def check
153151 # For interpolated heredocs the pipe whitespace is in the HEREDOC_POST token so we need scan forward
154152 # to this and get its length.
155153 next_token = token . next_token
156- while !next_token . nil? and next_token . type != :NEWLINE and next_token . type != :HEREDOC_POST
154+ while !next_token . nil? && ( next_token . type != :NEWLINE ) && ( next_token . type != :HEREDOC_POST )
157155 next_token = next_token . next_token
158156 end
159157 if next_token . type == :HEREDOC_POST
@@ -197,7 +195,7 @@ def fix(problem)
197195 change = problem [ :indent ] - problem [ :actual ]
198196 indent_heredoc ( problem [ :token ] , change )
199197 next_token = problem [ :token ] . next_token
200- while !next_token . nil? and next_token . type != :HEREDOC_POST
198+ while !next_token . nil? && ( next_token . type != :HEREDOC_POST )
201199 indent_heredoc ( next_token , change ) if next_token . type == :HEREDOC_MID
202200 next_token = next_token . next_token
203201 end
@@ -213,10 +211,10 @@ def fix(problem)
213211 def map_heredoc_lines ( value , change , skip )
214212 char_for_indent = ' '
215213 value . split ( "\n " ) . map! do |line |
216- if skip or line . empty?
214+ if skip || line . empty?
217215 skip = false
218216 line
219- elsif change < 0
217+ elsif change . negative?
220218 line [ -change ..]
221219 else
222220 ( char_for_indent * change ) + line
0 commit comments