Skip to content
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

changed files are reported incorrectly with yamlfmt #279

Closed
nokazn opened this issue Apr 5, 2024 · 2 comments
Closed

changed files are reported incorrectly with yamlfmt #279

nokazn opened this issue Apr 5, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@nokazn
Copy link
Contributor

nokazn commented Apr 5, 2024

Describe the bug

I set up treefmt with google/yamlfmt, and when running treefmt --fail-on-change, encountered unexpected behavior.

There seems to be no unformatted files, but treefmt reports some files changed and fails in most cases.
Sometimes I can get correct reports (0 files changed) and the command not fails in some reason.

To Reproduce

Prepare some unformatted YAML files and set up yamlfmt in treefmt.toml like https://github.com/nokazn/treefmt-yamlfmt-repro-279

# treefmt.toml
[formatter.yaml]
command = "yamlfmt"
includes = ["*.yaml", "*.yml"]
  1. Run nix develop --command treefmt --no-cache
  2. 1 files changed message is reported and the unformatted files are formatted
  3. Run nix develop --command treefmt --no-cache again
  4. 1 files changed message is shown again and nothing seems to happen to the YAML files

Expected behavior

In step 4, 0 files changed message is shown. (And never fails with --fail-on-change)

System information

$ treefmt --version
treefmt 0.6.1

Additional context

N/A

@nokazn nokazn added the bug Something isn't working label Apr 5, 2024
@zimbatm
Copy link
Member

zimbatm commented Apr 5, 2024

This is probably a bug with yamlfmt. treefmt assumes that the formatting tool won't write to the files if the formatting hasn't changed.

you can test that by running

stat myfile.yaml
yamlfmt myfile.yaml
stat myfile.yaml

If the mtime has changed, then it means that yamlfmt is not compatible with treefmt.

@nokazn
Copy link
Contributor Author

nokazn commented Apr 6, 2024

@zimbatm

Indeed mtime is updated even though the file has no changes.

$ stat example.yaml; yamlfmt example.yaml; stat example.yaml                                                                                                                                    9:37:40
  File: example.yaml
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 8,32    Inode: 62136       Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/  nokazn)   Gid: ( 1000/  nokazn)
Access: 2024-04-06 09:37:40.200167151 +0900
Modify: 2024-04-06 09:37:40.200167151 +0900
Change: 2024-04-06 09:37:40.200167151 +0900
 Birth: 2024-04-06 00:55:13.169203563 +0900
  File: example.yaml
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 8,32    Inode: 62136       Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/  nokazn)   Gid: ( 1000/  nokazn)
Access: 2024-04-06 09:37:44.890167171 +0900
Modify: 2024-04-06 09:37:44.890167171 +0900
Change: 2024-04-06 09:37:44.890167171 +0900
 Birth: 2024-04-06 00:55:13.169203563 +0900

I'll ask yamlfmt side about this and close this issue.
Thank yoy for your reply!

Edit: google/yamlfmt#165 will resolve this. Sorry for my quick judgement...

@nokazn nokazn closed this as completed Apr 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants