Skip to content

Commit

Permalink
lint: validate unique string arrays
Browse files Browse the repository at this point in the history
This commit validates that the following properties don't have any duplicate values:

Track config:
- `exercises.concept.concepts`
- `exercises.concept.prerequisites`
- `exercises.practice.practices`
- `exercises.practice.prerequisites`

Concept Exercise config:
- `authors`
- `contributors`
- `forked_from`

Practice Exercise config:
- `authors`
- `contributors`
  • Loading branch information
ErikSchierboom committed Apr 30, 2021
1 parent 3ab3a42 commit 0a4b30f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/lint/concept_exercises.nim
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ proc isValidConceptExerciseConfig(data: JsonNode, path: Path): bool =
if isObject(data, "", path):
let checks = [
hasString(data, "blurb", path, maxLen = 350),
hasArrayOfStrings(data, "authors", path),
hasArrayOfStrings(data, "contributors", path, isRequired = false),
hasArrayOfStrings(data, "authors", path, uniqueValues = true),
hasArrayOfStrings(data, "contributors", path, isRequired = false,
uniqueValues = true),
hasValidFiles(data, path),
hasArrayOfStrings(data, "forked_from", path, isRequired = false),
hasArrayOfStrings(data, "forked_from", path, isRequired = false,
uniqueValues = true),
hasString(data, "language_versions", path, isRequired = false),
hasString(data, "icon", path, isRequired = false, checkIsKebab = true),
]
Expand Down
6 changes: 4 additions & 2 deletions src/lint/practice_exercises.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ proc isValidPracticeExerciseConfig(data: JsonNode, path: Path): bool =
# TODO: Enable the `files` checks after the tracks have had some time to update.
let checks = [
hasString(data, "blurb", path, maxLen = 350),
hasArrayOfStrings(data, "authors", path, isRequired = false),
hasArrayOfStrings(data, "contributors", path, isRequired = false),
hasArrayOfStrings(data, "authors", path, isRequired = false,
uniqueValues = true),
hasArrayOfStrings(data, "contributors", path, isRequired = false,
uniqueValues = true),
if false: hasValidFiles(data, path) else: true,
hasString(data, "language_versions", path, isRequired = false),
]
Expand Down
12 changes: 8 additions & 4 deletions src/lint/track_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ proc isValidConceptExercise(data: JsonNode; context: string; path: Path): bool =
hasString(data, "uuid", path, context, checkIsUuid = true),
hasBoolean(data, "deprecated", path, context, isRequired = false),
hasArrayOfStrings(data, "concepts", path, context,
allowedArrayLen = 0..int.high, checkIsKebab = true),
allowedArrayLen = 0..int.high, checkIsKebab = true,
uniqueValues = true),
hasArrayOfStrings(data, "prerequisites", path, context,
allowedArrayLen = 0..int.high, checkIsKebab = true),
allowedArrayLen = 0..int.high, checkIsKebab = true,
uniqueValues = true),
hasString(data, "status", path, context, isRequired = false,
allowed = statuses),
]
Expand All @@ -99,9 +101,11 @@ proc isValidPracticeExercise(data: JsonNode; context: string;
hasBoolean(data, "deprecated", path, context, isRequired = false),
hasInteger(data, "difficulty", path, context, allowed = 0..10),
hasArrayOfStrings(data, "practices", path, context,
allowedArrayLen = 0..int.high, checkIsKebab = true),
allowedArrayLen = 0..int.high, checkIsKebab = true,
uniqueValues = true),
hasArrayOfStrings(data, "prerequisites", path, context,
allowedArrayLen = 0..int.high, checkIsKebab = true),
allowedArrayLen = 0..int.high, checkIsKebab = true,
uniqueValues = true),
hasString(data, "status", path, context, isRequired = false,
allowed = statuses),
]
Expand Down

0 comments on commit 0a4b30f

Please sign in to comment.