-
Notifications
You must be signed in to change notification settings - Fork 122
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
No way to use filetype rules when piping with stdin #914
Comments
Just stumbled upon the same issue when adjusting my git-cliff config to integrate typos as a post-processing step (thanks @orhun for git-cliff). What I found out with the Meaning typos doesn't detect the file type from its content and probably needs an extra flag to define the file type when passing in the content through stdin. |
Thanks for looking into this @dnaka91! Indeed, file type isn't set when the content is given via stdin. I applied the following hacky patch to set it to md to see if it is going to make any difference: diff --git a/crates/typos-cli/src/policy.rs b/crates/typos-cli/src/policy.rs
index e8fb2e9..e7b7d32 100644
--- a/crates/typos-cli/src/policy.rs
+++ b/crates/typos-cli/src/policy.rs
@@ -330,7 +330,7 @@ impl DirConfig {
);
self.default
});
- (name, config)
+ (Some("md"), config)
}
} Unfortunately it didn't change anything. Maybe it should be set in a different way or we're not exactly on the right track. |
@orhun that only affected the returned name, it is still using the default config. btw if you enable logging, the above log line shows up saying that it chose the default policy because an unknown file type was selected. Could you describe the use case for what you are doing? For example, an extra flag for setting the file type means you need to do the file type detection. Would you instead want to tell us what the effective file name is so we still do our own detection? If that is the case, why can't we be given a file (I'm assuming its in memory?)? |
The use case is fixing the the typos for the generated changelog via [changelog]
postprocessors = [
# Check typos with https://github.com/crate-ci/typos
# If the spelling is incorrect, it will be automatically fixed.
{ pattern = '.*', replace_command = 'typos --write-changes -' },
] This is handled by piping the output to the given command's stdin, the implementation is here: https://github.com/orhun/git-cliff/blob/7ae77ff0e0a22b5f5e42737204cbf0ab8680f9d7/git-cliff-core/src/command.rs#L48 As you might guess the problem is that the
|
Is there any other info that I can provide to debug this further? 👀 |
The question isn't too clear to me. What is being debugged by whom? |
Sorry for not being clear. I'm trying to figure out what causes stdin to be handled differently in this case (for potentially fixing the issue) so I need some guidance. Let me know if I can provide any other information about my use-case for figuring out the next steps for making it possible. |
The difference is that there is no filename to do file type detection from. Our options for solutions are
Based on your workflow, it seems like either style of flag would work ( I would be curious if there is any prior art around this; if there are other tools that need to know the file type for stdin how they handle it. |
I'm not aware of any other tools. I think |
Someone just pointed out that bat has I am open to merging a PR for a |
I'm interested in making a PR but I'm not sure where to start. I added the command-line argument - as the next step should I override the file name if the argument is present? Can you provide some guidance about how to do that? |
This reverts commit 764e858. Until crate-ci/typos#914 is fixed
For changing the selected policy, For showing the name in the messages, we could
|
Saw that rustfmt is having a discussion on this to. It seems the discussion is in rust-lang/rustfmt#5266 |
Repro case:
I looked around in the codebase but couldn't figure out what causes stdin to be handled differently.
The text was updated successfully, but these errors were encountered: