From 154fb1c4490fea053a2dc15196a9c27ea1fddd24 Mon Sep 17 00:00:00 2001 From: Maxime Lapointe Date: Sat, 8 Jul 2023 13:49:56 -0400 Subject: [PATCH] Improve coverage related to new Rubocop system (#418) --- .../ruby_extraction/haml_comment_chunk.rb | 20 ------------------- spec/haml_lint/runner_spec.rb | 13 ++++++++++-- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/lib/haml_lint/ruby_extraction/haml_comment_chunk.rb b/lib/haml_lint/ruby_extraction/haml_comment_chunk.rb index 3e5afc81..0d195e8f 100644 --- a/lib/haml_lint/ruby_extraction/haml_comment_chunk.rb +++ b/lib/haml_lint/ruby_extraction/haml_comment_chunk.rb @@ -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) diff --git a/spec/haml_lint/runner_spec.rb b/spec/haml_lint/runner_spec.rb index 4d976f9b..c562f5d2 100644 --- a/spec/haml_lint/runner_spec.rb +++ b/spec/haml_lint/runner_spec.rb @@ -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) @@ -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