mirror of https://github.com/zulip/zulip.git
lint: Add shfmt as a linter.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
dfaea9df65
commit
6099612a15
|
@ -3,15 +3,15 @@ root = true
|
|||
[*]
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.{sh,py,pyi,xml,css,hbs,html}]
|
||||
indent_size = 4
|
||||
binary_next_line = true # for shfmt
|
||||
switch_case_indent = true # for shfmt
|
||||
|
||||
[{*.{js,json,ts},check-openapi}]
|
||||
indent_size = 4
|
||||
max_line_length = 100
|
||||
|
||||
[*.{py,pyi}]
|
||||
|
|
|
@ -381,6 +381,8 @@ def main(options: argparse.Namespace) -> "NoReturn":
|
|||
|
||||
# Install shellcheck.
|
||||
run_as_root(["tools/setup/install-shellcheck"])
|
||||
# Install shfmt.
|
||||
run_as_root(["tools/setup/install-shfmt"])
|
||||
|
||||
setup_venvs.main()
|
||||
|
||||
|
|
|
@ -75,6 +75,9 @@ def run() -> None:
|
|||
"(zerver/openapi/zulip.yaml) ")
|
||||
linter_config.external_linter('shellcheck', ['shellcheck', '-x', '-P', 'SCRIPTDIR'], ['sh'],
|
||||
description="Standard shell script linter")
|
||||
linter_config.external_linter('shfmt', ['shfmt'], ['sh'],
|
||||
check_arg='-d', fix_arg='-w',
|
||||
description="Formats shell scripts")
|
||||
command = ['tools/run-mypy', '--quiet']
|
||||
if args.force:
|
||||
command.append('--force')
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env bash
|
||||
set -eu
|
||||
|
||||
version=3.1.2
|
||||
binary="shfmt_v${version}_linux_amd64"
|
||||
sha256=c5794c1ac081f0028d60317454fe388068ab5af7740a83e393515170a7157dce
|
||||
|
||||
check_version() {
|
||||
out="$(shfmt --version 2>/dev/null)" && [ "$out" = "v$version" ]
|
||||
}
|
||||
|
||||
if ! check_version; then
|
||||
tmpdir="$(mktemp -d)"
|
||||
trap 'rm -r "$tmpdir"' EXIT
|
||||
cd "$tmpdir"
|
||||
wget -nv "https://github.com/mvdan/sh/releases/download/v3.1.2/$binary"
|
||||
sha256sum -c <<<"$sha256 $binary"
|
||||
chmod +x "$binary"
|
||||
mv "$binary" /usr/local/bin/shfmt
|
||||
check_version
|
||||
fi
|
Loading…
Reference in New Issue