hujsonfmt: -w rewrites already formatted files and -l lists them

Open Beginner friendly
#59 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
tooling

Research direction

Read cmd/hujsonfmt/hujsonfmt.go, especially processFile and processSrc. Compare the original src with the formatted output for both -l and -w, then check that an already formatted file is neither listed nor rewritten while an unformatted file is updated. The issue gives a reproducible command sequence to verify the behavior.

Written by the indexing model from the issue text.

Description

hujsonfmt -w rewrites a file that is already formatted, and hujsonfmt -l lists it as unformatted.

Steps, with hujsonfmt 0-unstable-2025-06-05 from nixpkgs on Linux; cmd/hujsonfmt/hujsonfmt.go at b80ff77 has the same code:

printf '{\n\t"a": 1,\n}\n' > policy.hujson
hujsonfmt -w policy.hujson          # formats it
hujsonfmt policy.hujson | diff - policy.hujson   # no output: already formatted
hujsonfmt -w policy.hujson          # mtime changes again
hujsonfmt -l policy.hujson          # prints policy.hujson

processFile passes input to processSrc, which can modify it in place, so the -l case compares the modified input with the output instead of src. The -w case calls writeFile without comparing at all, so every run writes a backup copy and rewrites the file. Formatters such as treefmt then report the file as changed on every run.

Would a fix that compares src with the output in both cases, and skips the write when they are equal, be welcome?

Dominant language
Go
Stars
892
Forks
40
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from tailscale/hujson

All issues in tailscale/hujson

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.