Skip to content
This repository has been archived by the owner on Mar 22, 2022. It is now read-only.

Commit

Permalink
lint: Check for README presence
Browse files Browse the repository at this point in the history
After exercism/meta#15, READMEs are to be
generated and placed into each track's exercise implementation
directory.

My (unsubstantiated) assumption is that they will be required to be
present after Nextercism, as we don't want to keep generating READMEs on
the fly.

If this assumption is correct, it seems necessary to check that READMEs
are present on all exercises.

With the attached fixture change and attached test changes:

* The example test would fail without the attached code change.
* The unit test in `lint_test.go` testing against `fixtures/numbers`
  actually does not fail, because there are other reasons for the track
  to be invalid, so the attached code change was not necessary. This
  points to the unit test being too coarse, but this is a discussion for
  another day. For now, the example test suffices.

Closes exercism/discussions#200
Closes exercism/configlet#86
  • Loading branch information
Peter Tseng committed Oct 14, 2017
1 parent e7c3d0a commit 3e36a32
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cmd/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ func lintTrack(path string) bool {
check: missingSolution,
msg: "The implementation for '%v' is missing an example solution.",
},
{
check: missingReadme,
msg: "The implementation for '%v' is missing a README.",
},
{
check: missingTestSuite,
msg: "The implementation for '%v' is missing a test suite.",
Expand Down Expand Up @@ -201,6 +205,25 @@ func missingSolution(t track.Track) []string {
return slugs
}

func missingReadme(t track.Track) []string {
readmes := map[string]bool{}
for _, exercise := range t.Exercises {
readmes[exercise.Slug] = exercise.HasReadme()
}
// Don't complain about missing readmes in foregone exercises.
for _, slug := range t.Config.ForegoneSlugs {
readmes[slug] = true
}

slugs := []string{}
for slug, ok := range readmes {
if !ok {
slugs = append(slugs, slug)
}
}
return slugs
}

func missingTestSuite(t track.Track) []string {
tests := map[string]bool{}
for _, exercise := range t.Exercises {
Expand Down
1 change: 1 addition & 0 deletions cmd/lint_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func ExampleLint() {
// Output:
// -> An exercise with slug 'bajillion' is referenced in config.json, but no implementation was found.
// -> The implementation for 'three' is missing an example solution.
// -> The implementation for 'four' is missing a README.
// -> The implementation for 'two' is missing a test suite.
// -> The exercise 'one' was found in config.json, but does not have a UUID.
// -> An implementation for 'zero' was found, but config.json specifies that it should be foregone (not implemented).
Expand Down
6 changes: 6 additions & 0 deletions fixtures/numbers/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
"topics": [],
"difficulty": 1
},
{
"uuid": "444",
"slug": "four",
"topics": [],
"difficulty": 1
},
{
"uuid": "ddd",
"slug": "bajillion",
Expand Down
Empty file.
Empty file.
1 change: 1 addition & 0 deletions track/track_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestNewTrack(t *testing.T) {
"one": false,
"two": false,
"three": false,
"four": false,
}

assert.Equal(t, len(slugs), len(track.Exercises))
Expand Down

0 comments on commit 3e36a32

Please sign in to comment.