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

Support array inclusion checks for Style/HashExcept #10698

Closed
Darhazer opened this issue Jun 7, 2022 · 0 comments · Fixed by #10699
Closed

Support array inclusion checks for Style/HashExcept #10698

Darhazer opened this issue Jun 7, 2022 · 0 comments · Fixed by #10699

Comments

@Darhazer
Copy link
Member

Darhazer commented Jun 7, 2022

Is your feature request related to a problem? Please describe.

Given the following code:

{foo: 1, bar: 2, baz: 3}.reject { |k, _v| k.in?(%I[bar baz]) }

Style/HashExcept does not trigger an offense, as currently it only support equality checks

Describe the solution you'd like

It should suggest:

{foo: 1, bar: 2, baz: 3}.except(:bar, :baz)

Here are some other usages that could be detected:

{foo: 1, bar: 2, baz: 3}.reject { |k, _v| k.in?(SOME_CONSTANT) }
{foo: 1, bar: 2, baz: 3}.reject { |k, _v| k.in?(some_var) }
{foo: 1, bar: 2, baz: 3}.reject { |k, _v| %I[bar baz].include?(k) }
{foo: 1, bar: 2, baz: 3}.select { |k, _v| %I[bar baz].exclude?(k) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant