Expected behavior: Running standardrb --fix will not break code.
Observed behavior: standard --fix includes cops which are unsafe.
Environment: Ruby 3.2.0, default standardrb install,
standard (1.28.2)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.50.2)
standard-custom (~> 1.0.0)
standard-performance (~> 1.0.1)
The count cop will transform
hash.select { |k,v| k == "count me" }.count
into
hash.count { |k,v| k == "count me" }
However the count method on a hash does not pass |k,v| to the block, but rather an array, [k,v]. This is not a safe transformation, and requires modification to the block, or the caller for the transformed code to operate correctly eg:
hash.keys.count { |k| k == "count me" }
See this issue in rubocop where they mark the count cop as unsafe, rubocop/rubocop-performance#69