-
-
Notifications
You must be signed in to change notification settings - Fork 14
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: add initial linting of practice exercises #219
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import std/[json, os] | ||
import ".."/helpers | ||
import "."/validators | ||
|
||
proc isValidAuthorOrContributor(data: JsonNode, context: string, path: string): bool = | ||
if isObject(data, context, path): | ||
result = true | ||
if not checkString(data, "github_username", path): | ||
result = false | ||
if not checkString(data, "exercism_username", path, isRequired = false): | ||
result = false | ||
|
||
proc checkFiles(data: JsonNode, context, path: string): bool = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is virtually identical to the corresponding concept exercise code, except for |
||
result = true | ||
if hasObject(data, context, path): | ||
if not checkArrayOfStrings(data, context, "solution", path): | ||
result = false | ||
if not checkArrayOfStrings(data, context, "test", path): | ||
result = false | ||
if not checkArrayOfStrings(data, context, "example", path): | ||
result = false | ||
else: | ||
result = false | ||
|
||
proc isValidPracticeExerciseConfig(data: JsonNode, path: string): bool = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once again, this logic is almost identical to the concept exercises' logic. For now, the only difference is that there is no |
||
if isObject(data, "root", path): | ||
result = true | ||
# Temporarily disable the checking of authors as we'll be doing bulk PRs | ||
# to pre-populate this field for all tracks | ||
# if not checkArrayOf(data, "authors", path, isValidAuthorOrContributor): | ||
# result = false | ||
if not checkArrayOf(data, "contributors", path, isValidAuthorOrContributor, | ||
isRequired = false): | ||
result = false | ||
# Temporarily disable the checking of the files to give tracks the chance | ||
# to update this manually | ||
# if not checkFiles(data, "files", path): | ||
# result = false | ||
if not checkString(data, "language_versions", path, isRequired = false): | ||
result = false | ||
|
||
proc isEveryPracticeExerciseConfigValid*(trackDir: string): bool = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And again, this logic is very similar to the concept exercises logic. We could extract it to a helper method. |
||
let practiceExercisesDir = trackDir / "exercises" / "practice" | ||
result = true | ||
# Return true even if the directory does not exist - this allows a future | ||
# track to have concept exercises and no practice exercises. | ||
if dirExists(practiceExercisesDir): | ||
for exerciseDir in getSortedSubdirs(practiceExercisesDir): | ||
let configPath = exerciseDir / ".meta" / "config.json" | ||
if fileExists(configPath): | ||
let j = | ||
try: | ||
parseFile(configPath) | ||
except: | ||
result.setFalseAndPrint("JSON parsing error", getCurrentExceptionMsg()) | ||
continue | ||
if not isValidPracticeExerciseConfig(j, configPath): | ||
result = false | ||
|
||
ee7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
proc practiceExerciseFilesExist*(trackDir: string): bool = | ||
## Returns true if every subdirectory in `trackDir/exercises/practice` has the | ||
## required files. | ||
const | ||
requiredPracticeExerciseFiles = [ | ||
".docs" / "instructions.md", | ||
".meta" / "config.json", | ||
] | ||
|
||
let practiceExercisesDir = trackDir / "exercises" / "practice" | ||
result = subdirsContain(practiceExercisesDir, requiredPracticeExerciseFiles) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is currently duplicated between the practice_exercises and concept_exercises modules. We could extract it to some shared module.