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 added TestMissingReadme would fail if the attached code change
  were incorrect.
* The TestLintTrack 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 other two tests suffice.

Closes exercism/discussions#200
Closes exercism/configlet#86
  • Loading branch information
Peter Tseng committed Oct 14, 2017
1 parent e7c3d0a commit 9838396
Show file tree
Hide file tree
Showing 7 changed files with 52 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 @@ -89,6 +89,10 @@ func lintTrack(path string) bool {
check: missingMetadata,
msg: "An implementation for '%v' was found, but config.json does not reference this exercise.",
},
{
check: missingReadme,
msg: "The implementation for '%v' is missing a README.",
},
{
check: missingSolution,
msg: "The implementation for '%v' is missing an example solution.",
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 @@ -16,6 +16,7 @@ func ExampleLint() {
lintTrack(filepath.FromSlash("../fixtures/numbers"))
// Output:
// -> An exercise with slug 'bajillion' is referenced in config.json, but no implementation was found.
// -> The implementation for 'four' is missing a README.
// -> The implementation for 'three' is missing an example solution.
// -> The implementation for 'two' is missing a test suite.
// -> The exercise 'one' was found in config.json, but does not have a UUID.
Expand Down
21 changes: 21 additions & 0 deletions cmd/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,27 @@ func TestMissingMetadata(t *testing.T) {
assert.Equal(t, "cherry", slugs[1])
}

func TestMissingReadme(t *testing.T) {
track := track.Track{
Exercises: []track.Exercise{
{Slug: "apple"},
{Slug: "banana", ReadmePath: "README.md"},
{Slug: "cherry"},
},
}

slugs := missingReadme(track)

if len(slugs) != 2 {
t.Fatalf("Expected missing solutions in 2 exercises, missing in %d", len(slugs))
}

sort.Strings(slugs)

assert.Equal(t, "apple", slugs[0])
assert.Equal(t, "cherry", slugs[1])
}

func TestMissingSolution(t *testing.T) {
track := track.Track{
Exercises: []track.Exercise{
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 9838396

Please sign in to comment.