Add shellcheck for bash completion#266
Conversation
dnephin
left a comment
There was a problem hiding this comment.
For some reason only 2 of the 5 CI jobs ran. It looks like it doesn't have any workflows: https://circleci.com/gh/docker/workflows/cli/tree/pull%2F266
Did you setup circleCI to test your fork? I think that caused problems for me in the past.
If you disable it for your fork and force push, it should trigger a new build.
| @@ -0,0 +1,9 @@ | |||
| FROM debian:stretch-slim | |||
There was a problem hiding this comment.
Minor: could we name this file Dockerfile.shellcheck or Dockerfile.shellvalidate so that it's clear that it's different from "go validation"
| DEV_DOCKER_IMAGE_NAME = docker-cli-dev | ||
| LINTER_IMAGE_NAME = docker-cli-lint | ||
| CROSS_IMAGE_NAME = docker-cli-cross | ||
| VALIDATE_IMAGE_NAME = docker-cli-validate |
There was a problem hiding this comment.
s/docker-cli-validate/docker-cli-shell-validate
| # Maintain an array of files to shellcheck not the best solution but will do for the time being | ||
| FILES=() | ||
| FILES+=("contrib/completion/bash/docker") | ||
| FILES+=("scripts/validate/shellcheck") |
There was a problem hiding this comment.
Shouldn't we also validate everything under scripts/ ?
There was a problem hiding this comment.
We should but the intent of this initial PR is to introduce shellcheck validation. I don't want it to end up like my original PR on the Moby project where it started to be very difficult to review and merge.
The idea is once we have that integrated to the build, we start adding the rest of scripts/
Codecov Report
@@ Coverage Diff @@
## master #266 +/- ##
=======================================
Coverage 48.85% 48.85%
=======================================
Files 186 186
Lines 12413 12413
=======================================
Hits 6064 6064
Misses 5975 5975
Partials 374 374 |
| @@ -0,0 +1,9 @@ | |||
| FROM debian:stretch-slim | |||
There was a problem hiding this comment.
Looks like there are some warnings related to koalaman/shellcheck#785, but probably not an issue.
Could we use debian:jessie here?
There was a problem hiding this comment.
I noticed that as well. The problem with debian:jessie is the version of Shellcheck. (See: moby/moby#33260 (comment)).
I would have to recompile from source which involves cabal-install. I'm not sure it's worth the effort but I understand those warnings annoy me as well :)
| apt-get -y install make shellcheck && \ | ||
| apt-get clean | ||
|
|
||
| WORKDIR /tmp |
There was a problem hiding this comment.
Minor: could we use /go/src/github.com/docker/cli here too? It just makes it easier to re-use MOUNTS in the docker.Makefile if the code is mounted at the same place in all conatiners.
|
cc @albers |
|
looks like this needs a rebase |
|
I think we can merge this, but I'd like to give @albers a chance to take a look at it first, since he's the primary contributor to the bash completion. |
|
@jphuynh How can I invoke shellcheck? I tried $ make -f docker.Makefile shellcheck
[...]
docker run -ti --rm -v "/home/user/go/src/github.com/docker/cli":/go/src/github.com/docker/cli docker-cli-shell-validate make shellcheck
scripts/validate/shellcheck
shellcheck: unable to decommit memory: Invalid argument
shellcheck: unable to decommit memory: Invalid argument
shellcheck: unable to decommit memory: Invalid argumentexit code was 0, though. edit: looks like the messages are just warnings that can be ignored. If I introduce a problem, shellcheck reports it when invoked as mentioned above. |
albers
left a comment
There was a problem hiding this comment.
I'm not familiar with the build and CI scripts, so my review is just about bash completion.
I found some minor nits, please update.
| esac | ||
| done | ||
| __docker_complete_containers_removable | ||
| __docker_complete_containers_removable "$@" |
There was a problem hiding this comment.
This addition does not make sense.
| ;; | ||
| *) | ||
| __docker_complete_containers_stopped | ||
| __docker_complete_containers_stopped "$@" |
There was a problem hiding this comment.
Same as above: why did you add this?
There was a problem hiding this comment.
TBH I didn't even check. It's coming from my previous PR and are leftovers of an attempt to automate certain rules on my side. It didn't work really great.
| if [ $cword -eq $counter ]; then | ||
| __docker_complete_containers_unpauseable | ||
| if [ "$cword" -eq "$counter" ]; then | ||
| __docker_complete_containers_unpauseable "$@" |
| ;; | ||
| --storage-driver|-s) | ||
| COMPREPLY=( $( compgen -W "aufs btrfs devicemapper overlay overlay2 vfs zfs" -- "$(echo $cur | tr '[:upper:]' '[:lower:]')" ) ) | ||
| COMPREPLY=( $( compgen -W "aufs btrfs devicemapper overlay overlay2 vfs zfs" -- "$(echo "$cur" | tr '[:upper:]' '[:lower:]')" ) ) |
There was a problem hiding this comment.
Please remove the extra blank (probably came back in the rebase)
| if [ "$cword" -eq "$counter" ]; then | ||
| __docker_complete_networks | ||
| elif [ $cword -eq $(($counter + 1)) ]; then | ||
| elif [ "$cword" -eq $((counter + 1)) ]; then |
There was a problem hiding this comment.
To be consistent, the second expression should be quoted as well (see line 1101).
|
|
||
| _docker_rm() { | ||
| _docker_container_rm | ||
| _docker_container_rm "$@" |
|
|
||
| _docker_start() { | ||
| _docker_container_start | ||
| _docker_container_start "$@" |
|
|
||
| _docker_unpause() { | ||
| _docker_container_unpause | ||
| _docker_container_unpause "$@" |
| esac | ||
|
|
||
| local repo_print_command | ||
| # shellcheck disable=SC2016 |
There was a problem hiding this comment.
I think SC2016 is so basic that we should not warn about it.
We have several computed awk expressions that all produce these warnings. Please add SC2016 to the general exclusions.
| @@ -1,4 +1,8 @@ | |||
| #!/usr/bin/env bash | |||
| # shellcheck disable=SC2155 | |||
There was a problem hiding this comment.
Please add a comment where to find documentation on shellcheck warnings: https://github.com/koalaman/shellcheck/wiki/SCXXXX
|
Now that #206 is merged this can be updated to use the shared engine (see the new circle.yml config) |
Signed-off-by: Jean-Pierre Huynh <jean-pierre.huynh@ounet.fr>
Signed-off-by: Jean-Pierre Huynh <jean-pierre.huynh@ounet.fr>
Signed-off-by: Jean-Pierre Huynh <jean-pierre.huynh@ounet.fr>
Signed-off-by: Jean-Pierre Huynh <jean-pierre.huynh@ounet.fr>
274f02d to
f708621
Compare
| if [ $cword -eq $counter ]; then | ||
| __docker_complete_services_and_tasks | ||
| if [ "$cword" -eq "$counter" ]; then | ||
| __docker_complete_services_and_tasks "$@" |
There was a problem hiding this comment.
Please remove the argument
| __docker_complete_containers_running() { | ||
| __docker_complete_containers "$@" --filter status=running | ||
| } | ||
|
|
There was a problem hiding this comment.
Please do not remove this blank line.
Signed-off-by: Jean-Pierre Huynh <jean-pierre.huynh@ounet.fr>
albers
left a comment
There was a problem hiding this comment.
LGTM
Thanks very much for your patience and repeated re-work.
Some of the warnigs in bash completion can be removed through code changes, but this is out of scope of this PR. I will take care of this in a follow-up.
@thaJeztah I'd like to merge this but I haven't got permission to do so. Can I please get the required privileges? After all, this repo is my primary field of work.
[17.10] Backport version fix for Windows manifest lists
Signed-off-by: Jean-Pierre Huynh jean-pierre.huynh@ounet.fr
This is the equivalent of the PR from the moby project before cli was relocated here (See: moby/moby#33260).
A new docker image has been added because of the lack of a precompiled version of shellcheck on Alpine. Installing the dependencies and compiling from source would take more build time.
Eventually it would be nice to merge the validate and shellcheck jobs to use only
Dockerfile.validateinstead ofDockerfile.dev