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

Style/HashSlice (new in 1.45.0) reports false positives #696

Open
myronmarston opened this issue Feb 21, 2025 · 0 comments
Open

Style/HashSlice (new in 1.45.0) reports false positives #696

myronmarston opened this issue Feb 21, 2025 · 0 comments

Comments

@myronmarston
Copy link

I'm working on upgrading from 1.44.0 to 1.45.0, and I'm finding that 1.45.0 enables the new Style/HashSlice cop is a bit buggy and is failing on a piece of my code that can't actually use .slice like it recommends.

I've reported this bug to RuboCop itself but also wanted to surface it here because it doesn't seem fully ready for inclusion in a curated linter like standard.

Here's an example script that demonstrates the problem:

require "bundler/inline"

gemfile do
  source "https://rubygems.org"

  gem "standard", "1.45.0"
end

referenced_types_by_source_type = {
  "Foo" => ["Foo", "Bar"],
  "Bar" => [],
  "Bazz" => ["Bar"]
}

results = referenced_types_by_source_type
  .select { |source_type, referenced_types| referenced_types.include?(source_type) }

if ENV["PRINT"]
  puts results
end

require "standard"
Standard::Cli.new(["--format", "progress", "--", __FILE__]).run

When I run this, here's the output I get:

Inspecting 1 file
C

Offenses:

standardrb_bug.rb:16:4: C: [Correctable] Style/HashSlice: Use slice(*referenced_types) instead.
  .select { |source_type, referenced_types| referenced_types.include?(source_type) }
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected, 1 more offense can be corrected with `rubocop -A`

...but there's no way to use .slice(...) here.

Should Style/HashSlice be disabled by standardrb until the bugs are fixed in it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant