-
Notifications
You must be signed in to change notification settings - Fork 53
fix: normalize stdin path to be relative to tree root #682
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
Open
adrian-gierakowski
wants to merge
1
commit into
numtide:main
Choose a base branch
from
adrian-gierakowski:fix/includes-excludes-with-stdin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+53
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This smells weird to me. Could we just make do without trying to call resolvePath at all?
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 use resolvePath to match existing behaviour when used without --stdin. IMHO the behaviour should be the same between these 2 cases when main.go is a symlink to another file which matches a different formatter than the path of the symlink iself:
treefmt ./main.go cat main.go | treefmt --stdin ./main.gothe first command (before and after this PR) follows the symlink and dispatches to formatter based on the path the symlink is pointing at
if we don't use
resolvePathhere, the second command would format based on the location of the symlink, not the file it is pointing atThe fallback is in case the path provided to --stdin is simply a hint, and does not point at an existing file.
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.
here's an implementation without the symlink resolution in case you want to try it for yourself:
adrian-gierakowski@9f74345
NOTE: I based this PR on last commit for which CI was green (CI failure here must be due to main being broken and github merging main into PR branch before running CI)
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 non symlink resolving version better. Unless there's something I'm missing, I'd like to merge that version if you can create the PR and we can close this one.
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.
Can I also remove the symlink resolution when formatting a file given it's path? Otherwise we'll have inconsistent behaviour.
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.
Not does not
Please see my explanation in above
I think you make some good points. Maybe we should reach out to whomever imolemented the symlink resolution logic in the first place to understand the motivation a bit better? What I care is content behaviour file path and stdin formatting.
Uh oh!
There was an error while loading. Please reload this page.
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.
Sure, or if it were me, I'd start by just trying to implement what I described, and see if any tests fail and take it from there.
I prefer the "format based on the location of the symlink" behavior, which I believe is consistent with my "let's ignore symlinks" proposal.
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.
Also, I do think we can land the non-symlink resolving version of this PR before revisiting treefmt's overall handling of symlinks.
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 be happy to remove symlink resolving altogether. But hesitant to put any time into this unless an authoritative decision is made that it would be merged. In the meantime I'm using my fork since I really need stdin to work (and without surprises)
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.
Let's get rid of it. If the tests pass, then I see no reason to keep any of it around. @brianmcgee?