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

ShellCheck v0.4.7 fixes #1684

Merged
merged 2 commits into from Dec 13, 2017
Merged

Conversation

PeterDaveHello
Copy link
Collaborator

ShellCheck v0.4.7 just released 6 hours ago and hopefully will be deployed on Travis CI soon.
This is the fix for SC2207 and SC1117

@ljharb
Copy link
Member

ljharb commented Dec 9, 2017

Until I can use the updated shellcheck locally, I'm not going to be comfortable landing this.

@ljharb ljharb self-assigned this Dec 9, 2017
@@ -53,7 +53,7 @@ nvm_command_info() {
INFO="$(which "${COMMAND}") ($(type "${COMMAND}" | command awk '{ $1=$2=$3=$4="" ;print }' | command sed -e 's/^\ *//g' -Ee "s/\`|'//g" ))"
elif type "${COMMAND}" | nvm_grep -q "^${COMMAND} is an alias for"; then
INFO="$(which "${COMMAND}") ($(type "${COMMAND}" | command awk '{ $1=$2=$3=$4=$5="" ;print }' | command sed 's/^\ *//g'))"
elif type "${COMMAND}" | nvm_grep -q "^${COMMAND} is \/"; then
elif type "${COMMAND}" | nvm_grep -q "^${COMMAND} is \\/"; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the intention here to grep for $COMMAND is \/ or $COMMAND is /?

https://github.com/koalaman/shellcheck/wiki/SC1117 implies that it probably should have been $COMMAND is /?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$COMMAND is /, the effect here is the same, it won't be $COMMAND is \/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't \\ put a literal backslash into the text?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so but I don't think so now. From SC1117 wiki, looks like it's because we use " not '.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, so '\n' is correct, and "\\n" is the double-quoted equivalent?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems so!

nvm.sh Outdated
@@ -645,16 +645,16 @@ nvm_print_formatted_alias() {
DEST_FORMAT='%s'
VERSION_FORMAT='%s'
local NEWLINE
NEWLINE="\n"
NEWLINE="\\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just doesn't seem right to me. The intention is to insert a literal newline; not to literally add a backslash and an n

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's newline, that's the tricky point I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\\n isn't a newline tho :-/

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really? I tested it with this code block and it looks fine:

export NEWLINE="\n"
command printf -- "${NEWLINE}"
unset NEWLINE
export NEWLINE="\\n"
command printf -- "${NEWLINE}"
unset NEWLINE
command printf -- "${NEWLINE}"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused; does that mean \n and \\n are the same? Or is the former a literal newline, and the latter a literal \n that the shell later turns into a newline?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think they are the same as the wiki mentions, the old usage may be wrong, and just fallback as what we want, that's the reason why they output the same.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so on this line; can it be replaced with '\n'?

bash_completion Outdated
@@ -10,7 +10,7 @@ __nvm_generate_completion()
{
declare current_word
current_word="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=($(compgen -W "$1" -- "$current_word"))
COMPREPLY=("$(compgen -W "$1" -- "$current_word")")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is not the intention to split the output here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My fault.

nvm.sh Outdated
" \
-e "s#^\([^/]\{1,\}\)/\(.*\)\$#\2.\1#;" \
-e "s#^\\([^/]\\{1,\\}\\)/\\(.*\\)\$#\\2.\\1#;" \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of making this line less readable, could it be single-quoted instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it and it seems wrong lol.

nvm.sh Outdated
| command sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n \
| command sed "
s#\(.*\)\.\([^\.]\{1,\}\)\$#\2-\1#;
s#\\(.*\\)\\.\\([^\\.]\\{1,\\}\\)\$#\\2-\\1#;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one combined with shell variable below, I'm not very sure how to deal with it lol

@PeterDaveHello PeterDaveHello force-pushed the ShellCheck-v0.4.7-fixes branch 2 times, most recently from de43f24 to 6632245 Compare December 13, 2017 17:28
nvm.sh Outdated
if [ "_${DEFAULT}" = '_true' ]; then
NEWLINE=" (default)\n"
NEWLINE=" (default)\\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also can this be single-quoted, and then the double backslash removed?

nvm.sh Outdated
fi
local ARROW
ARROW='->'
if [ -z "${NVM_NO_COLORS}" ] && nvm_has_colors; then
ARROW='\033[0;90m->\033[0m'
if [ "_${DEFAULT}" = '_true' ]; then
NEWLINE=" \033[0;37m(default)\033[0m\n"
NEWLINE=" \\033[0;37m(default)\\033[0m\\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also can this be single-quoted, and then the double backslash removed?

nvm.sh Outdated
@@ -1021,25 +1021,23 @@ nvm_ls() {
PATTERN='v'
SEARCH_PATTERN='.*'
else
SEARCH_PATTERN="$(echo "${PATTERN}" | command sed "s#\.#\\\.#g;")"
SEARCH_PATTERN="$(echo "${PATTERN}" | command sed "s#\\.#\\\\.#g;")"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also here

@PeterDaveHello
Copy link
Collaborator Author

Hope this one can be good, replaced those patterns without a variable to use the single quote now.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@PeterDaveHello
Copy link
Collaborator Author

PeterDaveHello commented Dec 13, 2017

Noticed that SC2016 should be disabled for $COMPLETION_STR in install.sh , updated line 329.

@PeterDaveHello
Copy link
Collaborator Author

Tests passed!

@ljharb ljharb merged commit 2a25943 into nvm-sh:master Dec 13, 2017
@PeterDaveHello PeterDaveHello deleted the ShellCheck-v0.4.7-fixes branch December 14, 2017 03:52
edwmurph pushed a commit to edwmurph/nvm that referenced this pull request Apr 9, 2018
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

Successfully merging this pull request may close these issues.

None yet

2 participants