Open KEINOS opened 3 years ago
./.github/run-lint.sh
shfmt
.editorconfig
以下の 40 行目のインデントにスペースが 1 つ余計に入っています。
https://github.com/Qithub-BOT/QiiCipher/blob/6d0cf1e7bf149e47968bf5a1901c4e87d9f7ad22/.github/run-test.sh#L31-L41
しかし、テスト結果はパスしています。
=============================================================================== Requirement Check for Linting and Static Analysis =============================================================================== - ShellCheck version: 0.7.0 - shfmt version: v3.3.0 ------------------------------------------------------------------------------- Running linters ------------------------------------------------------------------------------- - Shellformat ... OK - ShellCheck ... OK
これは少し古いローカルの shfmt v3.2.1-0 でも同じ現象でした。
shfmt v3.2.1-0
shfmt -i=4 ./.github/run-tests.sh とインデントをオプションで指定すると検知することから、.editorconfig が反映されないパターンがあるようです。
shfmt -i=4 ./.github/run-tests.sh
$ shfmt --version 3.2.1-0 $ shfmt -d ./.github/run-test.sh $ echo $? 0 $ shfmt -i=4 -d ./.github/run-test.sh --- ./.github/run-test.sh.orig +++ ./.github/run-test.sh @@ -37,7 +37,7 @@ return $FAILURE } - echo "$(echo "$result" | head -n 2 | tail -n 1)" 'OK' + echo "$(echo "$result" | head -n 2 | tail -n 1)" 'OK' } # -----------------------------------------------------------------------------
問題は、さらに古い shfmt のバージョンだと検知することです。shellspec の Alpine Docker イメージ に shfmt を入れると shfmt v3.1.1-0 が入るのですが、その場合は検知します。
shellspec
#14 0.278 =============================================================================== #14 0.278 Requirement Check for Linting and Static Analysis #14 0.278 =============================================================================== #14 0.283 - ShellCheck version: 0.7.1 #14 0.289 - shfmt version: 3.1.1-0 #14 0.290 ------------------------------------------------------------------------------- #14 0.290 Running linters #14 0.290 ------------------------------------------------------------------------------- #14 0.290 - Shellformat ... --- ./.github/run-test.sh.orig #14 0.305 +++ ./.github/run-test.sh #14 0.305 @@ -1,71 +1,71 @@ #14 0.305 #!/bin/sh #14 0.305 # ============================================================================= #14 0.305 # ShellSpec による動的/単体テストの実行スクリプト #14 0.305 # ============================================================================= #14 0.305 ...(略)... #14 0.306 # ----------------------------------------------------------------------------- #14 0.306 # Functions #14 0.306 # ----------------------------------------------------------------------------- #14 0.306 #14 0.306 runShellSpec() { #14 0.307 printf "%s" '- ShellSpec ' #14 0.307 #14 0.307 result=$(shellspec 2>&1) || { #14 0.307 printf >&2 ": NG\n%s" "$result" #14 0.307 #14 0.307 return $FAILURE #14 0.307 } #14 0.307 #14 0.307 - echo "$(echo "$result" | head -n 2 | tail -n 1)" 'OK' #14 0.307 + echo "$(echo "$result" | head -n 2 | tail -n 1)" 'OK' #14 0.307 } ...(略)...
ただ、このバージョン(shfmt v3.1.1-0)は shellspec のテスト構文を正しく解釈できないため、とんでもない数のエラーを吐き出します。そのため、shfmt v3.2 以降での対策が必要です。
FROM shellspec/shellspec:latest AS testbuild # Install miminum requirements for QiiCipher RUN apk add --no-cache \ openssl \ openssh \ ca-certificates && update-ca-certificates # Install requirements for testing RUN apk add --no-cache \ git \ shellcheck \ shfmt # Copy the hole repo COPY . /app WORKDIR /app # Run tests RUN \ /app/.github/run-lint.sh \ && /app/.github/run-test.sh
どうも、shfmt 本家の issue #393 やソースを見ると、shfmt の呼び出し時にオプションがある場合は .editorconfig は無視されるっぽい。
以下で -d オプションを付けてるのが原因っぽい(未検証)
-d
https://github.com/Qithub-BOT/QiiCipher/blob/6d0cf1e7bf149e47968bf5a1901c4e87d9f7ad22/.github/run-lint.sh#L57-L81
TL; DR (今北産業)
./.github/run-lint.sh
でshfmt
の lint チェック時に検知漏れがある。shfmt
のバージョンにも関係していそうshfmt
v3.3.0 -> 検知しないshfmt
v3.2.1-0 -> 検知しないshfmt
v3.1.1-0 -> 検知するshfmt
のバージョンによって.editorconfig
が反映されないケースがあるっぽいTS; DR
以下の 40 行目のインデントにスペースが 1 つ余計に入っています。
https://github.com/Qithub-BOT/QiiCipher/blob/6d0cf1e7bf149e47968bf5a1901c4e87d9f7ad22/.github/run-test.sh#L31-L41
しかし、テスト結果はパスしています。
これは少し古いローカルの
shfmt v3.2.1-0
でも同じ現象でした。shfmt -i=4 ./.github/run-tests.sh
とインデントをオプションで指定すると検知することから、.editorconfig
が反映されないパターンがあるようです。問題は、さらに古い
shfmt
のバージョンだと検知することです。shellspec
の Alpine Docker イメージ にshfmt
を入れるとshfmt
v3.1.1-0 が入るのですが、その場合は検知します。ただ、このバージョン(
shfmt
v3.1.1-0)はshellspec
のテスト構文を正しく解釈できないため、とんでもない数のエラーを吐き出します。そのため、shfmt
v3.2 以降での対策が必要です。