Skip to content

Commit

Permalink
Merge branch 'main' into fix_multiline_pipes
Browse files Browse the repository at this point in the history
  • Loading branch information
sds authored Jul 6, 2023
2 parents 8fc1db2 + 92bd0d4 commit 2298240
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# HAML-Lint Changelog

# master (unreleased)

* Fix `Marshal.dump` error when using `--parallel` option and `RepeatedId` Linter
* Improved support for multiline code with RuboCop linting/auto-correction

# 0.47.0
Expand Down
3 changes: 2 additions & 1 deletion lib/haml_lint/linter/repeated_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ class Linter::RepeatedId < Linter
MESSAGE_FORMAT = %{Do not repeat id "#%s" on the page}

def visit_root(_node)
@id_map = Hash.new { |hash, key| hash[key] = [] }
@id_map = {}
end

def visit_tag(node)
id = node.tag_id
return unless id && !id.empty?

id_map[id] ||= []
nodes = (id_map[id] << node)
case nodes.size
when 1 then nil
Expand Down
21 changes: 21 additions & 0 deletions spec/haml_lint/linter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,25 @@ def visit_root(_node)

it { should == 'SomeLinterName' }
end

# Source from https://apidock.com/rails/Class/descendants
linter_classes = []
ObjectSpace.each_object(HamlLint::Linter.singleton_class) do |k|
next if k.singleton_class?
linter_classes.unshift k unless k == self
end
linter_classes.each do |linter_class|
describe "subclass #{linter_class.name}" do
# Needed for parallel mode, because lints are dumped and they refer to the linter
it 'instances can be Marshal.dump' do
document = HamlLint::Document.new('something', config: HamlLint::ConfigurationLoader.default_configuration)
expect do
linter = linter_class.new(config)
linter.run(document)

Marshal.dump(linter)
end.not_to raise_error
end
end
end
end

0 comments on commit 2298240

Please sign in to comment.