Skip to content

Commit

Permalink
Revert "Fix Linter ControlStatementSpacing raise incorrect = (#164)" (#…
Browse files Browse the repository at this point in the history
…169)

This reverts commit ff1ef25, since it
results in the issue described in
#168.
  • Loading branch information
sds committed Jan 16, 2024
1 parent 251c1c8 commit e72519e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 130 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Slim-Lint Changelog

## Unreleased

* Revert "Fix `ControlSpacingStatement` linter handling of `=` in some cases"

## 0.25.0

* Drop support for Ruby 2.x
Expand Down
34 changes: 2 additions & 32 deletions lib/slim_lint/linter/control_statement_spacing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@ class Linter::ControlStatementSpacing < Linter

on [:html, :tag, anything, [],
[:slim, :output, anything, capture(:ruby, anything)]] do |sexp|
# Process original slim code so that multi-line attributes become single line.
# And store the correction line count
source = merge_multiline_attributes(document.source_lines)

# Fetch processed Slim code that contains an element with a control statement.
line = source[sexp.line - 1][:line]
# Apply correction to the line count.
sexp.line += source[sexp.line - 1][:line_count]
# Fetch original Slim code that contains an element with a control statement.
line = document.source_lines[sexp.line - 1]

# Remove any Ruby code, because our regexp below must not match inside Ruby.
ruby = captures[:ruby]
Expand All @@ -26,29 +20,5 @@ class Linter::ControlStatementSpacing < Linter

report_lint(sexp, MESSAGE)
end

private

def merge_multiline_attributes(source_lines)
result = []
memo = ''
correction_line_count = 0

source_lines.each do |line|
memo += line.chomp('\\')

# Lines ending in a backslash are concatenated with the next line
# And count the number of lines to correct the sexp line count.
if line.match?(/\\$/)
correction_line_count += 1
next
end

# Add merged rows and correction line count to the result and reset the memo
result << { line: memo, line_count: correction_line_count }
memo = ''
end
result
end
end
end
98 changes: 0 additions & 98 deletions spec/slim_lint/linter/control_statement_spacing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,104 +175,6 @@
it { should_not report_lint }
end

context 'when an element has a multi-line attribute' do
# OK
context 'when it is simple' do
let(:slim) { <<-'SLIM' }
div class='one \
two'
div = some_method
SLIM

it { should_not report_lint }
end

context 'when it is more than two lines' do
let(:slim) { <<-'SLIM' }
div class='one \
two three four \
five six seven \
eight nine ten eleven twelve'
div = some_method
SLIM

it { should_not report_lint }
end

context 'when it has more than two locations' do
let(:slim) { <<-'SLIM' }
div class='one \
two'
div class='one \
two three four five six seven \
eight nine ten eleven twelve'
div class='one \
two three four five six seven \
eight nine ten eleven twelve'
div = some_method
SLIM

it { should_not report_lint }
end

# NG
context 'when it is simple' do
let(:slim) { <<-'SLIM' }
div class='one \
two'
div= some_method
SLIM

it { should report_lint line: 3 }
end

context 'when it is more than two lines' do
let(:slim) { <<-'SLIM' }
div class='one \
two three four \
five six seven \
eight nine ten eleven twelve'
div =some_method
SLIM

it { should report_lint line: 5 }
end

context 'when it has more than two locations' do
let(:slim) { <<-'SLIM' }
div class='one \
two'
div class='one \
two three four five six seven \
eight nine ten eleven twelve'
div class='one \
two three four five six seven \
eight nine ten eleven twelve'
div=some_method
SLIM

it { should report_lint line: 9 }
end

context 'when it has more than two locations and verify the correctness of the line count.' do
let(:slim) { <<-'SLIM' }
div class='one \
two'
div class='one \
two three four five six seven \
eight nine ten eleven twelve'
div=some_method_one
div class='one \
two three four five six seven \
eight nine ten eleven twelve'
div=some_method_two
SLIM

it { should report_lint line: 6 }
it { should report_lint line: 10 }
end
end

context 'when leading whitespace (=<) is used' do
context 'and it has appropriate spacing' do
let(:slim) { 'title =< "Something"' }
Expand Down

0 comments on commit e72519e

Please sign in to comment.