From 3e36a328b86018e8ad63d65aef4b6cda8af5c86d Mon Sep 17 00:00:00 2001 From: Peter Tseng Date: Fri, 13 Oct 2017 17:20:53 -0700 Subject: [PATCH] lint: Check for README presence After https://github.com/exercism/meta/issues/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 https://github.com/exercism/discussions/issues/200 Closes https://github.com/exercism/configlet/issues/86 --- cmd/lint.go | 23 +++++++++++++++++++++ cmd/lint_example_test.go | 1 + fixtures/numbers/config.json | 6 ++++++ fixtures/numbers/exercises/four/example.ext | 0 fixtures/numbers/exercises/four/test.ext | 0 track/track_test.go | 1 + 6 files changed, 31 insertions(+) create mode 100644 fixtures/numbers/exercises/four/example.ext create mode 100644 fixtures/numbers/exercises/four/test.ext diff --git a/cmd/lint.go b/cmd/lint.go index 1ee5056..e733324 100644 --- a/cmd/lint.go +++ b/cmd/lint.go @@ -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.", @@ -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 { diff --git a/cmd/lint_example_test.go b/cmd/lint_example_test.go index c2dac02..8c92039 100644 --- a/cmd/lint_example_test.go +++ b/cmd/lint_example_test.go @@ -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). diff --git a/fixtures/numbers/config.json b/fixtures/numbers/config.json index e8f36e9..73ae56c 100644 --- a/fixtures/numbers/config.json +++ b/fixtures/numbers/config.json @@ -23,6 +23,12 @@ "topics": [], "difficulty": 1 }, + { + "uuid": "444", + "slug": "four", + "topics": [], + "difficulty": 1 + }, { "uuid": "ddd", "slug": "bajillion", diff --git a/fixtures/numbers/exercises/four/example.ext b/fixtures/numbers/exercises/four/example.ext new file mode 100644 index 0000000..e69de29 diff --git a/fixtures/numbers/exercises/four/test.ext b/fixtures/numbers/exercises/four/test.ext new file mode 100644 index 0000000..e69de29 diff --git a/track/track_test.go b/track/track_test.go index 6eb5e1f..d77fd2f 100644 --- a/track/track_test.go +++ b/track/track_test.go @@ -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))