Skip to content

Commit

Permalink
README, CONTRIBUTING, and LICENSE files throw INFO if they are not UP…
Browse files Browse the repository at this point in the history
…PERCASE
  • Loading branch information
willoller committed Apr 27, 2015
1 parent c946379 commit 5583885
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 14 deletions.
2 changes: 1 addition & 1 deletion flint/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func NewApp() *cli.App {
app := cli.NewApp()
app.Name = "flint"
app.Usage = "Check a project for common sources of contributor friction"
app.Version = "0.0.4"
app.Version = "0.0.4.1"
app.Flags = []cli.Flag{
cli.BoolFlag{"skip-readme", "skip check for README", ""},
cli.BoolFlag{"skip-contributing", "skip check for contributing guide", ""},
Expand Down
16 changes: 15 additions & 1 deletion flint/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,35 @@ var ReadmeNotFoundInfo = &LintError{
"Every project begins with a README. http://bit.ly/1dqUYQF",
}

var ReadmeLowercaseInfo = &LintError{
0,
"README file name should be in UPPERCASE for sorting.",
}

var ContributingNotFoundError = &LintError{
2,
"CONTRIBUTING guide not found",
}

var ContributingNotFoundInfo = &LintError{
0,
"Add a guide for potential contributors. http://git.io/z-TiGg",
}

var ContributingLowercaseInfo = &LintError{
0,
"CONTRIBUTING guide file name should be in UPPERCASE for sorting.",
}

var LicenseNotFoundError = &LintError{
2,
"LICENSE not found",
}

var LicenseLowercaseInfo = &LintError{
0,
"LICENSE file name should be in UPPERCASE for sorting.",
}

var LicenseNotFoundInfo = &LintError{
0,
"Add a license to protect yourself and your users. http://choosealicense.com/",
Expand Down
31 changes: 25 additions & 6 deletions flint/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ type Flags struct {

type Project interface {
CheckReadme() bool
CheckLowercaseReadme() bool
CheckContributing() bool
CheckLowercaseContributing() bool
CheckLicense() bool
CheckLowercaseLicense() bool
CheckBootstrap() bool
CheckTestScript() bool
}
Expand All @@ -30,21 +33,37 @@ func (l *Linter) Run(p Project, flags *Flags) (summary *Summary, err error) {
summary = &Summary{}

if flags.RunReadme && !p.CheckReadme() {
summary.AppendError(ReadmeNotFoundError)
summary.AppendError(ReadmeNotFoundInfo)
if p.CheckLowercaseReadme() {
summary.AppendError(ReadmeLowercaseInfo)
} else {
summary.AppendError(ReadmeNotFoundError)
summary.AppendError(ReadmeNotFoundInfo)
}
}

if flags.RunContributing && !p.CheckContributing() {
summary.AppendError(ContributingNotFoundError)
summary.AppendError(ContributingNotFoundInfo)
if p.CheckLowercaseContributing(){
summary.AppendError(ContributingLowercaseInfo)
} else {
summary.AppendError(ContributingNotFoundError)
summary.AppendError(ContributingNotFoundInfo)
}
}

if flags.RunLicense && !p.CheckLicense() {
summary.AppendError(LicenseNotFoundError)
summary.AppendError(LicenseNotFoundInfo)
if p.CheckLowercaseLicense() {
summary.AppendError(LicenseLowercaseInfo)
} else {
summary.AppendError(LicenseNotFoundError)
summary.AppendError(LicenseNotFoundInfo)
}
}

if flags.RunBootstrap && !p.CheckBootstrap() {
summary.AppendError(BootstrapNotFoundError)
summary.AppendError(BootstrapNotFoundInfo)
}

if flags.RunTestScript && !p.CheckTestScript() {
summary.AppendError(TestScriptNotFoundError)
summary.AppendError(TestScriptNotFoundInfo)
Expand Down
12 changes: 12 additions & 0 deletions flint/linter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,26 @@ func (p *FakeProject) CheckReadme() bool {
return p.RunReadme
}

func (p *FakeProject) CheckLowercaseReadme() bool {
return p.RunReadme
}

func (p *FakeProject) CheckContributing() bool {
return p.RunContributing
}

func (p *FakeProject) CheckLowercaseContributing() bool {
return p.RunContributing
}

func (p *FakeProject) CheckLicense() bool {
return p.RunLicense
}

func (p *FakeProject) CheckLowercaseLicense() bool {
return p.RunLicense
}

func (p *FakeProject) CheckBootstrap() bool {
return p.RunBootstrap
}
Expand Down
12 changes: 12 additions & 0 deletions flint/local_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,26 @@ func (l *LocalProject) CheckReadme() bool {
return l.searchPath("README*")
}

func (l *LocalProject) CheckLowercaseReadme() bool {
return l.searchPath("[Rr]eadme*")
}

func (l *LocalProject) CheckContributing() bool {
return l.searchPath("CONTRIBUTING*")
}

func (l *LocalProject) CheckLowercaseContributing() bool {
return l.searchPath("[Cc]ontributing*")
}

func (l *LocalProject) CheckLicense() bool {
return l.searchPath("LICENSE*")
}

func (l *LocalProject) CheckLowercaseLicense() bool {
return l.searchPath("[Ll]icense*")
}

func (l *LocalProject) CheckBootstrap() bool {
return l.searchPath("script/bootstrap")
}
Expand Down
32 changes: 32 additions & 0 deletions flint/local_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ var readmeTests = []scenarios{
{"README.rst", true},
{"docs/README.rst", false},
{"docs/README.md", false},
{"Readme.md", false},
{"readme.md", false},
}

func TestLocalProjectFindsReadme(t *testing.T) {
Expand All @@ -40,6 +42,36 @@ func TestLocalProjectFindsReadme(t *testing.T) {
}
}

var lowercaseReadmeTests = []scenarios{
{"", false},
{"README", false},
{"README.md", false},
{"README.rst", false},
{"docs/README.rst", false},
{"docs/README.md", false},
{"Readme.md", true},
{"readme.md", true},
{"docs/Readme.rst", false},
{"docs/Readme.md", false},
}

func TestLocalProjectFindsLowercaseReadme(t *testing.T) {
for _, tt := range readmeTests {
setup := setupLocalProjectTest()
defer setup.Teardown()

if len(tt.path) > 0 {
setup.WriteFile(tt.path, "The README")
}

project := &LocalProject{Path: setup.Path}
actual := project.CheckReadme()

msg := fmt.Sprintf("Path: '%s', Errors: %d", tt.path, tt.result)
assert.Equal(t, tt.result, actual, msg)
}
}

var contributingTests = []scenarios{
{"", false},
{"CONTRIBUTING", true},
Expand Down
18 changes: 15 additions & 3 deletions flint/remote_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,27 @@ func (l *RemoteProject) searchPath(re *regexp.Regexp) bool {
}

func (l *RemoteProject) CheckReadme() bool {
return l.searchPath(regexp.MustCompile(`README`))
return l.searchPath(regexp.MustCompile(`(?i)README`))
}

func (l *RemoteProject) CheckLowercaseReadme() bool {
return l.searchPath(regexp.MustCompile(`[Rr]eadme`))
}

func (l *RemoteProject) CheckContributing() bool {
return l.searchPath(regexp.MustCompile(`CONTRIBUTING`))
return l.searchPath(regexp.MustCompile(`(?i)CONTRIBUTING`))
}

func (l *RemoteProject) CheckLowercaseContributing() bool {
return l.searchPath(regexp.MustCompile(`[Cc]ontributing`))
}

func (l *RemoteProject) CheckLicense() bool {
return l.searchPath(regexp.MustCompile(`LICENSE`))
return l.searchPath(regexp.MustCompile(`(?i)LICENSE`))
}

func (l *RemoteProject) CheckLowercaseLicense() bool {
return l.searchPath(regexp.MustCompile(`[Ll]icense`))
}

func (l *RemoteProject) CheckBootstrap() bool {
Expand Down
45 changes: 42 additions & 3 deletions flint/remote_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,20 @@ func TestRemoteProjectCheckReadme(t *testing.T) {
project = &RemoteProject{FullName: "projects/lowercase-names"}
err = project.Fetch(fetcher)
assert.Nil(t, err)
assert.False(t, project.CheckReadme())
assert.True(t, project.CheckReadme())
}

func TestRemoteProjectCheckLowercaseReadme(t *testing.T) {
project := &RemoteProject{FullName: "octokit/octokit.rb"}
fetcher := &FakeProjectFetcher{}
err := project.Fetch(fetcher)
assert.Nil(t, err)
assert.True(t, project.CheckReadme())

project = &RemoteProject{FullName: "projects/lowercase-names"}
err = project.Fetch(fetcher)
assert.Nil(t, err)
assert.True(t, project.CheckLowercaseReadme())
}

func TestRemoteProjectCheckContributing(t *testing.T) {
Expand All @@ -54,7 +67,20 @@ func TestRemoteProjectCheckContributing(t *testing.T) {
project = &RemoteProject{FullName: "projects/lowercase-names"}
err = project.Fetch(fetcher)
assert.Nil(t, err)
assert.False(t, project.CheckContributing())
assert.True(t, project.CheckContributing())
}

func TestRemoteProjectCheckLowercaseContributing(t *testing.T) {
project := &RemoteProject{FullName: "octokit/octokit.rb"}
fetcher := &FakeProjectFetcher{}
err := project.Fetch(fetcher)
assert.Nil(t, err)
assert.True(t, project.CheckContributing())

project = &RemoteProject{FullName: "projects/lowercase-names"}
err = project.Fetch(fetcher)
assert.Nil(t, err)
assert.True(t, project.CheckLowercaseContributing())
}

func TestRemoteProjectCheckLicense(t *testing.T) {
Expand All @@ -67,7 +93,20 @@ func TestRemoteProjectCheckLicense(t *testing.T) {
project = &RemoteProject{FullName: "projects/lowercase-names"}
err = project.Fetch(fetcher)
assert.Nil(t, err)
assert.False(t, project.CheckLicense())
assert.True(t, project.CheckLicense())
}

func TestRemoteProjectCheckLowercaseLicense(t *testing.T) {
project := &RemoteProject{FullName: "octokit/octokit.rb"}
fetcher := &FakeProjectFetcher{}
err := project.Fetch(fetcher)
assert.Nil(t, err)
assert.True(t, project.CheckLicense())

project = &RemoteProject{FullName: "projects/lowercase-names"}
err = project.Fetch(fetcher)
assert.Nil(t, err)
assert.True(t, project.CheckLowercaseLicense())
}

func TestRemoteProjectCheckBootstrap(t *testing.T) {
Expand Down

0 comments on commit 5583885

Please sign in to comment.