{"id":20858751,"url":"https://github.com/thesephist/inkfmt","last_synced_at":"2025-04-10T21:21:07.510Z","repository":{"id":97277300,"uuid":"260358208","full_name":"thesephist/inkfmt","owner":"thesephist","description":"Code formatter for the Ink programming language","archived":false,"fork":false,"pushed_at":"2020-12-20T17:14:09.000Z","size":139,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T18:49:39.608Z","etag":null,"topics":["code-formatter","ink","recursive-descent-parser"],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thesephist.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-01T01:50:53.000Z","updated_at":"2024-12-31T17:08:32.000Z","dependencies_parsed_at":"2023-06-26T03:01:19.757Z","dependency_job_id":null,"html_url":"https://github.com/thesephist/inkfmt","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thesephist%2Finkfmt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thesephist%2Finkfmt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thesephist%2Finkfmt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thesephist%2Finkfmt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thesephist","download_url":"https://codeload.github.com/thesephist/inkfmt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248298959,"owners_count":21080441,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-formatter","ink","recursive-descent-parser"],"created_at":"2024-11-18T04:47:14.010Z","updated_at":"2025-04-10T21:21:07.503Z","avatar_url":"https://github.com/thesephist.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# inkfmt 🖋\n\n**inkfmt** (pronounced \"ink format\") is a self-hosting code formatter for the [Ink programming language](https://dotink.co/). It's written in Ink itself, and designed to be run before commits to canonicalize syntax and whitespace, but still respects the code author's line breaks and comments. It's a work in progress, but gives the expected output for 95% of cases today.\n\nAll Ink code in this project is, of course, formatted with inkfmt. You can read an in-depth review of inkfmt's design and implementation in the [inkfmt post on the Ink blog](https://dotink.co/posts/inkfmt/).\n\n![Demo / screenshot](inkfmt.jpg)\n\ninkfmt makes these transformations:\n\n- Remove unnecessary commas\n\t- At ends of lines (Ink has automatic comma insertion at line endings)\n\t```\n\ta := 1,\t\t\t\ta := 1\n\tb := 2,\t\t\t-\u003e\tb := 2\n\tc := a + b,\t\t\tc := a + b\n\t```\n\t- At end of expression and argument lists\n\t```\n\tresult := f(1, 2, [3, 4, ], {\n\t\tkey: val,\n\t}, )\n\t\t-\u003e\n\tresult := f(1, 2, [3, 4], {\n\t\tkey: val\n\t})\n\t```\n- Canonicalize whitespaces\n\t- Sensibly auto-indent lines\n\t```\n\tfunc := n =\u003e even?(n) :: {\n     true -\u003e 'is' +\n      ' even'\n\t\t\tfalse -\u003e 'is odd'\n\t\t}\n\t\t-\u003e\n\tfunc := n =\u003e even?(n) :: {\n\t\ttrue -\u003e 'is' +\n\t\t\t' even'\n\t\tfalse -\u003e 'is odd\n\t}\n\t```\n    - Ensure single spaces between specific tokens, when appropriate\n\t```\n\tfunc := (x,y)=\u003e pow(x,2)+3.1415\n\t\t-\u003e\n\tfunc := (x, y) =\u003e pow(x, 2) + 3.1415\n\t```\n\ninkfmt intentionally avoids certain kinds of code transformations that might be disruptive to the intent of the code author.\n\n- inkfmt doesn't **change line breaks** in code. Many other formatters like [Prettier](https://prettier.io) and [rustfmt](https://github.com/rust-lang/rustfmt) break lines according to some length heuristic, while others like [gofmt](https://golang.org/cmd/gofmt/) do not. I personally prefer formatters not to mess with my line breaks. Line breaks often convey important information, grouping arguments or list entries together in semantically important ways. If a line gets too long, I can manually break it in a sensible place. It might also be an indicator that there might be a better way to describe what I'm doing in code.\n- inkfmt doesn't **add or remove idempotent parentheses**. Some more strict and deterministic formatters like [Prettier](https://prettier.io) will add and remove parentheses around expressions to disambiguate expressions or add consistency, but like line breaks, I think programmers use parentheses to group things in meaningful ways or make the code more readable, and formatters should clean them up, not remove them.\n\n## Usage\n\nAt this point, the `fmt` program reads Ink code in from `stdin` and writes formatted code and/or errors out to `stdout`. Eventually, the goal will be for the executable to read a tree of files and format all Ink programs within.\n\nWith Ink installed, we can simply run:\n\n```sh\n./fmt.ink \u003c input.ink \u003e output.ink\n```\n\n## References and further reading\n\n- Phil Wadler's [Prettier Printer](https://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf)\n- Prettier's JavaScript implementation of the above, [GitHub](https://github.com/prettier/prettier-printer)\n- Go's implementation of [gofmt](https://golang.org/src/cmd/gofmt/doc.go)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthesephist%2Finkfmt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthesephist%2Finkfmt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthesephist%2Finkfmt/lists"}