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 key_features #236

Merged
merged 1 commit into from
Mar 25, 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
39 changes: 39 additions & 0 deletions src/lint/track_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,43 @@ proc hasValidOnlineEditor(data: JsonNode, path: string): bool =
else:
result = false

proc isValidKeyFeature(data: JsonNode, context: string, path: string): bool =
if isObject(data, context, path):
result = true

# TODO: Enable the `icon` checks when we have a list of valid icons.
if false:
const icons = [
"todo",
].toHashSet()

if checkString(data, "icon", path):
let s = data["icon"].getStr()

if s notin icons:
let msg = "The value of `key_features.icon` is `" & s &
"` which is not one of the valid values"
result.setFalseAndPrint(msg, path)
ee7 marked this conversation as resolved.
Show resolved Hide resolved

if not checkString(data, "title", path, maxLen = 25):
result = false
if not checkString(data, "content", path, maxLen = 100):
result = false

proc hasValidKeyFeatures(data: JsonNode, path: string): bool =
result = true
if data.hasKey("key_features"):
let d = data["key_features"]
if isArrayOf(d, "key_features", path, isValidKeyFeature,
isRequired = false):
let arrayLen = d.len
if arrayLen != 0 and arrayLen != 6:
let msg = "The `key_features` array has length " & $arrayLen &
", but must have length 6"
result.setFalseAndPrint(msg, path)
else:
result = false

proc isValidTrackConfig(data: JsonNode, path: string): bool =
if isObject(data, "", path):
result = true
Expand All @@ -115,6 +152,8 @@ proc isValidTrackConfig(data: JsonNode, path: string): bool =
result = false
if not hasValidOnlineEditor(data, path):
result = false
if not hasValidKeyFeatures(data, path):
result = false

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