|
40 | 40 | importpath: golang.org/x/tools/cmd/goimports |
41 | 41 |
|
42 | 42 | steps: |
43 | | - |
44 | 43 | - name: Set up Go 1.15.x |
45 | 44 | uses: actions/setup-go@v2 |
46 | 45 | with: |
@@ -198,6 +197,40 @@ jobs: |
198 | 197 |
|
199 | 198 | echo '::endgroup::' |
200 | 199 |
|
| 200 | + - name: Redundant Format |
| 201 | + shell: bash |
| 202 | + if: ${{ always() }} |
| 203 | + env: |
| 204 | + REVIEWDOG_GITHUB_API_TOKEN: ${{ github.token }} |
| 205 | + run: | |
| 206 | + set -e |
| 207 | + cd "${GITHUB_WORKSPACE}" || exit 1 |
| 208 | +
|
| 209 | + echo '::group:: Flagging possibly unnecessary format calls for trailing argument with reviewdog 🐶 ...' |
| 210 | + # Don't fail because of misspell |
| 211 | + set +o pipefail |
| 212 | + # For all look for formatting calls and extract the ones that |
| 213 | + # have only a single formatting argument and that argument is in the last position. |
| 214 | + # But exclude the `fmt.Errorf` calls since there's no `fmt.Error` and `errors.New` is not |
| 215 | + # as versatile. |
| 216 | + # Also ignore `%T` — to print the type and `%q` to quote the final string. |
| 217 | + fn=$(find . -path './vendor' -prune -o -path './third_party' -prune -o -name '*.pb.go' -prune -o -type f -name '*.go' -print) |
| 218 | + grep -nE '[^.]+\.(Fatalf|Errorf|Warnf|Infof|Debugf)[^\%]+%[^Tq]",[^,]+' $fn | grep -v "fmt.Errorf" | |
| 219 | + while read -r ent ; do |
| 220 | + file=$(echo $ent | cut -d':' -f 1); |
| 221 | + line=$(echo $ent | cut -d':' -f 2); |
| 222 | + ch=$(echo $ent | cut -d':' -f3-); |
| 223 | + err=$(echo $ch | sed -E 's/([^.]+\.)(Fatal|Error|Warn|Info|Debug)f([^\%]+)(%[^wq]",)([^,]+)/\1\2\3",\5/'); |
| 224 | + echo "$file:$line: Please consider avoiding tail format like this:%0A$err" |
| 225 | + done | |
| 226 | + reviewdog -efm="%f:%l: %m" \ |
| 227 | + -name="Redundant Format" \ |
| 228 | + -reporter="github-pr-check" \ |
| 229 | + -filter-mode="added" \ |
| 230 | + -fail-on-error="true" \ |
| 231 | + -level="error" |
| 232 | + echo '::endgroup::' |
| 233 | +
|
201 | 234 | # This is mostly copied from https://github.com/get-woke/woke-action-reviewdog/blob/main/entrypoint.sh |
202 | 235 | # since their action is not yet released under a stable version. |
203 | 236 | - name: Language |
|
0 commit comments