Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Fix Linter ControlStatementSpacing raise incorrect = (#164)" #169

Merged
merged 1 commit into from
Jan 16, 2024
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
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