Skip to content

Commit 0f25122

Browse files
MaxymVlasovantonbabenko
authored andcommitted
chore: Implement DRY for HOOK_ID (#405)
1 parent 2623b7b commit 0f25122

13 files changed

Lines changed: 6 additions & 30 deletions

hooks/_common.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#!/usr/bin/env bash
22
set -eo pipefail
33

4+
# Hook ID, based on hook filename.
5+
# Hook filename MUST BE same with `- id` in .pre-commit-hooks.yaml file
6+
# shellcheck disable=SC2034 # Unused var.
7+
HOOK_ID=${0##*/}
8+
readonly HOOK_ID=${HOOK_ID%%.*}
9+
410
#######################################################################
511
# Init arguments parser
612
# Arguments:

hooks/infracost_breakdown.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
set -eo pipefail
33

44
# globals variables
5-
# hook ID, see `- id` for details in .pre-commit-hooks.yaml file
6-
# shellcheck disable=SC2034 # Unused var.
7-
readonly HOOK_ID='infracost_breakdown'
85
# shellcheck disable=SC2155 # No way to assign to readonly variable in separate lines
96
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
107
# shellcheck source=_common.sh

hooks/terraform_checkov.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
set -eo pipefail
33

44
# globals variables
5-
# hook ID, see `- id` for details in .pre-commit-hooks.yaml file
6-
# shellcheck disable=SC2034 # Unused var.
7-
readonly HOOK_ID='terraform_checkov'
85
# shellcheck disable=SC2155 # No way to assign to readonly variable in separate lines
96
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
107
# shellcheck source=_common.sh

hooks/terraform_fmt.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
set -eo pipefail
33

44
# globals variables
5-
# hook ID, see `- id` for details in .pre-commit-hooks.yaml file
6-
# shellcheck disable=SC2034 # Unused var.
7-
readonly HOOK_ID='terraform_fmt'
85
# shellcheck disable=SC2155 # No way to assign to readonly variable in separate lines
96
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
107
# shellcheck source=_common.sh

hooks/terraform_providers_lock.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
set -eo pipefail
44

55
# globals variables
6-
# hook ID, see `- id` for details in .pre-commit-hooks.yaml file
7-
readonly HOOK_ID='terraform_providers_lock'
86
# shellcheck disable=SC2155 # No way to assign to readonly variable in separate lines
97
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
108
# shellcheck source=_common.sh

hooks/terraform_tflint.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
set -eo pipefail
44

55
# globals variables
6-
# hook ID, see `- id` for details in .pre-commit-hooks.yaml file
7-
readonly HOOK_ID='terraform_tflint'
86
# shellcheck disable=SC2155 # No way to assign to readonly variable in separate lines
97
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
108
# shellcheck source=_common.sh

hooks/terraform_tfsec.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
set -eo pipefail
33

44
# globals variables
5-
# hook ID, see `- id` for details in .pre-commit-hooks.yaml file
6-
readonly HOOK_ID='terraform_tfsec'
75
# shellcheck disable=SC2155 # No way to assign to readonly variable in separate lines
86
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
97
# shellcheck source=_common.sh

hooks/terraform_validate.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
set -eo pipefail
33

44
# globals variables
5-
# hook ID, see `- id` for details in .pre-commit-hooks.yaml file
6-
# shellcheck disable=SC2034 # Unused var.
7-
readonly HOOK_ID='terraform_validate'
85
# shellcheck disable=SC2155 # No way to assign to readonly variable in separate lines
96
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
107
# shellcheck source=_common.sh

hooks/terraform_wrapper_module_for_each.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
set -eo pipefail
33

44
# globals variables
5-
# hook ID, see `- id` for details in .pre-commit-hooks.yaml file
6-
# shellcheck disable=SC2034 # Unused var.
7-
HOOK_ID=${0##*/}
8-
readonly HOOK_ID=${HOOK_ID%%.*}
95
# shellcheck disable=SC2155 # No way to assign to readonly variable in separate lines
106
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
117
# shellcheck source=_common.sh

hooks/terragrunt_fmt.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
set -eo pipefail
33

44
# globals variables
5-
# hook ID, see `- id` for details in .pre-commit-hooks.yaml file
6-
readonly HOOK_ID='terragrunt_fmt'
75
# shellcheck disable=SC2155 # No way to assign to readonly variable in separate lines
86
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
97
# shellcheck source=_common.sh

0 commit comments

Comments
 (0)