Skip to content

Detect unnecessary stringify_keys/symbolize_keys calls #1332

Open
@fatkodima

Description

@fatkodima

In our app, I noticed a lot of unnecessary usage of the mentioned methods when we can just rewrite the hash definition (or the hash is already having the right format, so method call is not needed).

# bad
SomeJob.perform_async({ foo: 1, bar: 2 }.stringify_keys)

# good
SomeJob.perform_async({ "foo" => 1, "bar" => 2 })

I was also able to find a few offences in OSS projects, for example gitlab.

1 offense for symbolize_keys https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/instrumentation/redis_payload.rb#L22-29

and 54 offenses for stringify_keyslike https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/models/lfs_download_object.rb#L23-28

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions