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/WordArray cop would be more inteligent in case of multidimensional array #10194

Closed
deepj opened this issue Oct 18, 2021 · 3 comments · Fixed by #11334
Closed

Style/WordArray cop would be more inteligent in case of multidimensional array #10194

deepj opened this issue Oct 18, 2021 · 3 comments · Fixed by #11334

Comments

@deepj
Copy link
Contributor

deepj commented Oct 18, 2021

I have some cases of multidimensional array where (from my perspective) default Style/WordArray cop makes the code less readable and confusing. See this example:

CONTENT_TYPE = [
    ['TSR', 'Teaser'],
    ['PRO', 'Promo'],
    ['RTG', 'Rating Tag'],
    ['RTG-F', 'Rating Tag for Feature'],
]

Rubocop forces me to change it to:

CONTENT_TYPE = [
    %w[TSR Teaser],
    %w[PRO Promo],
    ['RTG', 'Rating Tag'],
    ['RTG-F', 'Rating Tag for Feature'],
]

I don't think this helps to better readability. I would wish if this would be valid and fine for default Style/WordArray cop

CONTENT_TYPE = [
    ['TSR', 'Teaser'],
    ['PRO', 'Promo'],
    ['RTG', 'Rating Tag'],
    ['RTG-F', 'Rating Tag for Feature'],
]

Please, consider this as an example ^^.

@deepj deepj changed the title Style/WordArray would be more inteligent in case of multidimensional array Style/WordArray cop would be more inteligent in case of multidimensional array Oct 18, 2021
@tejasbubane
Copy link
Contributor

tejasbubane commented Oct 30, 2021

I would argue that it looks confusing because your arrays happen to have some strings with spaces (which cannot be converted to WordArray). Had it been as follows, it is not confusing anymore:

CONTENT_TYPE = [
    %w[TSR Teaser],
    %w[PRO Promo]
]

However one solution could be to add a configuration flag which disable cop for nested arrays:

# EnabledForNestedArrays: false
# good
CONTENT_TYPE = [
    ['TSR', 'Teaser'],
    ['PRO', 'Promo']
]

# EnabledForNestedArrays: true
# bad
CONTENT_TYPE = [
    ['TSR', 'Teaser'],
    ['PRO', 'Promo']
]

Although I don't prefer adding more complexity with flags, I can put together a PR if maintainers are willing to accept this.

@deepj
Copy link
Contributor Author

deepj commented Apr 26, 2022

@tejasbubane I appreciate your comment but the arrays cannot be changed.

CONTENT_TYPE = [
    ['TSR', 'Teaser'],
    ['PRO', 'Promo'],
    ['RTG', 'Rating Tag'],
    ['RTG-F', 'Rating Tag for Feature'],
]

What I need in this case the cop ignores this kind of arrays. I think your suggestion to turn off it for them is one of the solution.

@koic What do you think?

@deepj
Copy link
Contributor Author

deepj commented Dec 31, 2022

@fatkodima Thank you!

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