Skip to content

Commit dfc4adf

Browse files
committed
rubocop: autofix
1 parent 88835cf commit dfc4adf

File tree

2 files changed

+19
-59
lines changed

2 files changed

+19
-59
lines changed

.rubocop_todo.yml

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config --no-auto-gen-timestamp`
3-
# using RuboCop version 1.79.2.
3+
# using RuboCop version 1.81.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -38,17 +38,9 @@ RSpec/DescribeClass:
3838
- '**/spec/views/**/*'
3939
- 'spec/puppet-lint/plugins/check_strict_indent_spec.rb'
4040

41-
# Offense count: 17
42-
# This cop supports unsafe autocorrection (--autocorrect-all).
43-
# Configuration parameters: EnforcedStyle.
44-
# SupportedStyles: always, conditionals
45-
Style/AndOr:
46-
Exclude:
47-
- 'lib/puppet-lint/plugins/check_strict_indent.rb'
48-
4941
# Offense count: 1
5042
# This cop supports safe autocorrection (--autocorrect).
51-
# Configuration parameters: AutoCorrect, EnforcedStyle, AllowComments.
43+
# Configuration parameters: EnforcedStyle, AllowComments.
5244
# SupportedStyles: empty, nil, both
5345
Style/EmptyElse:
5446
Exclude:
@@ -60,37 +52,7 @@ Style/MultilineBlockChain:
6052
- 'lib/puppet-lint/plugins/check_strict_indent.rb'
6153
- 'spec/puppet-lint/plugins/check_strict_indent_spec.rb'
6254

63-
# Offense count: 1
64-
# This cop supports safe autocorrection (--autocorrect).
65-
# Configuration parameters: AllowMethodComparison, ComparisonsThreshold.
66-
Style/MultipleComparison:
67-
Exclude:
68-
- 'lib/puppet-lint/plugins/check_strict_indent.rb'
69-
7055
# Offense count: 3
71-
# This cop supports unsafe autocorrection (--autocorrect-all).
72-
# Configuration parameters: EnforcedStyle, AllowedMethods, AllowedPatterns.
73-
# SupportedStyles: predicate, comparison
74-
Style/NumericPredicate:
75-
Exclude:
76-
- 'spec/**/*'
77-
- 'lib/puppet-lint/plugins/check_strict_indent.rb'
78-
79-
# Offense count: 1
80-
# This cop supports unsafe autocorrection (--autocorrect-all).
81-
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength.
82-
# AllowedMethods: present?, blank?, presence, try, try!
83-
Style/SafeNavigation:
84-
Exclude:
85-
- 'lib/puppet-lint/plugins/check_strict_indent.rb'
86-
87-
# Offense count: 1
88-
# This cop supports safe autocorrection (--autocorrect).
89-
Style/WhileUntilModifier:
90-
Exclude:
91-
- 'lib/puppet-lint/plugins/check_strict_indent.rb'
92-
93-
# Offense count: 2
9456
# This cop supports safe autocorrection (--autocorrect).
9557
# Configuration parameters: AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
9658
# URISchemes: http, https

lib/puppet-lint/plugins/check_strict_indent.rb

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)