2
2
let
3
3
inherit ( config ) hooks tools settings ;
4
4
cfg = config ;
5
- inherit ( lib ) flatten mapAttrs mapAttrsToList mkDefault mkOption mkRenamedOptionModule types ;
5
+ inherit ( lib ) flatten mapAttrs mapAttrsToList mkDefault mkOption mkRemovedOptionModule mkRenamedOptionModule types ;
6
6
7
7
cargoManifestPathArg =
8
8
lib . optionalString
27
27
imports =
28
28
# Rename `settings.<name>.package` to `hooks.<name>.package`
29
29
map ( name : mkRenamedOptionModule [ "settings" name "package" ] [ "hooks" name "package" ] ) [ "alejandra" "eclint" "flynt" "mdl" "treefmt" ]
30
- # Manually rename options that had a package option
30
+ # These options were renamed in 20fbe2c9731810b1020572a2cb6cbf64e3dd3873 to avoid shadowing
31
+ ++ map ( name : mkRenamedOptionModule [ "settings" name "config" ] [ "hooks" name "settings" "configuration" ] ) [ "lua-ls" "markdownlint" "typos" "vale" ]
32
+ ++ [
33
+ ( mkRemovedOptionModule [ "settings" "yamllint" "relaxed" ] ''
34
+ This option has been removed. Use `hooks.yamllint.settings.preset = "relaxed"`.
35
+ '' )
36
+ ]
37
+ # Manually rename options that had a package or a config option
31
38
++ flatten ( mapAttrsToList ( name : map ( o : mkRenamedOptionModule [ "settings" name o ] [ "hooks" name "settings" o ] ) ) {
32
39
"alejandra" = [ "check" "exclude" "threads" "verbosity" ] ;
33
40
"eclint" = [ "fix" "summary" "color" "exclude" "verbosity" ] ;
34
41
"flynt" = [ "aggressive" "binPath" "dry-run" "exclude" "fail-on-change" "line-length" "no-multiline" "quiet" "string" "transform-concats" "verbose" ] ;
35
42
"mdl" = [ "configPath" "git-recurse" "ignore-front-matter" "json" "rules" "rulesets" "show-aliases" "warnings" "skip-default-ruleset" "style" "tags" "verbose" ] ;
43
+ "lua-ls" = [ "checklevel" ] ;
44
+ "typos" = [ "binary" "color" "configPath" "diff" "exclude" "format" "hidden" "ignored-words" "locale" "no-check-filenames" "no-check-files" "no-unicode" "quiet" "verbose" "write" ] ;
45
+ "vale" = [ "configPath" "flags" ] ;
46
+ "yamllint" = [ "configPath" ] ;
36
47
} )
37
48
# Rename the remaining `settings.<name>` to `hooks.<name>.settings`
38
49
++ map ( name : mkRenamedOptionModule [ "settings" name ] [ "hooks" name "settings" ] )
39
- [ "ansible-lint" "autoflake" "clippy" "cmake-format" "credo" "deadnix" "denofmt" "denolint" "dune-fmt" "eslint" "flake8" "headache" "hlint" "hpack" "isort" "latexindent" "lua-ls" " lychee" "markdownlint" " mkdocs-linkcheck" "mypy" "nixfmt" "ormolu" "php-cs-fixer" "phpcbf" "phpcs" "phpstan" "prettier" "psalm" "pylint" "pyright" "pyupgrade" "revive" "rome" "statix" "typos" "vale" "yamllint " ] ;
50
+ [ "ansible-lint" "autoflake" "clippy" "cmake-format" "credo" "deadnix" "denofmt" "denolint" "dune-fmt" "eslint" "flake8" "headache" "hlint" "hpack" "isort" "latexindent" "lychee" "mkdocs-linkcheck" "mypy" "nixfmt" "ormolu" "php-cs-fixer" "phpcbf" "phpcs" "phpstan" "prettier" "psalm" "pylint" "pyright" "pyupgrade" "revive" "rome" "statix" ] ;
40
51
41
52
options . hookModule = lib . mkOption {
42
53
type = types . deferredModule ;
594
605
"The diagnostic check level" ;
595
606
default = "Warning" ;
596
607
} ;
597
- config = mkOption {
608
+ configuration = mkOption {
598
609
type = types . attrs ;
599
610
description = lib . mdDoc
600
611
"See https://github.com/LuaLS/lua-language-server/wiki/Configuration-File#luarcjson" ;
628
639
type = types . submodule {
629
640
imports = [ hookModule ] ;
630
641
options . settings = {
631
- config =
642
+ configuration =
632
643
mkOption {
633
644
type = types . attrs ;
634
645
description = lib . mdDoc
1416
1427
description = lib . mdDoc "When to use generate output." ;
1417
1428
default = "auto" ;
1418
1429
} ;
1419
- config =
1430
+ configuration =
1420
1431
mkOption {
1421
1432
type = types . str ;
1422
1433
description = lib . mdDoc "Multiline-string configuration passed as config file. If set, config set in `typos.settings.configPath` gets ignored." ;
1537
1548
type = types . submodule {
1538
1549
imports = [ hookModule ] ;
1539
1550
options . settings = {
1540
- config =
1551
+ configuration =
1541
1552
mkOption {
1542
1553
type = types . str ;
1543
1554
description = lib . mdDoc "Multiline-string configuration passed as config file." ;
@@ -1568,19 +1579,53 @@ in
1568
1579
type = types . submodule {
1569
1580
imports = [ hookModule ] ;
1570
1581
options . settings = {
1571
- relaxed = mkOption {
1572
- type = types . bool ;
1573
- description = lib . mdDoc "Whether to use the relaxed configuration." ;
1574
- default = false ;
1575
- } ;
1582
+ # `list-files` is not useful for a pre-commit hook as it always exits with exit code 0
1583
+ # `no-warnings` is not useful for a pre-commit hook as it exits with exit code 2 and the hook
1584
+ # therefore fails when warnings level problems are detected but there is no output
1585
+ configuration = mkOption {
1586
+ type = types . str ;
1587
+ description = lib . mdDoc "Multiline-string configuration passed as config file. If set, configuration file set in `yamllint.settings.configPath` gets ignored." ;
1588
+ default = "" ;
1589
+ example = ''
1590
+ ---
1591
+
1592
+ extends: relaxed
1576
1593
1594
+ rules:
1595
+ indentation: enable
1596
+ '' ;
1597
+ } ;
1598
+ configData = mkOption {
1599
+ type = types . str ;
1600
+ description = lib . mdDoc "Serialized YAML object describing the configuration." ;
1601
+ default = "" ;
1602
+ example = "{extends: relaxed, rules: {line-length: {max: 120}}}" ;
1603
+ } ;
1577
1604
configPath = mkOption {
1578
1605
type = types . str ;
1579
- description = lib . mdDoc "Path to the YAML configuration file." ;
1580
- # an empty string translates to use default configuration of the
1581
- # underlying yamllint binary
1606
+ description = lib . mdDoc "Path to a custom configuration file." ;
1607
+ # An empty string translates to yamllint looking for a configuration file in the
1608
+ # following locations (by order of preference):
1609
+ # a file named .yamllint, .yamllint.yaml or .yamllint.yml in the current working directory
1610
+ # a filename referenced by $YAMLLINT_CONFIG_FILE, if set
1611
+ # a file named $XDG_CONFIG_HOME/yamllint/config or ~/.config/yamllint/config, if present
1582
1612
default = "" ;
1583
1613
} ;
1614
+ format = mkOption {
1615
+ type = types . enum [ "parsable" "standard" "colored" "github" "auto" ] ;
1616
+ description = lib . mdDoc "Format for parsing output." ;
1617
+ default = "auto" ;
1618
+ } ;
1619
+ preset = mkOption {
1620
+ type = types . enum [ "default" "relaxed" ] ;
1621
+ description = lib . mdDoc "The configuration preset to use." ;
1622
+ default = "default" ;
1623
+ } ;
1624
+ strict = mkOption {
1625
+ type = types . bool ;
1626
+ description = lib . mdDoc "Return non-zero exit code on warnings as well as errors." ;
1627
+ default = true ;
1628
+ } ;
1584
1629
} ;
1585
1630
} ;
1586
1631
} ;
@@ -2483,7 +2528,7 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol
2483
2528
let
2484
2529
# .luarc.json has to be in a directory,
2485
2530
# or lua-language-server will hang forever.
2486
- luarc = pkgs . writeText ".luarc.json" ( builtins . toJSON hooks . lua-ls . settings . config ) ;
2531
+ luarc = pkgs . writeText ".luarc.json" ( builtins . toJSON hooks . lua-ls . settings . configuration ) ;
2487
2532
luarc-dir = pkgs . stdenv . mkDerivation {
2488
2533
name = "luarc" ;
2489
2534
unpackPhase = "true" ;
@@ -2547,7 +2592,7 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol
2547
2592
name = "markdownlint" ;
2548
2593
description = "Style checker and linter for markdown files." ;
2549
2594
package = tools . markdownlint-cli ;
2550
- entry = "${ hooks . markdownlint . package } /bin/markdownlint -c ${ pkgs . writeText "markdownlint.json" ( builtins . toJSON hooks . markdownlint . settings . config ) } " ;
2595
+ entry = "${ hooks . markdownlint . package } /bin/markdownlint -c ${ pkgs . writeText "markdownlint.json" ( builtins . toJSON hooks . markdownlint . settings . configuration ) } " ;
2551
2596
files = "\\ .md$" ;
2552
2597
} ;
2553
2598
mdl =
@@ -3262,15 +3307,15 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol
3262
3307
entry =
3263
3308
let
3264
3309
# Concatenate config in config file with section for ignoring words generated from list of words to ignore
3265
- config = "${ hooks . typos . settings . config } " + lib . strings . optionalString ( hooks . typos . settings . ignored-words != [ ] ) "\n \[ default.extend-words\] " + lib . strings . concatMapStrings ( x : "\n ${ x } = \" ${ x } \" " ) hooks . typos . settings . ignored-words ;
3266
- configFile = builtins . toFile "typos-config.toml" config ;
3310
+ configuration = "${ hooks . typos . settings . configuration } " + lib . strings . optionalString ( hooks . typos . settings . ignored-words != [ ] ) "\n \[ default.extend-words\] " + lib . strings . concatMapStrings ( x : "\n ${ x } = \" ${ x } \" " ) hooks . typos . settings . ignored-words ;
3311
+ configFile = builtins . toFile "typos-config.toml" configuration ;
3267
3312
cmdArgs =
3268
3313
mkCmdArgs
3269
3314
( with hooks . typos . settings ; [
3270
3315
[ binary "--binary" ]
3271
3316
[ ( color != "auto" ) "--color ${ color } " ]
3272
- [ ( config != "" ) "--config ${ configFile } " ]
3273
- [ ( configPath != "" && config == "" ) "--config ${ configPath } " ]
3317
+ [ ( configuration != "" ) "--config ${ configFile } " ]
3318
+ [ ( configPath != "" && configuration == "" ) "--config ${ configPath } " ]
3274
3319
[ diff "--diff" ]
3275
3320
[ ( exclude != "" ) "--exclude ${ exclude } --force-exclude" ]
3276
3321
[ ( format != "long" ) "--format ${ format } " ]
@@ -3306,7 +3351,7 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol
3306
3351
mkCmdArgs
3307
3352
( with hooks . vale . settings ; [
3308
3353
[ ( configPath != "" ) " --config ${ configPath } " ]
3309
- [ ( config != "" && configPath == "" ) " --config ${ configFile } " ]
3354
+ [ ( configuration != "" && configPath == "" ) " --config ${ configFile } " ]
3310
3355
] ) ;
3311
3356
in
3312
3357
"${ hooks . vale . package } /bin/vale${ cmdArgs } ${ hooks . vale . settings . flags } " ;
@@ -3315,16 +3360,23 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol
3315
3360
yamllint =
3316
3361
{
3317
3362
name = "yamllint" ;
3318
- description = "Yaml linter ." ;
3363
+ description = "Linter for YAML files ." ;
3319
3364
types = [ "file" "yaml" ] ;
3320
3365
package = tools . yamllint ;
3321
3366
entry =
3322
3367
let
3368
+ configFile = builtins . toFile "yamllint.yaml" "${ hooks . yamllint . settings . configuration } " ;
3323
3369
cmdArgs =
3324
- mkCmdArgs [
3325
- [ ( hooks . yamllint . settings . relaxed ) "-d relaxed" ]
3326
- [ ( hooks . yamllint . settings . configPath != "" ) "-c ${ hooks . yamllint . settings . configPath } " ]
3327
- ] ;
3370
+ mkCmdArgs
3371
+ ( with hooks . yamllint . settings ; [
3372
+ # Priorize multiline configuration over serialized configuration and configuration file
3373
+ [ ( configuration != "" ) "--config-file ${ configFile } " ]
3374
+ [ ( configData != "" && configuration == "" ) "--config-data \" ${ configData } \" " ]
3375
+ [ ( configPath != "" && configData == "" && configuration == "" && preset == "default" ) "--config-file ${ configPath } " ]
3376
+ [ ( format != "auto" ) "--format ${ format } " ]
3377
+ [ ( preset != "default" && configuration == "" ) "--config-data ${ preset } " ]
3378
+ [ strict "--strict" ]
3379
+ ] ) ;
3328
3380
in
3329
3381
"${ hooks . yamllint . package } /bin/yamllint ${ cmdArgs } " ;
3330
3382
} ;
0 commit comments