-
-
Notifications
You must be signed in to change notification settings - Fork 542
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
feat: TFLint: Add --hook-config=--delegate-chdir
to use tflint -chdir
#512
Conversation
Hmm, that's an interesting solution. I definitely like that you find a way to fix that issue, but not sure about realization and our ability to merge it just as a minor release. Can you please run some performance tests for your realization and for tag 1.77.3? 0.44.0 (2022-12-26) was added not so long time ago and that's the main issue from my perspective - many folks could not updated yet, and I don't like to force them to update outside of breaking change release. So for now - how it when will be merged and released - as 1.x or part of 2.0 - it's a question. Maybe I need to find some time to resolve #303 and then I'll be able to move some other hooks to git repo root too, as was asked in #508. With or without breaking changes - will see. |
What is proposed in this PR contradicts with the designed essence of To properly resolve author's use case, parent |
Thanks for the feedback! This was a bit of a hack - just reversing the caller behavior. It seemed to work well enough for me locally - but see the problems you are describing. I adjusted to add a Does this flag seem reasonable? I still haven't invested in running the performance tests yet - but doesn't seem like anything is on the hot path. Does this seem ok as is? If so I can get myself setup to run them. |
Working on addressing these PR comments now - should have it re-pushed/rebased etc in a few mins. |
And merge master branch too, please |
And you don't need to do force-pushes at all - we will squash it when it will be merged |
sorry - not super familiar with the best way to work with forked repos - mostly used internal monorepos. Will re-open in a min - I screwed up the rebase. |
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.
@lexton Could you please test this PR once again and if wit works as expected and as intended for all of --delegate-chdir
, --delegate-chdir=true
, --delegate-chdir=false
, and when --delegate-chdir
isn't used at all, then I'll be happy to approve.
Thank you
Yep - just tested this locally. All these situations worked as expected.
Interestingly when I ran it locally one of the surprising things - it seem to resolve symlinks - since we expect this to only ever be locally relative paths - maybe we just want the relative paths rather than the fully qualified symlink.
Specifically: |
This time this is for |
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.
@lexton Thank you for the contribution 🥳
hooks/_common.sh
Outdated
# Lookup hook-config for modifiers that impact common behavior | ||
local DELEGATE_CHDIR=false | ||
IFS=";" read -r -a configs <<< "${HOOK_CONFIG[*]}" | ||
for c in "${configs[@]}"; do | ||
IFS="=" read -r -a config <<< "$c" | ||
key=${config[0]} | ||
value=${config[1]} | ||
|
||
case $key in | ||
--delegate-chdir) | ||
# this flag will skip pushing and popping directories | ||
# delegating the responsibility to the hooked plugin/binary | ||
if [[ ! $value || $value == true ]]; then | ||
DELEGATE_CHDIR=true | ||
fi | ||
;; | ||
esac | ||
done |
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.
I don't like that it makes common::per_dir_hook
more complex.
I thinking about moving it to a separate function but I don't see how it could be done, at least, without introducing a new global env.
The main problem here is pushd/popd
IF's,
if [[ $DELEGATE_CHDIR != true ]]; then
pushd "$dir_path" > /dev/null || continue
fi
which, in current realization (internal variable naming?) looks too "tflint-specific"
I suppose CHANGE_DIR_INSIDE_HOOK
than DELEGATE_CHDIR
will be more universal and easier to understand
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.
Or at least, I have those feelings. Not sure how they could be properly described and, which more importantly, done via code.
Let me think about it for a few days (and test how that functional could works with other hooks), maybe then I can describe it better
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.
I like the delegate
wording. If DELEGATE_CHDIR
is too short for clear understanding, then DELEGATE_CHDIR_TO_HOOK
should suffice imho.
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.
I thinking about moving it to a separate function but I don't see how it could be done, at least, without introducing a new global env.
Parse HOOK_CONFIG
array outside of the function and define this function with or w/o pushd/popd
things based on presence or absence of --delegate-chdir
hook arg and its value 😜
This may be expanded later for alike use cases. Though this would add complexity to the code anyways.
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.
I'd leave this as is (the way it's coded by @lexton in this PR) as a one-off/unique instance, at least until we have more of this kind requested.
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.
I think its relatively well encapsulated as is.
If you wanted to change/extend this in the future it wouldn't be too hard to update/change variable wording without major impact.
The biggest thing that would be hard to change would be the exact flag name. --delegate-chdir
if you wanted to make this more future proof that makes sense to get correct right now.
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.
The biggest thing that would be hard to change would be the exact flag name.
--delegate-chdir
if you wanted to make this more future proof that makes sense to get correct right now.
My opinion for the flag is the same as for the var naming. JFYI.
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.
Okay, I double-checked #508 and this functional does not help avoid the mentioned issue, so, I'll make one tiny improvement and we are ready to go
Changes in commit above provide ability to extend different manipulations with dir path. IE., we could add " |
--hook-config=--delegate-chdir
--hook-config=--delegate-chdir
--hook-config=--delegate-chdir
to use tflint -chdir
# [1.79.0](v1.78.0...v1.79.0) (2023-05-08) ### Features * TFLint: Add `--hook-config=--delegate-chdir` to use `tflint -chdir` ([#512](#512)) ([1e9debc](1e9debc))
This PR is included in version 1.79.0 🎉 |
Put an
x
into the box if that apply:Description of your changes
This change leverages the
tflint -chdir
flag to do the nested lookup and provide fully qualified paths to the output.It unwraps the
pushd
/popd
functionality and delegates the directory changing to the binary process via chdir.This would be a breaking behavior if a user tried to add a
-chdir
flag to theargs
- but I can't think of a valid reason that anyone would do this - or if that functionality would even work with the pre-commit-terraform hooks.The
-chdir
flag was added in tflint 0.44.0 - I don't know how to enforce specific versions of the binary or to trivially change the commit hook driver behavior based upon the version. This flag is forwards compatible, while thedir
arg to tflint is being deprecated.Totally happy to revisit the approach or just keep maintaining a fork for my use cases.
Fixes #511
How can we test changes
Locally examine the output when the tflint succeeds vs fails.