Skip to content

Add shellcheck for bash completion#266

Merged
vdemeester merged 5 commits into
docker:masterfrom
jphuynh:shellcheck
Jul 18, 2017
Merged

Add shellcheck for bash completion#266
vdemeester merged 5 commits into
docker:masterfrom
jphuynh:shellcheck

Conversation

@jphuynh
Copy link
Copy Markdown
Contributor

@jphuynh jphuynh commented Jun 29, 2017

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.validate instead of Dockerfile.dev

Copy link
Copy Markdown
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor: could we name this file Dockerfile.shellcheck or Dockerfile.shellvalidate so that it's clear that it's different from "go validation"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep works for me.

Comment thread docker.Makefile Outdated
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't we also validate everything under scripts/ ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SGTM

@codecov-io
Copy link
Copy Markdown

codecov-io commented Jun 29, 2017

Codecov Report

Merging #266 into master will not change coverage.
The diff coverage is n/a.

@@           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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like there are some warnings related to koalaman/shellcheck#785, but probably not an issue.

Could we use debian:jessie here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 :)

Comment thread dockerfiles/Dockerfile.shellcheck Outdated
apt-get -y install make shellcheck && \
apt-get clean

WORKDIR /tmp
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

LGTM

@dnephin
Copy link
Copy Markdown
Contributor

dnephin commented Jun 30, 2017

cc @albers

@dnephin dnephin requested a review from vdemeester July 6, 2017 14:47
@dnephin
Copy link
Copy Markdown
Contributor

dnephin commented Jul 6, 2017

looks like this needs a rebase

Copy link
Copy Markdown
Collaborator

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

LGTM 🐸

@dnephin
Copy link
Copy Markdown
Contributor

dnephin commented Jul 6, 2017

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.

@albers
Copy link
Copy Markdown
Collaborator

albers commented Jul 7, 2017

@jphuynh How can I invoke shellcheck? I tried make -f docker.Makefile shellcheck but got error messages:

$ 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 argument

exit 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.

Copy link
Copy Markdown
Collaborator

@albers albers left a comment

Choose a reason for hiding this comment

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

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.

Comment thread contrib/completion/bash/docker Outdated
esac
done
__docker_complete_containers_removable
__docker_complete_containers_removable "$@"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This addition does not make sense.

Comment thread contrib/completion/bash/docker Outdated
;;
*)
__docker_complete_containers_stopped
__docker_complete_containers_stopped "$@"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same as above: why did you add this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment thread contrib/completion/bash/docker Outdated
if [ $cword -eq $counter ]; then
__docker_complete_containers_unpauseable
if [ "$cword" -eq "$counter" ]; then
__docker_complete_containers_unpauseable "$@"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

see above

Comment thread contrib/completion/bash/docker Outdated
;;
--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:]')" ) )
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please remove the extra blank (probably came back in the rebase)

Comment thread contrib/completion/bash/docker Outdated
if [ "$cword" -eq "$counter" ]; then
__docker_complete_networks
elif [ $cword -eq $(($counter + 1)) ]; then
elif [ "$cword" -eq $((counter + 1)) ]; then
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

To be consistent, the second expression should be quoted as well (see line 1101).

Comment thread contrib/completion/bash/docker Outdated

_docker_rm() {
_docker_container_rm
_docker_container_rm "$@"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

see above, please remove.

Comment thread contrib/completion/bash/docker Outdated

_docker_start() {
_docker_container_start
_docker_container_start "$@"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

see above, please remove.

Comment thread contrib/completion/bash/docker Outdated

_docker_unpause() {
_docker_container_unpause
_docker_container_unpause "$@"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

see above, please remove.

Comment thread contrib/completion/bash/docker Outdated
esac

local repo_print_command
# shellcheck disable=SC2016
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Comment thread contrib/completion/bash/docker Outdated
@@ -1,4 +1,8 @@
#!/usr/bin/env bash
# shellcheck disable=SC2155
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add a comment where to find documentation on shellcheck warnings: https://github.com/koalaman/shellcheck/wiki/SCXXXX

@dnephin
Copy link
Copy Markdown
Contributor

dnephin commented Jul 13, 2017

Now that #206 is merged this can be updated to use the shared engine (see the new circle.yml config)

jphuynh and others added 4 commits July 13, 2017 22:24
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>
@jphuynh jphuynh force-pushed the shellcheck branch 2 times, most recently from 274f02d to f708621 Compare July 13, 2017 21:36
Copy link
Copy Markdown
Collaborator

@albers albers left a comment

Choose a reason for hiding this comment

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

Great work, @jphuynh!
Found only minor nits, please update.

Comment thread contrib/completion/bash/docker Outdated
if [ $cword -eq $counter ]; then
__docker_complete_services_and_tasks
if [ "$cword" -eq "$counter" ]; then
__docker_complete_services_and_tasks "$@"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please remove the argument

__docker_complete_containers_running() {
__docker_complete_containers "$@" --filter status=running
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please do not remove this blank line.

Signed-off-by: Jean-Pierre Huynh <jean-pierre.huynh@ounet.fr>
Copy link
Copy Markdown
Collaborator

@albers albers left a comment

Choose a reason for hiding this comment

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

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.

@vdemeester vdemeester merged commit b75596e into docker:master Jul 18, 2017
@GordonTheTurtle GordonTheTurtle added this to the 17.07.0 milestone Jul 18, 2017
@jphuynh jphuynh deleted the shellcheck branch July 21, 2017 10:33
@albers albers mentioned this pull request Aug 3, 2018
nobiit pushed a commit to nobidev/docker-cli that referenced this pull request Nov 19, 2025
[17.10] Backport version fix for Windows manifest lists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants