diff options
author | Ben Sima <ben@bsima.me> | 2024-04-01 13:30:45 -0400 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2024-04-01 13:30:45 -0400 |
commit | db373a8c727cad91d375b40a6c70b11ed73bdafb (patch) | |
tree | a7ed24e98242b6e38f44cb0c9884718d248cc613 /Biz/Lint.hs | |
parent | 5c8ef1bf4dff4fc7c6e66a57673a81477bcc850a (diff) |
Add nixfmt to Lint.hs
nixfmt is the soon-to-be official formatter for Nix code, as per the NixOS
GitHub group. So I figure I should just adopt it without worrying too much about
the specifics of the formatting. I just formatted everything in one go, hence
the huge diff, oh well.
Diffstat (limited to 'Biz/Lint.hs')
-rw-r--r-- | Biz/Lint.hs | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/Biz/Lint.hs b/Biz/Lint.hs index 13150cc..d27ca1d 100644 --- a/Biz/Lint.hs +++ b/Biz/Lint.hs @@ -15,6 +15,7 @@ -- : run deadnix -- : run shellcheck -- : run indent +-- : run nixfmt module Biz.Lint (main) where import Alpha @@ -78,8 +79,11 @@ all your lint are belong to us Usage: lint test - lint [--fix] [<file>...] - lint -h, --help + lint [options] [<file>...] + +Options: + --fix, -f Apply fixes automatically + --help, -h Print this info |] exit :: [Result] -> IO () @@ -88,7 +92,7 @@ exit results = Exit.exitWith <| (n > 0) ?: (Exit.ExitFailure n, Exit.ExitSuccess n = length <| filter bad results bad = \case (Warn _) -> False - Done {status = Bad _} -> True + Done _ (Bad _) -> True _ -> False printResult :: Result -> IO Result @@ -137,8 +141,6 @@ data Linter = Linter formatter :: Maybe (String -> String) } --- deriving (Show) - ormolu :: Linter ormolu = Linter @@ -219,6 +221,15 @@ decodeDeadnixOutput deadnixJson = formatDeadnixResult DeadnixResult {..} = file <> ":" <> show line <> ":" <> show column <> ": " <> message +nixfmt :: Linter +nixfmt = + Linter + { exe = "nixfmt", + checkArgs = ["--check"], + fixArgs = Nothing, + formatter = Nothing + } + shellcheck :: Linter shellcheck = Linter @@ -241,7 +252,7 @@ data Status = Good | Bad String deriving (Show) data Result - = Done {linter :: Linter, status :: Status} + = Done Linter Status | Warn Text | NoOp Namespace.Ext @@ -251,6 +262,7 @@ run mode nsmap = nsmap |> Map.assocs |> traverse (runOne mode) /> concat runOne :: Mode -> (Ext, [Namespace]) -> IO [Result] runOne mode (ext, ns's) = results +> traverse printResult where + results :: IO [Result] results = -- i would run these with mapConcurrently, but the output gets mangled. to -- do it right i need a queue for the results. someday. @@ -264,9 +276,17 @@ runOne mode (ext, ns's) = results +> traverse printResult lint mode ruff ns's ] Namespace.Sh -> [lint mode shellcheck ns's] - Namespace.Nix -> [lint mode deadnix ns's] + Namespace.Nix -> [lint mode deadnix ns's, lint mode nixfmt ns's] Namespace.C -> [lint mode indent ns's] - _ -> [pure <. Warn <| "no linter for " <> show ext] + _ -> + ns's + |> map Namespace.toPath + |> joinWith ", " + |> str + |> ("no linter for " <>) + |> Warn + |> (pure :: Result -> IO Result) + |> (pure :: IO Result -> [IO Result]) lint :: Mode -> Linter -> [Namespace] -> IO Result lint mode linter@Linter {..} ns's = |