Add new Rails/JSONSymbolizeNames cop#1534
Conversation
5d3d3cd to
d75d110
Compare
|
Could you first propose this style to the style guide? |
| # JSON.parse(json, symbolize_names: true) | ||
| # | ||
| class JSONSymbolizeNames < Base | ||
| MSG = 'Use `symbolize_names` option.' |
There was a problem hiding this comment.
This message only shows the option name, which might make it difficult for users to understand the expected action in their code. It may be simpler to provide autocorrection and show the corrected code instead.
There was a problem hiding this comment.
I've implemented autocorrection
…ep_symbolize_keys` ref: rubocop/rubocop-rails#1534
fb6b1c1 to
62d7df0
Compare
From the issue:
So seems like this cop is acceptable, could you please take a look? @koic |
62d7df0 to
5622ae7
Compare
5622ae7 to
19e40c1
Compare
I've seen this pattern a lot: ```ruby JSON.parse(large_json).deep_symbolize_keys ``` instead of travesing Ruby hash once more we can use the `symbolize_names` option: ```ruby JSON.parse(large_json, symbolize_names: true) ``` Caveats / FP scenarios: 1. `symbolize_names` does not work if `create_addition` option is provided. 2. User might use both `symbolize_names: false` and `deep_symbolize_keys`. 3. There's no autocorrection yet, but it should be easy to add.
19e40c1 to
750fbc7
Compare
|
Pinging since there's no activity for 2 months @koic Can we either close or merge it? |
|
It follows the direction of rubocop/rails-style-guide#372, and since progress on the style guide has stalled, this PR has also been on hold. |
I've seen this pattern a lot:
instead of travesing Ruby hash once more we can use the
symbolize_namesoption:Caveats / FP scenarios:
symbolize_namesdoes not work ifcreate_additionoption is provided.symbolize_names: falseanddeep_symbolize_keys.Before submitting the PR make sure the following are checked:
master(if not - rebase it).bundle exec rake default. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.mdif the new code introduces user-observable changes. See changelog entry format for details.