From 562ea571b53599ff766a86f4214d579671a4b872 Mon Sep 17 00:00:00 2001 From: Michael Ekstrand Date: Mon, 8 Jul 2024 14:32:25 -0400 Subject: [PATCH] Add shell formatting to pre-commit (#60) Add shfmt to pre-commit to format our shell scripts, and run it on the existing scripts. This is an additional Go-based dependency. --- .pre-commit-config.yaml | 13 ++++++++++++- deploy.sh | 17 +++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0dbd3e2f..9c9eba66 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,15 +24,26 @@ repos: # Run the linter. - id: ruff args: [--fix] + name: auto-fix Python lint errors # Run the formatter. - id: ruff-format + name: format Python source - repo: local hooks: - id: format-toml-files - name: toml-format + name: format toml files entry: taplo args: ["format"] files: \.toml$ language: node additional_dependencies: - "@taplo/cli" + # shfmt support, adapted from https://github.com/mvdan/sh/issues/818 + - id: format-shell-scripts + name: format shell scripts + language: golang + require_serial: true + additional_dependencies: [mvdan.cc/sh/v3/cmd/shfmt@v3.8.0] + entry: shfmt + args: ["-l", "-w", "-i", "4"] + types: [shell] diff --git a/deploy.sh b/deploy.sh index 46a849ea..c23b751a 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,19 +1,20 @@ #!/bin/bash -while getopts ":e:r:" flag -do +while getopts ":e:r:" flag; do case "${flag}" in - e) env=${OPTARG};; - r) region=${OPTARG};; - *) echo "Invalid option. Only -e and -r are allowed" >&2 - exit 1 ;; + e) env=${OPTARG} ;; + r) region=${OPTARG} ;; + *) + echo "Invalid option. Only -e and -r are allowed" >&2 + exit 1 + ;; esac done env=${env:-prod} region=${region:-us-east-1} -echo "ENV: $env"; -echo "Region: $region"; +echo "ENV: $env" +echo "Region: $region" # Download model artifacts dvc pull