uttrflow / uttrflow/uttrflow-swift
Prettier receives a TypeScript filename for CSS, HTML and JSON clips
- Dominant language
- Swift
- Stars
- 4
- Forks
- 17
- Avg merge
- 3h 32m
- Merged PRs (30d)
- 277
Description
## Problem
`KnownFormatter.prettier` advertises JavaScript, TypeScript, JSON, CSS and HTML, but its `arguments` always return `["--stdin-filepath", "clip.ts"]`. `SystemCodeFormatter.format(_:as:)` selects the executable using the language and then passes those same arguments regardless of language.
Prettier infers its parser from that filename, so valid CSS, HTML and JSON are parsed as TypeScript and can fail. The app's `runFormatter(on:)` logs the nil result and returns without presenting the formatting diff.
## Verified reproduction
Reviewed main `8d93f5b8574f3c7b8c30086d9c817bf7f5d4827d`. Tested Prettier **3.9.6** in an isolated temporary installation, using the exact production arguments and the same restricted PATH environment. These inputs all returned exit code **2**, a syntax error, and empty stdout with `--stdin-filepath clip.ts`:
- CSS: `.card{color:red}`
- HTML: `
Hello
`- JSON: `{"name":"sample","count":2}`
Changing only the filename to `clip.css`, `clip.html`, or `clip.json` respectively returned exit code **0** and correctly formatted output. A TypeScript control, `const n:number=2`, succeeded with `clip.ts`.
The CLI was invoked directly from the temporary installation; this was not a UI test or an installation into the application's fixed formatter directories. Production source confirms that the failed exit status is converted to nil. Prettier documents the filename option in its [CLI reference](https://prettier.io/docs/cli#--stdin-filepath).
## Code path
- `Sources/UttrflowClipboard/CodeFormatting.swift`: `KnownFormatter.languages` and `arguments`.
- `Sources/UttrflowClipboard/CodeFormatting+System.swift`: `format(_:as:)` and exit-status handling in `run`.
- `Sources/Uttrflow/AppDelegate.swift`: `runFormatter(on:)` calls the formatter with the clip's detected language.
- `Tests/UttrflowClipboardTests/FormatterGuardTests.swift`: `argumentsAreConstants` currently pins the single `clip.ts` argument instead of checking language-specific selection. Its existing tests pass, so they do not detect this failure.
## Acceptance criteria
- Select a suitable stdin filename or explicit parser for the detected language.
- Keep arguments drawn from a fixed allowlist; the clip remains stdin, never shell code or command arguments.
- Cover CSS, HTML, JSON, JavaScript and TypeScript dispatch, with valid formatting examples.
- Preserve availability checks and the formatting preview/guard behavior.
Priority: P2 — a supported formatting action silently fails on valid input. Separate from #579, which concerns the formatter timeout.
Contributor guide
Research direction
Start in Sources/UttrflowClipboard/CodeFormatting.swift, then trace format(_:as:) in CodeFormatting+System.swift and run the existing FormatterGuardTests. Use the detected language and the documented acceptance criteria to define the expected dispatch for CSS, HTML, JSON, JavaScript, and TypeScript. Done means valid examples format successfully, arguments remain allowlisted, and availability and preview behavior still pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100