Repository navigation
Expand file tree
/
Copy pathlint
More file actions
executable file
·88 lines (75 loc) · 3.02 KB
/
Copy pathlint
File metadata and controls
executable file
·88 lines (75 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
# Copyright Materialize, Inc. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.
#
# lint — complains about misformatted files.
set -euo pipefail
cd "$(dirname "$0")/.."
. misc/shlib/shlib.bash
if [[ ! "${MZDEV_NO_SHELLCHECK:-}" ]]; then
if ! command_exists shellcheck; then
echo -e "lint: $(red fatal:) unable to find \`shellcheck\` command on your system" >&2
echo -e "hint: https://github.com/koalaman/shellcheck#installing" >&2
echo -e "hint: you can disable shellcheck locally by setting \$MZDEV_NO_SHELLCHECK=1" >&2
exit 1
fi
version=$(shellcheck --version | grep version: | grep -oE "[0-9]\.[0-9]\.[0-9]" || echo "0.0.0+unknown")
if ! version_compat "0.7.0" "$version"; then
echo -e "lint: $(red fatal:) shellcheck v0.7.0+ is required" >&2
echo -e "hint: detected version \"$version\"" >&2
echo -e "hint: you can disable shellcheck locally by setting \$MZDEV_NO_SHELLCHECK=1" >&2
exit 1
fi
fi
files=$(git_files)
copyright_files=$(grep -vE \
-e '(^|/)LICENSE$' \
-e '(^|/)\.(docker|git|vscode)ignore$' \
-e '(^|/)\.gitattributes$' \
-e '(^|/)\.gitmodules$' \
-e '(^|/)go\.sum$' \
-e '(^|/)(Cargo|askama)\.toml$' \
-e '^\.cargo/config$' \
-e '^Cargo\.lock$' \
-e '^deny\.toml$' \
-e '^netlify\.toml$' \
-e '^rust-toolchain$' \
-e '^rustfmt\.toml$' \
-e '(^|/)yarn\.lock$' \
-e '(^|/)requirements.*\.txt$' \
-e '\.(md|json|asc|png|jpe?g|svg|avro|pb|ico|html)$' \
-e '^doc/user/.*(\.scss|\.bnf|\.toml|\.yml)$' \
-e '^ci/builder/(ssh_known_hosts|stable.stamp|nightly.stamp|crosstool.defconfig)$' \
-e '^ci/www/public/_redirects$' \
-e 'demo/chbench/chbench' \
-e 'test/sqllogictest/postgres/testdata/.*\.data' \
-e 'test/pgtest/.*\.pt' \
-e 'gen/.*\.rs' \
<<< "$files"
)
# Only binary files are permitted to omit a trailing newline. If you're here to
# exclude a text file that is missing its trailing newline, like an SVG, add
# a trailing newline to the text file instead.
newline_files=$(grep -vE '\.(png|jpe?g|pb|avro|ico)$' <<< "$files")
shell_files=$(sort -u <(git_files '*.sh' '*.bash') <(git grep -l '#!.*bash' -- ':!*.*'))
try xargs -n1 awk -f misc/lint/copyright.awk <<< "$copyright_files"
try xargs misc/lint/trailing-newline.sh <<< "$newline_files"
try xargs git --no-pager diff --check "$(git_empty_tree)" <<< "$newline_files"
if [[ ! "${MZDEV_NO_SHELLCHECK:-}" ]]; then
try xargs shellcheck -P SCRIPTDIR <<< "$shell_files"
fi
if [[ ! "${MZDEV_NO_PYTHON:-}" ]]; then
try bin/pycheck
try bin/pyfmt --diff --check --quiet
if try_last_failed; then
echo "lint: $(red error:) python formatting discrepancies found"
echo "hint: run bin/pyfmt" >&2
fi
fi
try_finish