Skip to content

Commit

Permalink
lint: add checking of concept .meta/config.json
Browse files Browse the repository at this point in the history
  • Loading branch information
ee7 committed Apr 2, 2021
1 parent 60ae56e commit e09da95
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/lint/concepts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,27 @@ proc isEveryConceptLinksFileValid*(trackDir: string): bool =
if not isValidLinksFile(j, linksPath):
result = false

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

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

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

proc conceptDocsExist*(trackDir: string): 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: string): 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 e09da95

Please sign in to comment.