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

allow *%W for better readability (Lint/UnneededSplatExpansion) #7041

Closed
md-work opened this issue May 14, 2019 · 7 comments
Closed

allow *%W for better readability (Lint/UnneededSplatExpansion) #7041

md-work opened this issue May 14, 2019 · 7 comments
Labels
stale Issues that haven't been active in a while

Comments

@md-work
Copy link

md-work commented May 14, 2019

In certain scenarios, using *%W may improve readability. So there should be exceptions to: Lint/UnneededSplatExpansion

Most of those scenarios are when building shell commands.

E.g.:

# filename may be an arbitrary string, containing spaces and other weird stuff.
filename = "file \" ' name.txt"

# Unsafe!
# May lead to wrong behavior. E.g. delete `file` and `name.txt`, but not `file name.txt`.
system('sudo -u ' + target_user + '/usr/bin/rm -r -- ' + filename)
system("sudo -u '#{target_user}' -- /usr/bin/rm -r -- '#{filename}'")

# Safe, but hard to read.
# And this rm example is still a simple shell command.
# Longer shell commands get much harder to read in this style.
system('sudo', '-u', target_user, '/usr/bin/rm', '-r', '--', filename)

# Safe and good to read. But triggers Lint/UnneededSplatExpansion
# *%W[ isn't very pretty to read. But the important shell command is clearly recognizable
system(*%W[sudo -u #{target_user} -- /usr/bin/rm -r -- #{filename}])

Be aware, that system is not the only method covered by this. Open3.... is also affected and I'm actually using a custom method with adds additional checks when running external command. So excluding Lint/UnneededSplatExpansion for certain methods may not be a satisfying solution.

This might sound similar to #3512 and #6146.
But here the problem is, that using *%W explicitly improves readability.

@rrosenblum
Copy link
Contributor

I can see the benefit of improved readability. I feel like this is a highly specific use case. I'm not sure that there is a great solution for this. A few ideas that I have are:

  1. Create a white list of methods that you are allowed to pass splat expansion to
    We could have a default list of methods and allow users to add to the list. I'm not sure how many methods this would need to apply to
  2. Create a configuration that completely ignores *%W
    This would weaken the overall usefulness of this cop. If we go this route, would it be worth while to make all percent variables configurable?
  3. Do nothing and rely on rubocop:disable comments
    This is already supported. It can be annoying to need to flag all of these calls. It also means that other people that contribute to your code should know why the cop is disabled so that they don't change the code.

@stale
Copy link

stale bot commented Aug 12, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

@stale stale bot added the stale Issues that haven't been active in a while label Aug 12, 2019
@md-work
Copy link
Author

md-work commented Aug 13, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

The problem is still present in 0.74.0.

@stale stale bot removed the stale Issues that haven't been active in a while label Aug 13, 2019
@stale
Copy link

stale bot commented Feb 9, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

@stale stale bot added the stale Issues that haven't been active in a while label Feb 9, 2020
@md-work
Copy link
Author

md-work commented Feb 10, 2020

I guess this is still a problem.

@stale stale bot removed the stale Issues that haven't been active in a while label Feb 10, 2020
@stale
Copy link

stale bot commented Aug 8, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

@stale stale bot added the stale Issues that haven't been active in a while label Aug 8, 2020
@stale
Copy link

stale bot commented Nov 7, 2020

This issues been automatically closed due to lack of activity. Feel free to re-open it if you ever come back to it.

@stale stale bot closed this as completed Nov 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Issues that haven't been active in a while
Projects
None yet
Development

No branches or pull requests

2 participants