diff --git a/README.md b/README.md index 768201d..f78c182 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ This repository compiles the checks mandated by the MLS spec and their status of - `views/` contains the dhall code generating the visual representations - `views/dashboad.dhall`: generates the dashboard - `views/bookmarkletPage.dhall` generates the page containing the bookmarklet for highlighting the RFC +- `views/gen-check-ids-script.dhall`: generates a shell script to check for missing validation check IDs in the codebase ## Reference diff --git a/views/gen-check-ids-script.dhall b/views/gen-check-ids-script.dhall new file mode 100644 index 0000000..26ebcca --- /dev/null +++ b/views/gen-check-ids-script.dhall @@ -0,0 +1,102 @@ +let Prelude = + https://prelude.dhall-lang.org/v22.0.0/package.dhall + sha256:1c7622fdc868fe3a23462df3e6f533e50fdc12ecf3b42c0bb45c328ec8c4293e + +let Types = ../types.dhall + +let CheckSets = ../checksets.dhall + +let Natural/digits + : Natural -> Natural + = \(num : Natural) -> + if Prelude.Natural.lessThan 10000 num + then 5 + else if Prelude.Natural.lessThan 1000 num + then 4 + else if Prelude.Natural.lessThan 100 num + then 3 + else if Prelude.Natural.lessThan 10 num + then 2 + else 1 + +let Natural/padToText + : Natural -> Natural -> Text + = \(padTo : Natural) -> + \(num : Natural) -> + let digits = Natural/digits num + + let padCount = Natural/subtract digits padTo + + let zeroes = Prelude.Text.replicate padCount "0" + + let actualNumber = Natural/show num + + in zeroes ++ actualNumber + +let Check/toId + : Types.Check -> Text + = \(check : Types.Check) -> "valn" ++ Natural/padToText 4 check.id + +let Status/isComplete + : Types.Status -> Bool + = \(status : Types.Status) -> + merge + { Unknown = False, Missing = False, Partial = False, Complete = True } + status + +let allChecks = + Prelude.List.concatMap + Types.CheckSet + Types.Check + (\(cs : Types.CheckSet) -> cs.checks) + CheckSets + +let completeChecks = + Prelude.List.filter + Types.Check + (\(check : Types.Check) -> Status/isComplete check.implStatus) + allChecks + +let checkIds = Prelude.List.map Types.Check Text Check/toId completeChecks + +let generateCheckCommand + : Text -> Text + = \(id : Text) -> "if ! rg -q '${id}' .; then missing+=(\"${id}\"); fi" + +let checkCommands = Prelude.List.map Text Text generateCheckCommand checkIds + +let script = + '' + #!/bin/bash + + # Parse arguments + if [[ "$1" == "-h" || "$1" == "--help" ]]; then + cat <<'HELP' + Usage: $0 [-h] + + Checks for missing validation check IDs in the codebase. + + This script searches for validation check IDs (e.g., valn0001, valn0002) that are + marked as "Complete" in the validation.dhall repository but are not referenced + in the current codebase. + + Exit codes: + 0 - All expected validation check IDs are present + 1 - One or more validation check IDs are missing + + Options: + -h, --help Show this help message + HELP + exit 0 + fi + + missing=() + ${Prelude.Text.concatSep "\n" checkCommands} + if [ ''${#missing[@]} -gt 0 ]; then + echo "Missing check IDs:" + printf '%s\n' "''${missing[@]}" + exit 1 + fi + '' + +in script