improve linting#12023
Conversation
| PARTITION=${DISK}1p1 | ||
|
|
||
| [ -e "${PARTITION}" ] && mount -o "${MOUNT_ARGS}" -t vfat "${PARTITION}" /mnt/sd | ||
|
|
There was a problem hiding this comment.
I'd rather keep the newlines at end of file.
There was a problem hiding this comment.
OK, but it's a shfmt issue (with a newer version: 3.7.0), so how do you tell it to ignore those?
Out of curiosity, what's the rational?
There was a problem hiding this comment.
Out of curiosity, what's the rational?
Better diffs, consistency, etc.
There was a problem hiding this comment.
I guess we can use --ignore-blank-lines in base/utils/shellcheck.sh
--- i/utils/shellcheck.sh
+++ w/utils/shellcheck.sh
@@ -40,7 +40,7 @@ shfmt() {
}
diff() {
- local cmd=(command diff --unified)
+ local cmd=(command diff --ignore-blank-lines --unified)
if [[ -n "${CLICOLOR_FORCE}" ]]; then
cmd+=(--color=always)
fiThere was a problem hiding this comment.
It says here that "shfmt enforces trailing newlines"
mvdan/sh#733 (comment)
There was a problem hiding this comment.
Complain how?
# as is
$ shfmt_v3.8.0_linux_amd64 -i 4 enable-usbms.sh | diff enable-usbms.sh -
# no newline
$ shfmt_v3.8.0_linux_amd64 -i 4 enable-usbms.sh | diff enable-usbms.sh -
33c33
< sleep 1
\ No newline at end of file
---
> sleep 1
# two newline
$ shfmt_v3.8.0_linux_amd64 -i 4 enable-usbms.sh | diff enable-usbms.sh -
34d33
<
There was a problem hiding this comment.
It's disable-usbms.sh:
▸ tail -3 platform/cervantes/disable-usbms.sh
[ -e "${PARTITION}" ] && mount -o "${MOUNT_ARGS}" -t vfat "${PARTITION}" /mnt/sd
▸ for v in 3.4.3 3.7.0 3.8.0; do ./bin/shfmt_v${v}_linux_amd64 -i 4 -ci platform/cervantes/disable-usbms.sh | diff -u platform/cervantes/disable-usbms.sh -; done
--- platform/cervantes/disable-usbms.sh 2024-06-13 22:59:13.312754354 +0200
+++ - 2024-06-13 23:03:42.134574804 +0200
@@ -23,4 +23,3 @@
PARTITION=${DISK}1p1
[ -e "${PARTITION}" ] && mount -o "${MOUNT_ARGS}" -t vfat "${PARTITION}" /mnt/sd
-
--- platform/cervantes/disable-usbms.sh 2024-06-13 22:59:13.312754354 +0200
+++ - 2024-06-13 23:03:42.136661755 +0200
@@ -23,4 +23,3 @@
PARTITION=${DISK}1p1
[ -e "${PARTITION}" ] && mount -o "${MOUNT_ARGS}" -t vfat "${PARTITION}" /mnt/sd
-
--- platform/cervantes/disable-usbms.sh 2024-06-13 22:59:13.312754354 +0200
+++ - 2024-06-13 23:03:42.139547704 +0200
@@ -23,4 +23,3 @@
PARTITION=${DISK}1p1
[ -e "${PARTITION}" ] && mount -o "${MOUNT_ARGS}" -t vfat "${PARTITION}" /mnt/sd
-There was a problem hiding this comment.
Ohhhkay, giant miscommunication. I thought you were removing the trailing newline but you were removing an additional improperly trailing newline.
But why aren't we seeing it in the output right now? As stated, every version behaves exactly the same in this regard.
There was a problem hiding this comment.
Because of the way the check was done with [[ "$(cat t)" = "$($shfmt -i 4 -ci t)" ]], see comment above.
There was a problem hiding this comment.
I thought you were removing the trailing newline but you were removing an additional improperly trailing newline.
This incidentally is exactly the reason it should be there, so as not to produce diffs that are distracting at best and misleading at worst. But clearly I should head off to bed. ;-)
e12b849 to
3d9312c
Compare
|
The plot thickens… Why is that file not being checked on my side? o.O |
|
The fix: .ci/helper_shellchecks.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git i/.ci/helper_shellchecks.sh w/.ci/helper_shellchecks.sh
index f273d53e51..bdd69b3cb9 100755
--- i/.ci/helper_shellchecks.sh
+++ w/.ci/helper_shellchecks.sh
@@ -5,6 +5,6 @@ CI_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${CI_DIR}/common.sh"
# shellcheck disable=2016
-mapfile -t shellscript_locations < <({ git grep -lE '^#!(/usr)?/bin/(env )?(bash|sh)' | sed "/^plugins\/terminal.koplugin\/shfm$/d" && git submodule --quiet foreach '[ "$path" = "base" -o "$path" = "platform/android/luajit-launcher" ] || git grep -lE "^#!(/usr)?/bin/(env )?(bash|sh)" | sed "s|^|$path/|"' && git ls-files ./*.sh; } | sort | uniq)
+mapfile -t shellscript_locations < <({ git grep -lE '^#!(/usr)?/bin/(env )?(bash|sh)' | sed "/^plugins\/terminal.koplugin\/shfm$/d" && git submodule --quiet foreach '[ "$path" = "base" -o "$path" = "platform/android/luajit-launcher" ] || git grep -lE "^#!(/usr)?/bin/(env )?(bash|sh)" | sed "s|^|$path/|"' && git ls-files './*.sh'; } | sort | uniq)
./base/utils/shellcheck.sh "${shellscript_locations[@]}"Different bash config I guess? |
|
Base potentially suffers from the same issue. |
|
Nope, some stray shell scripts at the root of the checkout: ▸ ls *.sh
env.sh pouet.shSo the glob matches, and is not evaluated by |
- don't stop at the first error, report all issues - always run luacheck directly: so a luacheck install for another LUA version or using a shell script launcher works (the docker image wrapper already uses luajit) - don't disable colors in luacheck output - leave the terminal attributes to default at exit
Quote argument to `git ls-files`: ensure the glob is evaluated by git, not bash.
3d9312c to
a53d12e
Compare
Use
base/utils/shellcheck.shto ensure the same standard is used.Depend on koreader/koreader-base#1820.
Additionally: remove some CI dead code, and fix issues reported by newer shellcheck / shfmt versions.
This change is