Skip to content

Commit

Permalink
lint(track_config): check status and online_editor (#235)
Browse files Browse the repository at this point in the history
This commit implements the below rules for a track's `config.json` file.
- The `"status.concept_exercises"` key is required
- The `"status.concept_exercises"` value must be a boolean
- The `"status.test_runner"` key is required
- The `"status.test_runner"` value must be a boolean
- The `"status.representer"` key is required
- The `"status.representer"` value must be a boolean
- The `"status.analyzer"` key is required
- The `"status.analyzer"` value must be a boolean
- The `"online_editor.indent_style"` key is required
- The `"online_editor.indent_style"` value must be the string `space` or `tab`
- The `"online_editor.indent_size"` key is required
- The `"online_editor.indent_size"` value must be an integer >= 0

See the spec:
- https://github.com/exercism/docs/blob/950f1192adcf/building/configlet/lint.md#rule-configjson-file-is-valid
  • Loading branch information
ee7 authored Mar 24, 2021
1 parent f3bfb97 commit 3d19f64
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/lint/track_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,43 @@ proc isValidTag(data: JsonNode, context: string, path: string): bool =
else:
result.setFalseAndPrint("Tag is not a string: " & $data, path)

proc hasValidStatus(data: JsonNode, path: string): bool =
if hasObject(data, "status", path):
result = true
let d = data["status"]

if not checkBoolean(d, "concept_exercises", path):
result = false
if not checkBoolean(d, "test_runner", path):
result = false
if not checkBoolean(d, "representer", path):
result = false
if not checkBoolean(d, "analyzer", path):
result = false

proc hasValidOnlineEditor(data: JsonNode, path: string): bool =
if hasObject(data, "online_editor", path):
result = true
let d = data["online_editor"]

if checkString(d, "indent_style", path):
let s = d["indent_style"].getStr()
if s != "space" and s != "tab":
let msg = "The value of `online_editor.indent_style` is `" & s &
"`, but it must be `space` or `tab`"
result.setFalseAndPrint(msg, path)
else:
result = false

if checkInteger(d, "indent_size", path):
let num = d["indent_size"].getInt()
if num < 0:
let msg = "The value of `online_editor.indent_size` is `" & $num &
"`, but it must be an integer >= 0"
result.setFalseAndPrint(msg, path)
else:
result = false

proc isValidTrackConfig(data: JsonNode, path: string): bool =
if isObject(data, "", path):
result = true
Expand All @@ -74,6 +111,11 @@ proc isValidTrackConfig(data: JsonNode, path: string): bool =
else:
result = false

if not hasValidStatus(data, path):
result = false
if not hasValidOnlineEditor(data, path):
result = false

if not hasArrayOf(data, "tags", path, isValidTag):
result = false

Expand Down

0 comments on commit 3d19f64

Please sign in to comment.