-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Refactor] minor "if" and "return" improvement #1486
Conversation
nvm.sh
Outdated
setopt nomatch | ||
fi | ||
return 2 | ||
if [ -d "$FILE" ] && ! nvm_check_file_permissions "$FILE"; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isn't the same; if the file is a directory but nvm_check_file_permissions
returns true, i don't want anything to happen. With this change, it ends up hitting the else
branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really, I think here is no else
branch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aha, sorry, you're right, there's no else.
However, in the original code, if the file is a directory, nothing happened outside of the nvm_check_file_permissions
branch - in your new code, if the file is a directory but the permissions check fails, it falls to the elif
- which checks that it exists, and is not writable and not owned (possible for a directory), which means the file-related error message would be printed.
Am I reading this incorrectly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're correct, reverted this part, thanks.
nvm.sh
Outdated
fi | ||
|
||
if [ -n "${NPM_CONFIG_PREFIX-}" ] && ! (nvm_tree_contains_path "$NVM_DIR" "$NPM_CONFIG_PREFIX" >/dev/null 2>&1); then | ||
elif [ -n "${NPM_CONFIG_PREFIX-}" ] && ! (nvm_tree_contains_path "$NVM_DIR" "$NPM_CONFIG_PREFIX" >/dev/null 2>&1); then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need all these elifs; I actually prefer the separate if
blocks here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, reverted both above
a10a5ef
to
315f0df
Compare
No description provided.