From 9bb934626588aea506358a2ed28bcc62bca7e094 Mon Sep 17 00:00:00 2001 From: ee7 <45465154+ee7@users.noreply.github.com> Date: Fri, 2 Apr 2021 08:50:11 +0200 Subject: [PATCH] lint: check concept `.meta/config.json` files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/lint/concepts.nim | 22 ++++++++++++++++++++++ src/lint/lint.nim | 2 ++ 2 files changed, 24 insertions(+) diff --git a/src/lint/concepts.nim b/src/lint/concepts.nim index 8926723b..fbbe9e34 100644 --- a/src/lint/concepts.nim +++ b/src/lint/concepts.nim @@ -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. diff --git a/src/lint/lint.nim b/src/lint/lint.nim index 6500d4c8..7fdcbc6c 100644 --- a/src/lint/lint.nim +++ b/src/lint/lint.nim @@ -12,6 +12,7 @@ proc allChecksPass(trackDir: Path): bool = practiceExerciseDocsExist(trackDir), conceptDocsExist(trackDir), isEveryConceptLinksFileValid(trackDir), + isEveryConceptConfigValid(trackDir), isEveryConceptExerciseConfigValid(trackDir), isEveryPracticeExerciseConfigValid(trackDir), ] @@ -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