Skip to content

Commit 57dabe2

Browse files
authored
Merge pull request #328 from xsteadfastx/sql-formatter-fix
sql-formatter: fix multi file input
2 parents 18bed67 + 0a499a6 commit 57dabe2

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

examples/formatter-sql-formatter.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Example generated by ../examples.sh
22
[formatter.sql-formatter]
3-
command = "sql-formatter"
3+
command = "sql-formatter-fix"
44
excludes = []
55
includes = ["*.sql"]
6-
options = ["--fix"]
6+
options = []

programs/sql-formatter.nix

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
pkgs,
23
lib,
34
config,
45
mkFormatterModule,
@@ -34,9 +35,6 @@ in
3435
(mkFormatterModule {
3536
name = "sql-formatter";
3637
package = "sql-formatter";
37-
args = [
38-
"--fix"
39-
];
4038
includes = [ "*.sql" ];
4139
})
4240
];
@@ -52,10 +50,15 @@ in
5250

5351
config = lib.mkIf cfg.enable {
5452
settings.formatter.sql-formatter = {
55-
command = "${cfg.package}/bin/sql-formatter";
56-
options = lib.optionals (cfg.dialect != null) [
57-
"-l=${cfg.dialect}"
58-
];
53+
# sql-formatter doesn't support multiple file targets
54+
# see https://github.com/sql-formatter-org/sql-formatter/issues/552
55+
command = pkgs.writeShellScriptBin "sql-formatter-fix" ''
56+
for file in "$@"; do
57+
${cfg.package}/bin/sql-formatter --fix ${
58+
lib.optionalString (cfg.dialect != null) "-l ${cfg.dialect}"
59+
} $file
60+
done
61+
'';
5962
};
6063
};
6164
}

0 commit comments

Comments
 (0)