Skip to content

Commit 9c4469b

Browse files
authored
Merge pull request #700 from lucperkins/sqlfluff-hook
Add sqlfluff module
2 parents f799ae9 + c9e36e6 commit 9c4469b

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

modules/hooks.nix

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,60 @@ in
18331833
};
18341834
};
18351835
};
1836+
sqlfluff = lib.mkOption {
1837+
description = "sqlfluff hook";
1838+
type = types.submodule {
1839+
imports = [ hookModule ];
1840+
options.settings = {
1841+
configPath = mkOption {
1842+
type = types.nullOr (types.oneOf [ types.str types.path ]);
1843+
description = "Path to the SQLFluff config file.";
1844+
default = null;
1845+
example = ".sqlfluff";
1846+
};
1847+
dialect = mkOption {
1848+
type = types.nullOr types.str;
1849+
description = "SQL dialect to use (e.g. postgres, mysql, ansi).";
1850+
default = null;
1851+
example = "postgres";
1852+
};
1853+
path = mkOption {
1854+
type = types.nullOr (types.oneOf [ types.str types.path ]);
1855+
description = "Path to lint. If null, sqlfluff will lint the files passed by the hook runner.";
1856+
default = null;
1857+
example = "migrations/";
1858+
};
1859+
excludeRules = mkOption {
1860+
type = types.listOf types.str;
1861+
description = "Exclude specific rules from linting. For example, [\"LT01\", \"LT02\"].";
1862+
default = [ ];
1863+
example = [ "LT01" "LT02" ];
1864+
};
1865+
ignoreLocalConfig = mkOption {
1866+
type = types.bool;
1867+
description = "Ignore config files in default search path locations. Useful when combined with `configPath` to only use the specified config file.";
1868+
default = false;
1869+
};
1870+
rules = mkOption {
1871+
type = types.listOf types.str;
1872+
description = "Narrow linting to specific rules. For example, [\"LT01\", \"LT02\"].";
1873+
default = [ ];
1874+
example = [ "LT01" "LT02" ];
1875+
};
1876+
processes = mkOption {
1877+
type = types.nullOr types.int;
1878+
description = "The number of parallel processes to run.";
1879+
default = null;
1880+
example = 4;
1881+
};
1882+
format = mkOption {
1883+
type = types.enum [ "human" "json" "yaml" "sarif" "github-annotation" "github-annotation-native" "none" ];
1884+
description = "The format to return lint results in.";
1885+
default = "human";
1886+
};
1887+
};
1888+
};
1889+
};
18361890
statix = mkOption {
18371891
description = "statix hook";
18381892
type = types.submodule {
@@ -4139,6 +4193,33 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.fourm
41394193
entry = "${hooks.sort-simple-yaml.package}/bin/sort-simple-yaml";
41404194
files = "(\\.yaml$)|(\\.yml$)";
41414195
};
4196+
sqlfluff =
4197+
{
4198+
name = "sqlfluff";
4199+
description = "SQL linter and formatter";
4200+
package = tools.sqlfluff;
4201+
entry =
4202+
let
4203+
cmdArgs = mkCmdArgs [
4204+
[ (hooks.sqlfluff.settings.configPath != null) "--config ${hooks.sqlfluff.settings.configPath}" ]
4205+
[ (hooks.sqlfluff.settings.dialect != null) "--dialect ${hooks.sqlfluff.settings.dialect}" ]
4206+
[ (hooks.sqlfluff.settings.excludeRules != [ ]) "--exclude-rules ${lib.strings.concatStringsSep "," hooks.sqlfluff.settings.excludeRules}" ]
4207+
[ hooks.sqlfluff.settings.ignoreLocalConfig "--ignore-local-config" ]
4208+
[ (hooks.sqlfluff.settings.rules != [ ]) "--rules ${lib.strings.concatStringsSep "," hooks.sqlfluff.settings.rules}" ]
4209+
[ (hooks.sqlfluff.settings.processes != null) "--processes ${toString hooks.sqlfluff.settings.processes}" ]
4210+
[ (hooks.sqlfluff.settings.format != "human") "--format ${hooks.sqlfluff.settings.format}" ]
4211+
];
4212+
in
4213+
builtins.concatStringsSep " " (
4214+
[
4215+
(lib.getExe hooks.sqlfluff.package)
4216+
"lint"
4217+
cmdArgs
4218+
] ++ lib.optional (hooks.sqlfluff.settings.path != null) hooks.sqlfluff.settings.path
4219+
);
4220+
types = [ "sql" ];
4221+
pass_filenames = hooks.sqlfluff.settings.path == null;
4222+
};
41424223
staticcheck =
41434224
{
41444225
name = "staticcheck";

nix/tools.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
, bats
8282
, shfmt
8383
, beautysh
84+
, sqlfluff
8485
, statix
8586
, stylish-haskell
8687
, stylua
@@ -183,6 +184,7 @@ in
183184
selene
184185
shellcheck
185186
shfmt
187+
sqlfluff
186188
statix
187189
stylish-haskell
188190
stylua

0 commit comments

Comments
 (0)