Skip to content

Commit

Permalink
Add shellcheck as a linter.
Browse files Browse the repository at this point in the history
Fixes zulip#10162.

Tweaked by tabbott to cover documentation as well.

Signed-off-by: Anders Kaseorg <[email protected]>
  • Loading branch information
andersk authored and timabbott committed Oct 18, 2018
1 parent d0fb34e commit c3bd293
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 3 deletions.
13 changes: 11 additions & 2 deletions docs/testing/linters.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,19 @@ its CSS; see our
[configuration](https://github.com/zulip/zulip/blob/master/.stylelintrc)
for the rules we currently enforce.

#### Shell scripts

Zulip uses [shellcheck](https://github.com/koalaman/shellcheck) to
lint our shell scripts. We recommend the
[shellcheck gallery of bad code][shellcheck-bad-code] as a resource on
how to not write bad shell.

[shellcheck-bad-code]: https://github.com/koalaman/shellcheck/blob/master/README.md#user-content-gallery-of-bad-code

#### Markdown, shell scripts, JSON fixtures

We mostly validate miscellaneous source files like `.sh`, `.json`, and `.md` files for
whitespace issues.
We mostly validate miscellaneous source files like `.json`, and `.md`
files for whitespace issues.

## Philosophy

Expand Down
14 changes: 14 additions & 0 deletions scripts/lib/install-shellcheck
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -eu

version=0.5.0

if ! out="$(shellcheck --version 2>/dev/null)" || [[ "$out" != *"
version: $version
"* ]]; then
tmpdir="$(mktemp -d)"
trap 'rm -r "$tmpdir"' EXIT
cd "$tmpdir"
wget -nv "https://storage.googleapis.com/shellcheck/shellcheck-v$version.linux.x86_64.tar.xz"
tar -xJf "shellcheck-v$version.linux.x86_64.tar.xz" --no-same-owner --strip-components=1 -C /usr/local/bin "shellcheck-v$version/shellcheck"
fi
3 changes: 3 additions & 0 deletions tools/lib/provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ def main(options):
print(WARNING + "`yarn install` failed; retrying..." + ENDC)
setup_node_modules()

# Install shellcheck.
run(["sudo", "scripts/lib/install-shellcheck"])

# Import tools/setup_venv.py instead of running it so that we get an
# activated virtualenv for the rest of the provisioning process.
from tools.setup import setup_venvs
Expand Down
1 change: 1 addition & 0 deletions tools/lint
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def run():
linter_config.external_linter('templates', ['tools/check-templates'], ['handlebars', 'html'])
linter_config.external_linter('urls', ['tools/check-urls'], ['py'])
linter_config.external_linter('swagger', ['node', 'tools/check-swagger'], ['yaml'])
linter_config.external_linter('shellcheck', ['shellcheck', '-x'], ['sh'])

# Disabled check for imperative mood until it is stabilized
if not args.no_gitlint:
Expand Down
2 changes: 2 additions & 0 deletions tools/linter_lib/exclude.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"puppet/apt/manifests/release.pp",
"puppet/apt/manifests/unattended_upgrades.pp",
"puppet/stdlib/tests/file_line.pp",
"puppet/zulip/files/nagios_plugins/zulip_nagios_server/check_website_response.sh",
"scripts/lib/third",
"static/third",
# Transifex syncs translation.json files without trailing
# newlines; there's nothing other than trailing newlines we'd be
Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
# Typically, adding a dependency only requires a minor version bump, and
# removing a dependency requires a major version bump.

PROVISION_VERSION = '26.9'
PROVISION_VERSION = '26.10'

0 comments on commit c3bd293

Please sign in to comment.