Skip to content

Commit bc2786a

Browse files
committed
[#2351] Honored '@Formatter:off' markers in 'lint.scripts.sh' for shfmt.
1 parent bc9c3b5 commit bc2786a

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

.vortex/tests/lint.scripts.sh

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,30 @@ ROOT_DIR="$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)")"
1111

1212
[ ! -f "${ROOT_DIR}/.vortex/tests/vendor/bin/shellvar" ] && composer --working-dir="${ROOT_DIR}/.vortex/tests" install
1313

14+
# Mask out lines between '# @formatter:off' and '# @formatter:on' so that
15+
# shfmt does not reformat helper functions that are intentionally kept on
16+
# a single line. Each masked line is replaced with a ':' (no-op) placeholder
17+
# indented to match the '# @formatter:off' line's own indentation, so the
18+
# surrounding code parses as valid bash at the expected scope.
19+
mask_protected() {
20+
awk '
21+
/# @formatter:off/ {
22+
in_block = 1
23+
match($0, /^[[:space:]]*/)
24+
indent = substr($0, 1, RLENGTH)
25+
print
26+
next
27+
}
28+
/# @formatter:on/ {
29+
in_block = 0
30+
print
31+
next
32+
}
33+
in_block { print indent ":"; next }
34+
{ print }
35+
' "${1}"
36+
}
37+
1438
targets=()
1539
while IFS= read -r -d $'\0'; do
1640
targets+=("${REPLY}")
@@ -37,7 +61,7 @@ for file in "${targets[@]}"; do
3761
exit 1
3862
fi
3963

40-
if ! LC_ALL=C.UTF-8 shfmt -i 2 -ci -s -d "${file}"; then
64+
if ! mask_protected "${file}" | LC_ALL=C.UTF-8 shfmt -i 2 -ci -s -d; then
4165
exit 1
4266
fi
4367
fi

0 commit comments

Comments
 (0)