Skip to content

Commit 940bad4

Browse files
committed
Use check configuration superproject type field to skip subprojects
The newly added field allows moving the implementation of this filter out of the check function and into the check configuration. It also allows some simplification of the check function tests.
1 parent 308020e commit 940bad4

File tree

5 files changed

+17
-34
lines changed

5 files changed

+17
-34
lines changed

internal/rule/ruleconfiguration/ruleconfiguration.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ var configurations = []Type{
587587
},
588588
{
589589
ProjectType: projecttype.Library,
590-
SuperprojectType: projecttype.All,
590+
SuperprojectType: projecttype.Library,
591591
Category: "library.properties",
592592
Subcategory: "version field",
593593
ID: "LP022",
@@ -1147,7 +1147,7 @@ var configurations = []Type{
11471147
},
11481148
{
11491149
ProjectType: projecttype.Library,
1150-
SuperprojectType: projecttype.All,
1150+
SuperprojectType: projecttype.Library,
11511151
Category: "documentation",
11521152
Subcategory: "miscellaneous",
11531153
ID: "LD001",
@@ -1163,7 +1163,7 @@ var configurations = []Type{
11631163
},
11641164
{
11651165
ProjectType: projecttype.Library,
1166-
SuperprojectType: projecttype.All,
1166+
SuperprojectType: projecttype.Library,
11671167
Category: "documentation",
11681168
Subcategory: "miscellaneous",
11691169
ID: "LD002",
@@ -1339,7 +1339,7 @@ var configurations = []Type{
13391339
},
13401340
{
13411341
ProjectType: projecttype.Sketch,
1342-
SuperprojectType: projecttype.All,
1342+
SuperprojectType: projecttype.Sketch,
13431343
Category: "documentation",
13441344
Subcategory: "miscellaneous",
13451345
ID: "SD001",
@@ -1355,7 +1355,7 @@ var configurations = []Type{
13551355
},
13561356
{
13571357
ProjectType: projecttype.Sketch,
1358-
SuperprojectType: projecttype.All,
1358+
SuperprojectType: projecttype.Sketch,
13591359
Category: "documentation",
13601360
Subcategory: "miscellaneous",
13611361
ID: "SD002",
@@ -1403,7 +1403,7 @@ var configurations = []Type{
14031403
},
14041404
{
14051405
ProjectType: projecttype.Platform,
1406-
SuperprojectType: projecttype.All,
1406+
SuperprojectType: projecttype.Platform,
14071407
Category: "documentation",
14081408
Subcategory: "miscellaneous",
14091409
ID: "PD001",
@@ -1419,7 +1419,7 @@ var configurations = []Type{
14191419
},
14201420
{
14211421
ProjectType: projecttype.Platform,
1422-
SuperprojectType: projecttype.All,
1422+
SuperprojectType: projecttype.Platform,
14231423
Category: "documentation",
14241424
Subcategory: "miscellaneous",
14251425
ID: "PD002",

internal/rule/rulefunction/library.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -571,10 +571,6 @@ func LibraryPropertiesVersionFieldNonSemver() (result ruleresult.Type, output st
571571

572572
// LibraryPropertiesVersionFieldBehindTag checks whether a release tag was made without first bumping the library.properties version value.
573573
func LibraryPropertiesVersionFieldBehindTag() (result ruleresult.Type, output string) {
574-
if projectdata.ProjectType() != projectdata.SuperProjectType() {
575-
return ruleresult.Skip, "Not relevant for subprojects"
576-
}
577-
578574
if projectdata.LibraryPropertiesLoadError() != nil {
579575
return ruleresult.NotRun, "Couldn't load library.properties"
580576
}

internal/rule/rulefunction/library_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,6 @@ func TestLibraryPropertiesVersionFieldBehindTag(t *testing.T) {
494494
}
495495

496496
testTables := []libraryRuleFunctionTestTable{
497-
// TODO: Test Skip if subproject
498497
{"Unable to load", "InvalidLibraryProperties", ruleresult.NotRun, ""},
499498
{"Legacy", "Legacy", ruleresult.NotRun, ""},
500499
{"Unparsable version", "VersionFormatInvalid", ruleresult.NotRun, ""},

internal/rule/rulefunction/rulefunction.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ type Type func() (result ruleresult.Type, output string)
3434

3535
// MissingReadme checks if the project has a readme that will be recognized by GitHub.
3636
func MissingReadme() (result ruleresult.Type, output string) {
37-
if projectdata.ProjectType() != projectdata.SuperProjectType() {
38-
return ruleresult.Skip, "Readme not required for subprojects"
39-
}
40-
4137
// https://github.com/github/markup/blob/master/README.md
4238
readmeRegexp := regexp.MustCompile(`(?i)^readme\.(markdown)|(mdown)|(mkdn)|(md)|(textile)|(rdoc)|(org)|(creole)|(mediawiki)|(wiki)|(rst)|(asciidoc)|(adoc)|(asc)|(pod)|(txt)$`)
4339

@@ -53,10 +49,6 @@ func MissingReadme() (result ruleresult.Type, output string) {
5349

5450
// MissingLicenseFile checks if the project has a license file that will be recognized by GitHub.
5551
func MissingLicenseFile() (result ruleresult.Type, output string) {
56-
if projectdata.ProjectType() != projectdata.SuperProjectType() {
57-
return ruleresult.Skip, "License file not required for subprojects"
58-
}
59-
6052
// https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/licensing-a-repository#detecting-a-license
6153
// https://github.com/licensee/licensee/blob/master/docs/what-we-look-at.md#detecting-the-license-file
6254
// Should be `(?i)^(((un)?licen[sc]e)|(copy(ing|right))|(ofl)|(patents))(\.(?!spdx|header|gemspec).+)?$` but regexp package doesn't support negative lookahead, so only using "preferred extensions".

internal/rule/rulefunction/rulefunction_test.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ func init() {
3838
type ruleFunctionTestTable struct {
3939
testName string
4040
projectFolderName string
41-
projectType projecttype.Type
42-
superProjectType projecttype.Type
4341
expectedRuleResult ruleresult.Type
4442
expectedOutputQuery string
4543
}
@@ -50,8 +48,8 @@ func checkRuleFunction(ruleFunction Type, testTables []ruleFunctionTestTable, t
5048

5149
testProject := project.Type{
5250
Path: testDataPath.Join(testTable.projectFolderName),
53-
ProjectType: testTable.projectType,
54-
SuperprojectType: testTable.superProjectType,
51+
ProjectType: projecttype.Library,
52+
SuperprojectType: projecttype.Library,
5553
}
5654

5755
projectdata.Initialize(testProject)
@@ -64,30 +62,28 @@ func checkRuleFunction(ruleFunction Type, testTables []ruleFunctionTestTable, t
6462

6563
func TestMissingReadme(t *testing.T) {
6664
testTables := []ruleFunctionTestTable{
67-
{"Subproject", "readme", projecttype.Sketch, projecttype.Library, ruleresult.Skip, ""},
68-
{"Readme", "readme", projecttype.Sketch, projecttype.Sketch, ruleresult.Pass, ""},
69-
{"No readme", "no-readme", projecttype.Sketch, projecttype.Sketch, ruleresult.Fail, ""},
65+
{"Readme", "readme", ruleresult.Pass, ""},
66+
{"No readme", "no-readme", ruleresult.Fail, ""},
7067
}
7168

7269
checkRuleFunction(MissingReadme, testTables, t)
7370
}
7471

7572
func TestMissingLicenseFile(t *testing.T) {
7673
testTables := []ruleFunctionTestTable{
77-
{"Subproject", "no-license-file", projecttype.Sketch, projecttype.Library, ruleresult.Skip, ""},
78-
{"Has license", "license-file", projecttype.Sketch, projecttype.Sketch, ruleresult.Pass, ""},
79-
{"Has license in subfolder", "license-file-in-subfolder", projecttype.Sketch, projecttype.Sketch, ruleresult.Fail, ""},
80-
{"No license", "no-license-file", projecttype.Sketch, projecttype.Sketch, ruleresult.Fail, ""},
74+
{"Has license", "license-file", ruleresult.Pass, ""},
75+
{"Has license in subfolder", "license-file-in-subfolder", ruleresult.Fail, ""},
76+
{"No license", "no-license-file", ruleresult.Fail, ""},
8177
}
8278

8379
checkRuleFunction(MissingLicenseFile, testTables, t)
8480
}
8581

8682
func TestIncorrectArduinoDotHFileNameCase(t *testing.T) {
8783
testTables := []ruleFunctionTestTable{
88-
{"Incorrect, angle brackets", "arduino.h-angle", projecttype.Sketch, projecttype.Sketch, ruleresult.Fail, ""},
89-
{"Incorrect, quotes", "arduino.h-quote", projecttype.Sketch, projecttype.Sketch, ruleresult.Fail, ""},
90-
{"Correct case", "Arduino.h", projecttype.Sketch, projecttype.Sketch, ruleresult.Pass, ""},
84+
{"Incorrect, angle brackets", "arduino.h-angle", ruleresult.Fail, ""},
85+
{"Incorrect, quotes", "arduino.h-quote", ruleresult.Fail, ""},
86+
{"Correct case", "Arduino.h", ruleresult.Pass, ""},
9187
}
9288

9389
checkRuleFunction(IncorrectArduinoDotHFileNameCase, testTables, t)

0 commit comments

Comments
 (0)