Skip to content

Commit

Permalink
lint: check concept .meta/config.json files
Browse files Browse the repository at this point in the history
This commit implements the below checks for each concept's
`.meta/config.json` file.
- The JSON root must be an object
- The `"blurb"` key is required
- The `"blurb"` value must be a non-blank string¹ with length <= 350
- The `"authors"` key is required
- The `"authors"` value must be an array
- The `"authors"` values must be non-blank strings¹
- The `"authors"` values must not have duplicates
- The `"contributors"` key is optional
- The `"contributors"` value must be an array
- The `"contributors"` values must be non-blank strings¹
- The `"contributors"` values must not have duplicates

[1] Non-blank string: a string that contains at least one non-whitespace
    character.
  • Loading branch information
ee7 committed May 1, 2021
1 parent 5f3716b commit 9bb9346
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/lint/concepts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@ proc isEveryConceptLinksFileValid*(trackDir: Path): bool =
if not isValidLinksFile(j, linksPath):
result = false

proc isValidConceptConfig(data: JsonNode, path: Path): bool =
if isObject(data, "", path):
let checks = [
hasString(data, "blurb", path, maxLen = 350),
hasArrayOfStrings(data, "authors", path, uniqueValues = true),
hasArrayOfStrings(data, "contributors", path, isRequired = false,
uniqueValues = true),
]
result = allTrue(checks)

proc isEveryConceptConfigValid*(trackDir: Path): bool =
let conceptsDir = trackDir / "concepts"
result = true

if dirExists(conceptsDir):
for conceptDir in getSortedSubdirs(conceptsDir):
let configPath = conceptDir / ".meta" / "config.json"
let j = parseJsonFile(configPath, result)
if j != nil:
if not isValidConceptConfig(j, configPath):
result = false

proc conceptDocsExist*(trackDir: Path): bool =
## Returns true if every subdirectory in `trackDir/concepts` has the required
## Markdown files.
Expand Down
2 changes: 2 additions & 0 deletions src/lint/lint.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ proc allChecksPass(trackDir: Path): bool =
practiceExerciseDocsExist(trackDir),
conceptDocsExist(trackDir),
isEveryConceptLinksFileValid(trackDir),
isEveryConceptConfigValid(trackDir),
isEveryConceptExerciseConfigValid(trackDir),
isEveryPracticeExerciseConfigValid(trackDir),
]
Expand All @@ -32,6 +33,7 @@ Basic linting finished successfully:
language, slug, active, blurb, version, status, online_editor, key_features, tags
- Every concept has the required .md files
- Every concept has a valid links.json file
- Every concept has a valid .meta/config.json file
- Every concept exercise has the required .md files
- Every concept exercise has a valid .meta/config.json file
- Every practice exercise has the required .md files
Expand Down

0 comments on commit 9bb9346

Please sign in to comment.