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
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ def walk_ast_for_indentation(node, deltas, parent = nil)
end
end
when :if
# We don't want to add deltas for elsif, because it's handled by the if node:
if node.keyword == "if" || node.keyword == "unless"
# Modifier conditionals don't introduce indentation, and elsif is handled by the if node:
if !node.modifier_form? && (node.keyword == "if" || node.keyword == "unless")
if location = node.location
deltas[location.line] += 1
deltas[location.last_line] -= 1
Expand Down
4 changes: 4 additions & 0 deletions releases.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Releases

## Unreleased

- Fixed `Layout/ConsistentBlankLineIndentation` to ignore modifier conditionals when calculating indentation depth.

## v0.11.0

- Fixed `Layout/ConsistentBlankLineIndentation` to preserve semantic indentation depth for same-line nested structures, avoiding negative indentation levels when later closing lines are processed.
Expand Down
30 changes: 30 additions & 0 deletions test/rubocop/socketry/layout/consistent_blank_line_indentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -842,4 +842,34 @@ def foo
expect(offenses).to be(:empty?)
end
end

with "a block guarded by a modifier conditional" do
let(:source) {"describe Foo do\n\tit \"works\" do\n\t\tfoo\n\tend\n\t\n\tit \"still works\" do\n\t\tbar\n\tend\nend if condition\n"}

it "does not count the modifier conditional as an indentation level" do
processed_source = RuboCop::ProcessedSource.new(source, RUBY_VERSION.to_f)
investigator = RuboCop::Cop::Commissioner.new([cop], [], raise_error: true)
report = investigator.investigate(processed_source)
offenses = report.offenses
expect(offenses).to be(:empty?)
end
end

with "begin blocks guarded by modifier loops" do
let(:sources) do
["while", "until"].map do |keyword|
"begin\n\tfoo do\n\tend\n\t\n\tbar\nend #{keyword} condition\n"
end
end

it "does not count modifier loops as indentation levels" do
sources.each do |source|
processed_source = RuboCop::ProcessedSource.new(source, RUBY_VERSION.to_f)
investigator = RuboCop::Cop::Commissioner.new([cop], [], raise_error: true)
report = investigator.investigate(processed_source)
offenses = report.offenses
expect(offenses).to be(:empty?)
end
end
end
end
Loading