Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint(track_config): check status and online_editor #235

Merged
merged 1 commit into from
Mar 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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