Skip to content

treefmt --stdin doesn't work if file name has no extension #620

@manuelteillet

Description

@manuelteillet

Describe the bug

When using treefmt in stdin mode on a justfile, I get a warning "no formatter for path".

To Reproduce

Here is my example:

echo "set quiet := true

# print this message
help:
    just --list --list-submodules --unsorted

# interactive recipes launcher
choose:
    just --choose --unsorted



mod init 'just/init.just'
mod bootstrap 'just/bootstrap.just'
mod apply 'just/apply.just'
"|treefmt --stdin justfile

and my result:

WARN no formatter for path: 1621644870
set quiet := true

# print this message
help:
    just --list --list-submodules --unsorted

# interactive recipes launcher
choose:
    just --choose --unsorted



mod init 'just/init.just'
mod bootstrap 'just/bootstrap.just'
mod apply 'just/apply.just'

traversed 1 files
emitted 0 files for processing
formatted 0 files (0 changed) in 18ms

Expected behavior

The same example just adding a . in front of justfile:

echo "set quiet := true

# print this message
help:
    just --list --list-submodules --unsorted

# interactive recipes launcher
choose:
    just --choose --unsorted



mod init 'just/init.just'
mod bootstrap 'just/bootstrap.just'
mod apply 'just/apply.just'
"|treefmt --stdin .justfile

works flawlessly:

set quiet := true

# print this message
help:
    just --list --list-submodules --unsorted

# interactive recipes launcher
choose:
    just --choose --unsorted

mod init 'just/init.just'
mod bootstrap 'just/bootstrap.just'
mod apply 'just/apply.just'
traversed 1 files
emitted 1 files for processing
formatted 1 files (1 changed) in 21ms

Possible explanation

I suspect that the copy of stdin to a file with the same extension as the original file doesn't work well if original file has no extension:

// read stdin into a temporary file with the same file extension

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions