-
-
Notifications
You must be signed in to change notification settings - Fork 540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Pre-commit-terraform terraform_validate hook #401
fix: Pre-commit-terraform terraform_validate hook #401
Conversation
@nshenry03 |
Thanks @yermulnik, here is the output from $ type cd
cd is a shell builtin It seems to for me $ cd Repositories/terraform/modules/aws/kms/
/Users/hnicholas/Repositories/terraform/modules/aws/kms
$ System Info $ system_profiler SPSoftwareDataType
Software:
System Software Overview:
System Version: macOS 11.6.7 (20G630)
Kernel Version: Darwin 20.6.0
Boot Volume: Macintosh HD
Boot Mode: Normal
Computer Name: hnicholas-a01
User Name: Nicholas Henry (hnicholas)
Secure Virtual Memory: Enabled
System Integrity Protection: Enabled
Time since boot: 10 days 21:01
$ echo $SHELL
/usr/local/bin/bash
$ ll /usr/local/bin/bash
lrwxr-xr-x 1 hnicholas admin 30 Jan 14 09:16 /usr/local/bin/bash@ -> ../Cellar/bash/5.1.16/bin/bash
$ brew info bash
bash: stable 5.1.16 (bottled), HEAD
Bourne-Again SHell, a UNIX command interpreter
https://www.gnu.org/software/bash/
/usr/local/Cellar/bash/5.1.16 (157 files, 10.9MB) *
Poured from bottle on 2022-01-14 at 09:16:49
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/bash.rb
License: GPL-3.0-or-later
==> Options
--HEAD
Install HEAD version
==> Analytics
install: 21,000 (30 days), 64,439 (90 days), 311,670 (365 days)
install-on-request: 16,991 (30 days), 52,064 (90 days), 256,604 (365 days)
build-error: 33 (30 days) |
On the other hand shell scripts shouldn't be taking into account aliases and functions 🤔 What's your OS and Bash versions? |
Aha, that's because of
So we only need to suppress stdout. I'll leave a commit suggestion in a sec. |
Only supress stdout and not stderror Co-authored-by: George L. Yermulnik <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Add a space after `>`. Co-authored-by: George L. Yermulnik <[email protected]>
Once @MaxymVlasov and/or @antonbabenko make it to this PR to do the review, it will be merged. @nshenry03 Thanks for contribution. |
## [1.72.2](v1.72.1...v1.72.2) (2022-06-21) ### Bug Fixes * Pre-commit-terraform terraform_validate hook ([#401](#401)) ([d9f482c](d9f482c))
This PR is included in version 1.72.2 🎉 |
@@ -111,7 +111,7 @@ function terraform_validate_ { | |||
|
|||
if [[ -n "$(find "$dir_path" -maxdepth 1 -name '*.tf' -print -quit)" ]]; then | |||
|
|||
pushd "$(cd "$dir_path" && pwd -P)" > /dev/null | |||
pushd "$(cd "$dir_path" > /dev/null && pwd -P)" > /dev/null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, you found code written in Paleolithic.
Let's try reuse logic that used in common functions here:
https://github.com/antonbabenko/pre-commit-terraform/blob/master/hooks/_common.sh#L178
Absolutely have no idea why it was written in so complex way
From @MaxymVlasov in antonbabenko#401 (comment): > Heh, you found code written in Paleolithic. > > Let's try reuse logic that used in common functions here: > > https://github.com/antonbabenko/pre-commit-terraform/blob/master/hooks/_common.sh#L178 > > Absolutely have no idea why it was written in so complex way
Put an
x
into the box if that apply:Description of your changes
This PR simple redirects
stdout
andstderror
to/dev/null
for thecd
command.Fixes
hooks/terraform_validate.sh
The
terraform_validate
hook was failing for me because the script was gettingNo such file or directory
error:Digging deeper, it seems that
cd
was outputting the name of the directory, but we don't want that, we only want output frompwd -P
.How can we test changes
I changed this locally and it fixed the issue.