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 (#98)
Browse files Browse the repository at this point in the history
* exercise: add HasReadme

* fixtures: Add READMEs to linted tracks

After exercism/meta#15, READMEs are to be
generated and placed into each track's exercise implementation
directory.

This may even become required at some point. Prepare for this
requirement by placing READMEs in the correct places.

Note: numbers/zero does not require a README as it is foregone.

* lint: Check for README presence

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 authored and nywilken committed Feb 4, 2018
1 parent 2aa5178 commit def9684
Show file tree
Hide file tree
Showing 10 changed files with 74 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-readme",
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
Empty file.
14 changes: 14 additions & 0 deletions fixtures/missing-readme/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"slug": "missing-readme",
"language": "Missing Readme",
"repository": "https://github.com/exercism/missing-readme",
"active": true,
"exercises": [
{
"uuid": "missingmissing",
"slug": "missing-readme",
"topics": [],
"difficulty": 1
}
]
}
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
11 changes: 11 additions & 0 deletions track/exercise.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
// Exercise is an implementation of an Exercism exercise.
type Exercise struct {
Slug string
ReadmePath string
SolutionPath string
TestSuitePath string
}
Expand All @@ -31,6 +32,11 @@ func NewExercise(root string, pg PatternGroup) (Exercise, error) {
return ex, err
}

err = setPath(root, "README\\.md", &ex.ReadmePath)
if err != nil {
return ex, err
}

return ex, err
}

Expand Down Expand Up @@ -62,6 +68,11 @@ func setPath(root, pattern string, field *string) error {
return filepath.Walk(root, walkFn)
}

// HasReadme checks that an exercise has a README.
func (ex Exercise) HasReadme() bool {
return ex.ReadmePath != ""
}

// HasTestSuite checks that an exercise has a test suite.
func (ex Exercise) HasTestSuite() bool {
return ex.TestSuitePath != ""
Expand Down

0 comments on commit def9684

Please sign in to comment.