Add shellcheck as a linter.

Fixes #10162.

Tweaked by tabbott to cover documentation as well.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
Anders Kaseorg 2018-08-02 20:09:42 -04:00 committed by Tim Abbott
parent d0fb34e8af
commit c3bd293eaf
6 changed files with 32 additions and 3 deletions

View File

@ -210,10 +210,19 @@ its CSS; see our
[configuration](https://github.com/zulip/zulip/blob/master/.stylelintrc) [configuration](https://github.com/zulip/zulip/blob/master/.stylelintrc)
for the rules we currently enforce. 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 #### Markdown, shell scripts, JSON fixtures
We mostly validate miscellaneous source files like `.sh`, `.json`, and `.md` files for We mostly validate miscellaneous source files like `.json`, and `.md`
whitespace issues. files for whitespace issues.
## Philosophy ## Philosophy

14
scripts/lib/install-shellcheck Executable file
View File

@ -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

View File

@ -260,6 +260,9 @@ def main(options):
print(WARNING + "`yarn install` failed; retrying..." + ENDC) print(WARNING + "`yarn install` failed; retrying..." + ENDC)
setup_node_modules() 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 # Import tools/setup_venv.py instead of running it so that we get an
# activated virtualenv for the rest of the provisioning process. # activated virtualenv for the rest of the provisioning process.
from tools.setup import setup_venvs from tools.setup import setup_venvs

View File

@ -97,6 +97,7 @@ def run():
linter_config.external_linter('templates', ['tools/check-templates'], ['handlebars', 'html']) linter_config.external_linter('templates', ['tools/check-templates'], ['handlebars', 'html'])
linter_config.external_linter('urls', ['tools/check-urls'], ['py']) linter_config.external_linter('urls', ['tools/check-urls'], ['py'])
linter_config.external_linter('swagger', ['node', 'tools/check-swagger'], ['yaml']) 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 # Disabled check for imperative mood until it is stabilized
if not args.no_gitlint: if not args.no_gitlint:

View File

@ -8,6 +8,8 @@ EXCLUDED_FILES = [
"puppet/apt/manifests/release.pp", "puppet/apt/manifests/release.pp",
"puppet/apt/manifests/unattended_upgrades.pp", "puppet/apt/manifests/unattended_upgrades.pp",
"puppet/stdlib/tests/file_line.pp", "puppet/stdlib/tests/file_line.pp",
"puppet/zulip/files/nagios_plugins/zulip_nagios_server/check_website_response.sh",
"scripts/lib/third",
"static/third", "static/third",
# Transifex syncs translation.json files without trailing # Transifex syncs translation.json files without trailing
# newlines; there's nothing other than trailing newlines we'd be # newlines; there's nothing other than trailing newlines we'd be

View File

@ -8,4 +8,4 @@ ZULIP_VERSION = "1.9.0-rc2+git"
# Typically, adding a dependency only requires a minor version bump, and # Typically, adding a dependency only requires a minor version bump, and
# removing a dependency requires a major version bump. # removing a dependency requires a major version bump.
PROVISION_VERSION = '26.9' PROVISION_VERSION = '26.10'