Skip to content

Commit

Permalink
lint(track_config): improve concepts check
Browse files Browse the repository at this point in the history
  • Loading branch information
ee7 committed Sep 5, 2021
1 parent d95abbd commit 91c1a17
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/lint/track_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,16 @@ type
Exercises = object
`concept`: seq[ConceptExercise]

Concept = object
name: string
slug: string
uuid: string

Concepts = seq[Concept]

TrackConfig = object
exercises: Exercises
concepts: Concepts

proc hasValidPrerequisites(s: string; path: Path): bool =
# TODO: Add the missing checks to this proc.
Expand All @@ -230,6 +238,10 @@ proc hasValidPrerequisites(s: string; path: Path): bool =
for conceptTaught in conceptExercise.concepts:
conceptsTaught.incl conceptTaught

var conceptSlugs = initHashSet[string]()
for con in trackConfig.concepts:
conceptSlugs.incl con.slug

# Require that every prerequisite is taught by different Concept Exercise
for conceptExercise in trackConfig.exercises.`concept`:
if conceptExercise.status in [sBeta, sActive]:
Expand All @@ -244,6 +256,12 @@ proc hasValidPrerequisites(s: string; path: Path): bool =
"`concepts` array of any other user-facing Concept Exercise"
result.setFalseAndPrint(msg, path)

if prereq notin conceptSlugs:
let msg = &"The Concept Exercise {q conceptExercise.slug} has " &
&"{q preReq} in its `prerequisites`, which is not a `slug` " &
"in the list of `concepts`"
result.setFalseAndPrint(msg, path)

proc isValidTrackConfig(data: JsonNode; path: Path): bool =
if isObject(data, jsonRoot, path):
let checks = [
Expand Down

0 comments on commit 91c1a17

Please sign in to comment.