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) #56

Closed
md-work opened this issue May 14, 2019 · 1 comment
Closed

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

md-work opened this issue May 14, 2019 · 1 comment

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 is similar to #3512
But here the problem is, that using *%W explicitly improves readability.

@md-work
Copy link
Author

md-work commented May 14, 2019

Moved to: rubocop/rubocop#7041

@md-work md-work closed this as completed May 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant