Skip to content

Commit

Permalink
Merge pull request #760 from drestrepom/drestrepoatfluid
Browse files Browse the repository at this point in the history
feat(back): #753.1 add scala formatter
  • Loading branch information
jpverde authored Nov 2, 2021
2 parents a642017 + 11c014f commit c3451d0
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Diego Restrepo <[email protected]> Diego Restrepo Mesa <36453706+drest
Fluid Attacks <[email protected]> Fluid Attacks <[email protected]>
Github Dependabot <49699333+dependabot[bot]@users.noreply.github.com> dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Github Octocat <[email protected]> GitHub <[email protected]>
John Perez <[email protected]> John Perez <[email protected]>
Kevin Amado <[email protected]> Kevin Amado <[email protected]>
Luis Saavedra <[email protected]> Luis David Saavedra <[email protected]>
Luis Saavedra <[email protected]> Luis Saavedra <[email protected]>
Expand Down
1 change: 1 addition & 0 deletions src/evaluator/modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
(import ./format-markdown/default.nix args)
(import ./format-nix/default.nix args)
(import ./format-python/default.nix args)
(import ./format-scala/default.nix args)
(import ./format-javascript/default.nix args)
(import ./format-terraform/default.nix args)
(import ./hello-world/default.nix args)
Expand Down
53 changes: 53 additions & 0 deletions src/evaluator/modules/format-scala/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{ __nixpkgs__
, toBashArray
, makeDerivation
, makeScript
, isDarwin
, fetchUrl
, ...
}:
{ config
, lib
, ...
}:
let
chmodX = name: envSrc: makeDerivation {
env = { inherit envSrc; };
builder = "cp $envSrc $out && chmod +x $out";
inherit name;
};
scalafmt_version = "3.0.8";
binary_name = if isDarwin then "scalafmt-macos" else "scalafmt-linux-musl";
binary_file = fetchUrl {
url = "https://github.com/scalameta/scalafmt/releases/download/v${scalafmt_version}/${binary_name}";
sha256 = "0nxpny86qdbgsmxc9qzsv8f5qb21y25iyr8h2wg61kgiaw8988g0";
};
in
{
options = {
formatScala = {
enable = lib.mkOption {
default = false;
type = lib.types.bool;
};
targets = lib.mkOption {
default = [ "/" ];
type = lib.types.listOf lib.types.str;
};
};
};
config = {
outputs = {
"/formatScala" = lib.mkIf config.formatScala.enable
(makeScript {
replace = {
__argTargets__ = toBashArray
(builtins.map (rel: "." + rel) config.formatJavaScript.targets);
__argScalaFmtBinary__ = chmodX "scalafmt" binary_file;
};
name = "format-scala";
entrypoint = ./entrypoint.sh;
});
};
};
}
11 changes: 11 additions & 0 deletions src/evaluator/modules/format-scala/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# shellcheck shell=bash

function main {
source __argTargets__/template local targets

for target in "${targets[@]}"; do
'__argScalaFmtBinary__' "${target}"
done
}

main "${@}"

0 comments on commit c3451d0

Please sign in to comment.