Skip to content

Commit 59eee5a

Browse files
authored
Merge pull request #127 from arduino/per1234/recursive-default-false
Make the default value of the --recursive flag false
2 parents 1c754bd + 416a7c4 commit 59eee5a

File tree

12 files changed

+78
-25
lines changed

12 files changed

+78
-25
lines changed

Diff for: internal/cli/cli.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func Root() *cobra.Command {
3535
rootCommand.PersistentFlags().String("format", "text", "The output format can be {text|json}.")
3636
rootCommand.PersistentFlags().String("library-manager", "", "Configure the rules for libraries in the Arduino Library Manager index. Can be {submit|update|false}.\nsubmit: Also run additional rules required to pass before a library is accepted for inclusion in the index.\nupdate: Also run additional rules required to pass before new releases of a library already in the index are accepted.\nfalse: Don't run any Library Manager-specific rules.")
3737
rootCommand.PersistentFlags().String("project-type", "all", "Only check projects of the specified type and their subprojects. Can be {sketch|library|all}.")
38-
rootCommand.PersistentFlags().String("recursive", "true", "Search path recursively for Arduino projects to check. Can be {true|false}.")
38+
rootCommand.PersistentFlags().Bool("recursive", false, "Search path recursively for Arduino projects to check. Can be {true|false}.")
3939
rootCommand.PersistentFlags().String("report-file", "", "Save a report on the rules to this file.")
4040
rootCommand.PersistentFlags().BoolP("verbose", "v", false, "Show more information while running rules.")
4141
rootCommand.PersistentFlags().Bool("version", false, "Print version and timestamp of the build.")

Diff for: internal/configuration/configuration.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ func Initialize(flags *pflag.FlagSet, projectPaths []string) error {
8181
return fmt.Errorf("--project-type flag value %s not valid", superprojectTypeFilterString)
8282
}
8383

84-
recursiveString, _ := flags.GetString("recursive")
85-
recursive, err = strconv.ParseBool(recursiveString)
86-
if err != nil {
87-
return fmt.Errorf("--recursive flag value %s not valid", recursiveString)
88-
}
84+
recursive, _ = flags.GetBool("recursive")
8985

9086
reportFilePathString, _ := flags.GetString("report-file")
9187
reportFilePath = paths.New(reportFilePathString)

Diff for: internal/configuration/configuration_test.go

-3
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,6 @@ func TestInitializeProjectType(t *testing.T) {
159159
func TestInitializeRecursive(t *testing.T) {
160160
flags := test.ConfigurationFlags()
161161

162-
flags.Set("recursive", "foo")
163-
assert.Error(t, Initialize(flags, projectPaths))
164-
165162
flags.Set("recursive", "true")
166163
assert.Nil(t, Initialize(flags, projectPaths))
167164
assert.True(t, Recursive())

Diff for: internal/project/packageindex/packageindex.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,5 @@ func Find(folderPath *paths.Path) (*paths.Path, error) {
8181
}
8282
}
8383

84-
return nil, fmt.Errorf("No package index file found in %s", folderPath)
84+
return nil, nil
8585
}

Diff for: internal/project/packageindex/packageindex_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func TestFind(t *testing.T) {
7070
{"Single", testDataPath.Join("HasPackageIndex"), testDataPath.Join("HasPackageIndex", "package_foo_index.json"), assert.Nil},
7171
{"Multiple", testDataPath.Join("HasMultiple"), testDataPath.Join("HasMultiple", "package_foo_index.json"), assert.Nil},
7272
{"Valid extension fallback", testDataPath.Join("HasJSON"), testDataPath.Join("HasJSON", "foo.json"), assert.Nil},
73-
{"None", testDataPath.Join("HasNone"), nil, assert.NotNil},
73+
{"None", testDataPath.Join("HasNone"), nil, assert.Nil},
7474
}
7575

7676
for _, testTable := range testTables {

Diff for: internal/project/projectdata/packageindex.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import (
2121

2222
// InitializeForPackageIndex gathers the package index rule data for the specified project.
2323
func InitializeForPackageIndex() {
24-
packageIndex, packageIndexLoadError = packageindex.LoadIndex(ProjectPath())
24+
if ProjectPath() != nil {
25+
packageIndex, packageIndexLoadError = packageindex.LoadIndex(ProjectPath())
26+
}
2527
}
2628

2729
var packageIndex *packageindex.Index

Diff for: internal/rule/ruleconfiguration/ruleconfiguration.go

+16
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,22 @@ var configurations = []Type{
14811481
ErrorModes: []rulemode.Type{rulemode.Strict},
14821482
RuleFunction: rulefunction.IncorrectArduinoDotHFileNameCase,
14831483
},
1484+
{
1485+
ProjectType: projecttype.PackageIndex,
1486+
SuperprojectType: projecttype.All,
1487+
Category: "data",
1488+
Subcategory: "general",
1489+
ID: "IS001",
1490+
Brief: "missing",
1491+
Description: "",
1492+
MessageTemplate: "No package index was found in specified project path. See: https://arduino.github.io/arduino-cli/latest/package_index_json-specification/",
1493+
DisableModes: nil,
1494+
EnableModes: []rulemode.Type{rulemode.Default},
1495+
InfoModes: nil,
1496+
WarningModes: nil,
1497+
ErrorModes: []rulemode.Type{rulemode.Default},
1498+
RuleFunction: rulefunction.PackageIndexMissing,
1499+
},
14841500
{
14851501
ProjectType: projecttype.PackageIndex,
14861502
SuperprojectType: projecttype.All,

Diff for: internal/rule/rulefunction/packageindex.go

+17
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,21 @@ import (
2222

2323
// The rule functions for package indexes.
2424

25+
// PackageIndexMissing checks whether a file resembling a package index was found in the specified project folder.
26+
func PackageIndexMissing() (result ruleresult.Type, output string) {
27+
if projectdata.ProjectPath() == nil {
28+
return ruleresult.Fail, ""
29+
}
30+
31+
return ruleresult.Pass, ""
32+
}
33+
2534
// PackageIndexJSONFormat checks whether the package index file is a valid JSON document.
2635
func PackageIndexJSONFormat() (result ruleresult.Type, output string) {
36+
if projectdata.ProjectPath() == nil {
37+
return ruleresult.NotRun, "Package index not found"
38+
}
39+
2740
if isValidJSON(projectdata.ProjectPath()) {
2841
return ruleresult.Pass, ""
2942
}
@@ -33,6 +46,10 @@ func PackageIndexJSONFormat() (result ruleresult.Type, output string) {
3346

3447
// PackageIndexFormat checks for invalid package index data format.
3548
func PackageIndexFormat() (result ruleresult.Type, output string) {
49+
if projectdata.ProjectPath() == nil {
50+
return ruleresult.NotRun, "Package index not found"
51+
}
52+
3653
if projectdata.PackageIndexLoadError() != nil {
3754
return ruleresult.Fail, projectdata.PackageIndexLoadError().Error()
3855
}

Diff for: internal/rule/rulefunction/packageindex_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ func checkPackageIndexRuleFunction(ruleFunction Type, testTables []packageIndexR
5959
}
6060
}
6161

62+
func TestPackageIndexMissing(t *testing.T) {
63+
testTables := []packageIndexRuleFunctionTestTable{
64+
{"Missing", "missing", ruleresult.Fail, ""},
65+
{"Present", "valid-package-index", ruleresult.Pass, ""},
66+
}
67+
68+
checkPackageIndexRuleFunction(PackageIndexMissing, testTables, t)
69+
}
70+
6271
func TestPackageIndexJSONFormat(t *testing.T) {
6372
testTables := []packageIndexRuleFunctionTestTable{
6473
{"Invalid JSON", "invalid-JSON", ruleresult.Fail, ""},

Diff for: internal/rule/rulefunction/testdata/packageindexes/missing/.gitkeep

Whitespace-only changes.

Diff for: internal/util/test/test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func ConfigurationFlags() *pflag.FlagSet {
2727
flags.String("log-format", "text", "")
2828
flags.String("log-level", "panic", "")
2929
flags.String("project-type", "all", "")
30-
flags.String("recursive", "true", "")
30+
flags.Bool("recursive", true, "")
3131
flags.String("report-file", "", "")
3232
flags.Bool("verbose", false, "")
3333
flags.Bool("version", false, "")

Diff for: test/test_all.py

+28-12
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@
2626

2727

2828
def test_defaults(run_command):
29-
result = run_command(cmd=[], custom_working_dir=test_data_path.joinpath("recursive"))
29+
result = run_command(cmd=[], custom_working_dir=test_data_path.joinpath("ValidSketch"))
3030
assert result.ok
3131

32+
result = run_command(cmd=[], custom_working_dir=test_data_path.joinpath("recursive"))
33+
assert not result.ok
34+
3235

3336
@pytest.mark.parametrize(
3437
"project_folder, compliance_level",
@@ -115,31 +118,44 @@ def test_project_type_invalid(run_command):
115118

116119
def test_recursive(run_command):
117120
valid_projects_path = test_data_path.joinpath("recursive")
118-
result = run_command(cmd=["--recursive", "true", valid_projects_path])
119-
assert result.ok
120-
121-
result = run_command(cmd=["--recursive", "false", valid_projects_path])
121+
result = run_command(cmd=[valid_projects_path])
122122
assert not result.ok
123123

124-
125-
def test_recursive_invalid(run_command):
126-
result = run_command(cmd=["--recursive", "foo", test_data_path.joinpath("ValidSketch")])
127-
assert not result.ok
124+
result = run_command(cmd=["--recursive", valid_projects_path])
125+
assert result.ok
128126

129127

130128
def test_report_file(run_command, working_dir):
131129
project_path = test_data_path.joinpath("ValidSketch")
130+
compliance = "permissive"
131+
library_manager = "update"
132+
project_type = "sketch"
132133
report_file_name = "report.json"
133-
result = run_command(cmd=["--report-file", report_file_name, project_path])
134+
result = run_command(
135+
cmd=[
136+
"--compliance",
137+
compliance,
138+
"--library-manager",
139+
library_manager,
140+
"--project-type",
141+
project_type,
142+
"--recursive",
143+
"--report-file",
144+
report_file_name,
145+
project_path,
146+
]
147+
)
134148
assert result.ok
135149
with pathlib.Path(working_dir, report_file_name).open() as report_file:
136150
report = json.load(report_file)
137151

138152
assert pathlib.PurePath(report["configuration"]["paths"][0]) == project_path
139-
assert report["configuration"]["projectType"] == "all"
153+
assert report["configuration"]["projectType"] == project_type
140154
assert report["configuration"]["recursive"]
141155
assert pathlib.PurePath(report["projects"][0]["path"]) == project_path
142156
assert report["projects"][0]["projectType"] == "sketch"
157+
assert report["projects"][0]["configuration"]["compliance"] == compliance
158+
assert report["projects"][0]["configuration"]["libraryManager"] == library_manager
143159
assert report["projects"][0]["summary"]["pass"]
144160
assert report["projects"][0]["summary"]["errorCount"] == 0
145161
assert report["summary"]["pass"]
@@ -187,7 +203,7 @@ def test_version(run_command):
187203

188204

189205
def test_arduino_lint_official(run_command):
190-
project_path = test_data_path.joinpath("ARDUINO_LINT_OFFICIAL")
206+
project_path = test_data_path.joinpath("ARDUINO_LINT_OFFICIAL", "Arduino_Lib")
191207

192208
result = run_command(cmd=[project_path])
193209
assert not result.ok

0 commit comments

Comments
 (0)