Skip to content

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 added TestMissingReadme would fail if the attached code change
  were incorrect.
* The added TestLintTrack case on missing-readmes would fail without
  the attached code change.

Closes exercism/discussions#200
Closes exercism/configlet#86
  • Loading branch information
petertseng committed Oct 16, 2017
1 parent bc1d133 commit a72782d
Show file tree
Hide file tree
Showing 5 changed files with 62 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
26 changes: 26 additions & 0 deletions cmd/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func TestLintTrack(t *testing.T) {
path: "../fixtures/broken-maintainers",
expected: true,
},
{
desc: "should fail when given a track missing READMEs.",
path: "../fixtures/missing-readmes",
expected: true,
},
{
desc: "should not fail when given a track with all of its bits in place.",
path: "../fixtures/lint/valid-track",
Expand Down Expand Up @@ -110,6 +115,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 READMEs 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
13 changes: 13 additions & 0 deletions fixtures/missing-readme/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"slug": "missing-readme",
"language": "Missing Readme",
"repository": "https://github.com/exercism/missing-readme",
"active": true,
"exercises": [
{
"slug": "missing-readme",
"topics": [],
"difficulty": 1
}
]
}
Empty file.
Empty file.

0 comments on commit a72782d

Please sign in to comment.