Skip to content

Commit

Permalink
Improve coverage related to new Rubocop system (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxLap authored Jul 8, 2023
1 parent f425d19 commit 154fb1c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
20 changes: 0 additions & 20 deletions lib/haml_lint/ruby_extraction/haml_comment_chunk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,6 @@ def fuse(following_chunk)
HamlCommentChunk.new(node, @ruby_lines + following_chunk.ruby_lines, end_marker_indent: end_marker_indent)
end

def fuse_script_chunk(following_chunk)
return if following_chunk.end_marker_indent.nil?
return if following_chunk.must_start_chunk

nb_blank_lines_between = following_chunk.haml_line_index - haml_line_index - nb_haml_lines
blank_lines = nb_blank_lines_between > 0 ? [''] * nb_blank_lines_between : []
new_lines = @ruby_lines + blank_lines + following_chunk.ruby_lines

source_map_skips = @skip_line_indexes_in_source_map
source_map_skips.concat(following_chunk.skip_line_indexes_in_source_map
.map { |i| i + @ruby_lines.size })

ScriptChunk.new(node,
new_lines,
haml_line_index: haml_line_index,
skip_line_indexes_in_source_map: source_map_skips,
end_marker_indent: following_chunk.end_marker_indent,
previous_chunk: previous_chunk)
end

def transfer_correction_logic(_coordinator, to_ruby_lines, haml_lines)
if to_ruby_lines.empty?
haml_lines.slice!(@haml_line_index..haml_end_line_index)
Expand Down
13 changes: 11 additions & 2 deletions spec/haml_lint/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

context 'general tests' do
let(:files) { %w[file1.slim file2.slim] }
let(:mock_linter) { double('linter', lints: [], name: 'Blah') }

let(:options) do
base_options.merge(reporter: reporter)
Expand Down Expand Up @@ -90,13 +89,23 @@
include_context 'isolated environment'

before do
`echo "%div{ class: 'foo' } hello" > example.haml`
`echo "%div{ class: 'foo' } hello" > example.haml`
end

it 'successfully reports those errors' do
runner.unstub(:collect_lints)
expect(subject.lints.first.message).to match(/Avoid defining `class` in attributes hash/)
end

context 'with autocorrect on' do
let(:options) { super().merge(autocorrect: :all) }

it 'successfully fixes those errors' do
runner.unstub(:collect_lints)
expect(subject.lints.detect(&:corrected).message).to match(/Unnecessary spacing detected./)
expect(File.read('example.haml')).to eq("%div{ class: 'foo' } hello\n")
end
end
end
end

Expand Down

0 comments on commit 154fb1c

Please sign in to comment.