Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
chore: add treefmt formatting (nix fmt + pre-commit + CI check)#5
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| /.* | ||
| !/.gitignore | ||
| !/.github/ | ||
| !/.tidyrc.json | ||
| !/.lua-format | ||
| /output/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # LuaFormatter config for the hand-written FFI under src/. | ||
| # 2-space indent. Keep simple functions on one line; column_limit sits a few | ||
| # columns under luacheck's 130 limit because lua-format under-counts the leading | ||
| # indent and trailing comma, so this keeps every emitted line within 130. | ||
| indent_width: 2 | ||
| use_tab: false | ||
| column_limit: 126 | ||
| continuation_indent_width: 2 | ||
| keep_simple_function_one_line: true | ||
| keep_simple_control_block_one_line: true | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "importSort": "source", | ||
| "importWrap": "source", | ||
| "indent": 2, | ||
| "operatorsFile": null, | ||
| "ribbon": 1, | ||
| "typeArrowPlacement": "first", | ||
| "unicode": "source", | ||
| "width": 80 | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -9,16 +9,33 @@ | ||
| inputs.nixpkgs.follows = "nixpkgs"; | ||
| }; | ||
| pslua.url = "github:purescript-lua/purescript-lua"; | ||
| treefmt-nix = { | ||
| url = "github:numtide/treefmt-nix"; | ||
| inputs.nixpkgs.follows = "nixpkgs"; | ||
| }; | ||
| }; | ||
| outputs = { self, nixpkgs, flake-utils, purescript-overlay, pslua }: | ||
| flake-utils.lib.eachDefaultSystem (system: | ||
| outputs = | ||
| { | ||
| self, | ||
| nixpkgs, | ||
| flake-utils, | ||
| purescript-overlay, | ||
| pslua, | ||
| treefmt-nix, | ||
| }: | ||
| flake-utils.lib.eachDefaultSystem ( | ||
| system: | ||
| let | ||
| pkgs = import nixpkgs { | ||
| inherit system; | ||
| overlays = [ purescript-overlay.overlays.default ]; | ||
| }; | ||
| in { | ||
| treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix; | ||
| in | ||
| { | ||
| formatter = treefmtEval.config.build.wrapper; | ||
| checks.formatting = treefmtEval.config.build.check self; | ||
| devShell = pkgs.mkShell { | ||
| buildInputs = with pkgs; [ | ||
| dhall | ||
| @@ -31,8 +48,26 @@ | ||
| spago-bin.spago-0_21_0 | ||
| treefmt | ||
| ]; | ||
| # Install a content-based pre-commit hook. It compares the working | ||
| # tree diff before and after `nix fmt`, so it only objects to changes | ||
| # the formatter itself introduces (not the developer's existing | ||
| # unstaged work) and is not fooled by formatters that only bump mtime. | ||
| # Rewritten each shell entry to stay in sync with this flake. | ||
| shellHook = '' | ||
| hook=.git/hooks/pre-commit | ||
| if [ -d .git ]; then | ||
| printf '%s\n' \ | ||
| '#!/usr/bin/env bash' \ | ||
| 'before=$(git diff)' \ | ||
| 'nix fmt >/dev/null 2>&1 || exit 0' \ | ||
| '[ "$before" = "$(git diff)" ] || { echo "nix fmt changed files; re-stage them, then commit." >&2; exit 1; }' \ | ||
| > "$hook" | ||
| chmod +x "$hook" | ||
| fi | ||
| ''; | ||
Unisay marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| }; | ||
| }); | ||
| } | ||
| ); | ||
| # --- Flake Local Nix Configuration ---------------------------- | ||
| nixConfig = { | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| module Control.Alt | ||
| ( class Alt, alt, (<|>) | ||
| ( class Alt | ||
| , alt | ||
| , (<|>) | ||
| , module Data.Functor | ||
| ) where | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -22,4 +22,4 @@ instance lazyUnit :: Lazy Unit where | ||
| fix :: forall l. Lazy l => (l -> l) -> l | ||
| fix f = go | ||
| where | ||
| go = defer \_ -> f go | ||
| go = defer \_ -> f go | ||
Unisay marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| module Control.Plus | ||
| ( class Plus, empty | ||
| ( class Plus | ||
| , empty | ||
| , module Control.Alt | ||
| , module Data.Functor | ||
| ) where | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| { pkgs, ... }: | ||
| { | ||
| projectRootFile = "flake.nix"; | ||
| # Nix — RFC 166 formatter. | ||
| programs.nixfmt.enable = true; | ||
| # Dhall — spago.dhall / packages.dhall layout. | ||
| programs.dhall.enable = true; | ||
| # PureScript — purs-tidy is not a first-class treefmt program, so wire it via | ||
| # the generic mechanism. It picks up `.tidyrc.json` from the project root. | ||
| settings.formatter.purs-tidy = { | ||
| command = "${pkgs.purs-tidy}/bin/purs-tidy"; | ||
| options = [ "format-in-place" ]; | ||
| includes = [ "*.purs" ]; | ||
| }; | ||
| # Lua FFI — LuaFormatter keeps the parentheses pslua's foreign-file parser | ||
| # requires (unlike StyLua, which strips them). Config in `.lua-format`. | ||
| settings.formatter.lua-format = { | ||
Unisay marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| command = "${pkgs.luaformatter}/bin/lua-format"; | ||
| options = [ | ||
| "-i" | ||
| "-c" | ||
| ".lua-format" | ||
| ]; | ||
| includes = [ "*.lua" ]; | ||
| }; | ||
| # Never format generated output or vendored trees. | ||
| settings.global.excludes = [ | ||
| "dist/*" | ||
| "output/*" | ||
| ".spago/*" | ||
| "node_modules/*" | ||
| "*.lock" | ||
| "flake.lock" | ||
| "spago.lock" | ||
| ".tidyrc.json" | ||
| ".lua-format" | ||
| ]; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.