Support -stdin_filename for input from stdin
- Dominant language
- Go
- Stars
- 1.8k
- Forks
- 75
- PR merge metrics
- No merged PRs in 30d
Description
Hi!
Some formatters support an option to assume the filename when content is passed through stdin (clang-format's `--assume-filename`, ruff's `--stdin-filename`). Based on that filename they may act as if the user has passed an actual file.
I'm particularly interested in include/exclude config settings.
Currently, given this config
```yaml
match_type: doublestar
exclude: ["**/skip.yaml"]
```
I get the following output when provide the file path
```
$ ./yamlfmt -v -debug all -conf .yamlfmt skip.yaml
[DEBUG]: Using config path .yamlfmt from -conf flag
[DEBUG]: using doublestar path matching. include patterns: [skip.yaml]
[DEBUG]: trying pattern: skip.yaml
[DEBUG]: pattern skip.yaml matches: [skip.yaml]
[DEBUG]: calculating excludes for skip.yaml
[DEBUG]: pattern **/skip.yaml matched, excluding
[DEBUG]: paths to format: []
[DEBUG]: The following files were modified:
The following files were modified:
```
When passed to stdin it's being modified regardless which is expected
```
$ cat skip.yaml | ./yamlfmt -v -debug all -conf .yamlfmt -
[DEBUG]: Using config path .yamlfmt from -conf flag
[DEBUG]: using doublestar path matching. include patterns: [-]
[DEBUG]: trying pattern: -
[DEBUG]: pattern - matches: []
[DEBUG]: paths to format: []
a: 1
```
With `-stdin_filename skip.yaml` modification wouldn't have happened.
```
$ cat skip.yaml | ./yamlfmt -v -debug all -conf .yamlfmt -stdin_filename skip.yaml -
[DEBUG]: Using config path .yamlfmt from -conf flag
[DEBUG]: using doublestar path matching. include patterns: [skip.yaml]
[DEBUG]: trying pattern: skip.yaml
[DEBUG]: pattern skip.yaml matches: [skip.yaml]
[DEBUG]: calculating excludes for skip.yaml
[DEBUG]: pattern **/skip.yaml matched, excluding
[DEBUG]: paths to format: []
[DEBUG]: The following files were modified:
The following files were modified:
```
yamlfmt version
```
$ ./yamlfmt --version
yamlfmt 0.20.0 (42486ac)
```
Contributor guide
Assessment
This issue has not been assessed yet.