Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,3 @@ inherit_gem:
Naming/FileName:
Exclude:
- "*.gemspec"

AllCops:
TargetRubyVersion: 3.2
53 changes: 2 additions & 51 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config --no-auto-gen-timestamp`
# using RuboCop version 1.79.2.
# using RuboCop version 1.81.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -38,70 +38,21 @@ RSpec/DescribeClass:
- '**/spec/views/**/*'
- 'spec/puppet-lint/plugins/check_strict_indent_spec.rb'

# Offense count: 17
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, conditionals
Style/AndOr:
Exclude:
- 'lib/puppet-lint/plugins/check_strict_indent.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AutoCorrect, EnforcedStyle, AllowComments.
# Configuration parameters: EnforcedStyle, AllowComments.
# SupportedStyles: empty, nil, both
Style/EmptyElse:
Exclude:
- 'lib/puppet-lint/plugins/check_strict_indent.rb'

# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Style/FrozenStringLiteralComment:
Exclude:
- '**/*.arb'
- 'lib/puppet-lint/plugins/check_strict_indent.rb'
- 'puppet-lint-strict_indent-check.gemspec'
- 'spec/puppet-lint/plugins/check_strict_indent_spec.rb'

# Offense count: 4
Style/MultilineBlockChain:
Exclude:
- 'lib/puppet-lint/plugins/check_strict_indent.rb'
- 'spec/puppet-lint/plugins/check_strict_indent_spec.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowMethodComparison, ComparisonsThreshold.
Style/MultipleComparison:
Exclude:
- 'lib/puppet-lint/plugins/check_strict_indent.rb'

# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle, AllowedMethods, AllowedPatterns.
# SupportedStyles: predicate, comparison
Style/NumericPredicate:
Exclude:
- 'spec/**/*'
- 'lib/puppet-lint/plugins/check_strict_indent.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength.
# AllowedMethods: present?, blank?, presence, try, try!
Style/SafeNavigation:
Exclude:
- 'lib/puppet-lint/plugins/check_strict_indent.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Style/WhileUntilModifier:
Exclude:
- 'lib/puppet-lint/plugins/check_strict_indent.rb'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
# URISchemes: http, https
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ group :development do
gem 'rspec', '~> 3.12'
gem 'rspec-collection_matchers', '~> 1.2'
gem 'rspec-its', '>= 1.3', '< 3'
gem 'voxpupuli-rubocop', '~> 4.2.0'
gem 'voxpupuli-rubocop', '~> 5.0.0'
end
38 changes: 19 additions & 19 deletions lib/puppet-lint/plugins/check_strict_indent.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Public: Check the manifest tokens for correct indent levels and
# record a warning for each instance found.

Expand Down Expand Up @@ -50,12 +52,12 @@ def check
# indent for open groups in the previous line
open_groups = 0
prev_token = token.prev_token
while !prev_token.nil? and prev_token.type != :NEWLINE
while !prev_token.nil? && (prev_token.type != :NEWLINE)
temp_indent += 1 if prev_token.type == :HEREDOC_OPEN
if %i[LBRACE LBRACK LPAREN].include?(prev_token.type)
if matches[prev_token].nil?
open_groups += 1
elsif matches[prev_token].line > prev_token.line and !matched_open_lines.include?(matches[prev_token].line)
elsif (matches[prev_token].line > prev_token.line) && !matched_open_lines.include?(matches[prev_token].line)
# increase indent for left braces not matched in the same line or in a line we have already matched a brace to
open_groups += 1
matched_open_lines << matches[prev_token].line
Expand All @@ -67,17 +69,15 @@ def check

# reset prev_token to last non-whitespace token on previous line
prev_token = token.prev_token
while !prev_token.nil? and (prev_token.type == :WHITESPACE or prev_token.type == :COMMENT)
prev_token = prev_token.prev_token
end
prev_token = prev_token.prev_token while !prev_token.nil? && ((prev_token.type == :WHITESPACE) || (prev_token.type == :COMMENT))

# get type if available
prev_type = prev_token.nil? ? nil : prev_token.type
prev_type = prev_token&.type

# handle change in indent based on last token
case prev_type
when :COLON
if open_groups == 0
if open_groups.zero?
if colon_indent.nil?
# only indent for a colon when you haven't indented yet
colon_indent = prev_token.line
Expand All @@ -99,23 +99,23 @@ def check
# unindent for closing brackets in the current line
next_token = token.next_token
matched_close_lines = []
while !next_token.nil? and next_token.type != :NEWLINE
while !next_token.nil? && (next_token.type != :NEWLINE)
if %i[RBRACE RBRACK RPAREN].include?(next_token.type)
if !matches[next_token].nil? and
matches[next_token].line < next_token.line and
if !matches[next_token].nil? &&
(matches[next_token].line < next_token.line) &&
!matched_close_lines.include?(matches[next_token].line)
# right braces matched in a previous line decrease indent unless we already matched a brace in the same line
indent -= 1
matched_close_lines << matches[next_token].line
end
if next_token.type == :RBRACE and !colon_indent.nil? && (!matches[next_token].nil? and matches[next_token].line < colon_indent)
if (next_token.type == :RBRACE) && !colon_indent.nil? && !matches[next_token].nil? && (matches[next_token].line < colon_indent)
# unindent at the end of resources if needed
indent -= 1
colon_indent = nil
end
elsif next_token.type == :SEMIC and !colon_indent.nil? and
%i[INDENT NEWLINE].include?(next_token.prev_token.type) and
(next_token.next_token.nil? or next_token.next_token.type == :NEWLINE)
elsif (next_token.type == :SEMIC) && !colon_indent.nil? &&
%i[INDENT NEWLINE].include?(next_token.prev_token.type) &&
(next_token.next_token.nil? || (next_token.next_token.type == :NEWLINE))
# For a lone semicolon within a block decrement immediately. Use temp_indent because
# indent will be decremented in the next line by the prev_token logic above.
temp_indent -= 1
Expand All @@ -124,7 +124,7 @@ def check
end

# obviously we have a problem
if indent < 0
if indent.negative?
notify :error, {
message: 'Error calculating indent. Please file an issue at https://github.com/relud/puppet-lint-indent-check/issues',
line: token.next_token.line,
Expand All @@ -151,7 +151,7 @@ def check
# For interpolated heredocs the pipe whitespace is in the HEREDOC_POST token so we need scan forward
# to this and get its length.
next_token = token.next_token
while !next_token.nil? and next_token.type != :NEWLINE and next_token.type != :HEREDOC_POST
while !next_token.nil? && (next_token.type != :NEWLINE) && (next_token.type != :HEREDOC_POST)
next_token = next_token.next_token
end
if next_token.type == :HEREDOC_POST
Expand Down Expand Up @@ -195,7 +195,7 @@ def fix(problem)
change = problem[:indent] - problem[:actual]
indent_heredoc(problem[:token], change)
next_token = problem[:token].next_token
while !next_token.nil? and next_token.type != :HEREDOC_POST
while !next_token.nil? && (next_token.type != :HEREDOC_POST)
indent_heredoc(next_token, change) if next_token.type == :HEREDOC_MID
next_token = next_token.next_token
end
Expand All @@ -211,10 +211,10 @@ def fix(problem)
def map_heredoc_lines(value, change, skip)
char_for_indent = ' '
value.split("\n").map! do |line|
if skip or line.empty?
if skip || line.empty?
skip = false
line
elsif change < 0
elsif change.negative?
line[-change..]
else
(char_for_indent * change) + line
Expand Down
2 changes: 2 additions & 0 deletions puppet-lint-strict_indent-check.gemspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Gem::Specification.new do |spec|
spec.name = 'puppet-lint-strict_indent-check'
spec.version = '5.0.0'
Expand Down
2 changes: 2 additions & 0 deletions spec/puppet-lint/plugins/check_strict_indent_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'strict_indent' do
Expand Down