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: check concept .meta/config.json files #261

Merged
merged 1 commit into from
May 3, 2021
Merged
Show file tree
Hide file tree
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
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